diff options
| author | Ilya Biryukov <ibiryukov@google.com> | 2019-01-07 15:45:19 +0000 |
|---|---|---|
| committer | Ilya Biryukov <ibiryukov@google.com> | 2019-01-07 15:45:19 +0000 |
| commit | f2001aa74394885dc178c5997b83687acb4f55e4 (patch) | |
| tree | 80666e16bbebadef8f35d1d962e09da8a7812d13 /clang-tools-extra/clangd/ClangdServer.cpp | |
| parent | 25d3de8a0ac4d65f2ac9820ba62a372414780649 (diff) | |
| download | bcm5719-llvm-f2001aa74394885dc178c5997b83687acb4f55e4.tar.gz bcm5719-llvm-f2001aa74394885dc178c5997b83687acb4f55e4.zip | |
[clangd] Remove 'using namespace llvm' from .cpp files. NFC
The new guideline is to qualify with 'llvm::' explicitly both in
'.h' and '.cpp' files. This simplifies moving the code between
header and source files and is easier to keep consistent.
llvm-svn: 350531
Diffstat (limited to 'clang-tools-extra/clangd/ClangdServer.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/ClangdServer.cpp | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index e554ade874d..f799d6bc670 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -34,7 +34,6 @@ #include <future> #include <mutex> -using namespace llvm; namespace clang { namespace clangd { namespace { @@ -47,7 +46,7 @@ std::string getStandardResourceDir() { class RefactoringResultCollector final : public tooling::RefactoringResultConsumer { public: - void handleError(Error Err) override { + void handleError(llvm::Error Err) override { assert(!Result.hasValue()); // FIXME: figure out a way to return better message for DiagnosticError. // clangd uses llvm::toString to convert the Err to string, however, for @@ -63,7 +62,7 @@ public: Result = std::move(SourceReplacements); } - Optional<Expected<tooling::AtomicChanges>> Result; + llvm::Optional<llvm::Expected<tooling::AtomicChanges>> Result; }; // Update the FileIndex with new ASTs and plumb the diagnostics responses. @@ -147,7 +146,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB, AddIndex(DynamicIdx.get()); } -void ClangdServer::addDocument(PathRef File, StringRef Contents, +void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents, WantDiagnostics WantDiags) { // FIXME: some build systems like Bazel will take time to preparing // environment to build the file, it would be nice if we could emit a @@ -175,13 +174,13 @@ void ClangdServer::codeComplete(PathRef File, Position Pos, auto Task = [PCHs, Pos, FS, CodeCompleteOpts, this](Path File, Callback<CodeCompleteResult> CB, - Expected<InputsAndPreamble> IP) { + llvm::Expected<InputsAndPreamble> IP) { if (!IP) return CB(IP.takeError()); if (isCancelled()) - return CB(make_error<CancelledError>()); + return CB(llvm::make_error<CancelledError>()); - Optional<SpeculativeFuzzyFind> SpecFuzzyFind; + llvm::Optional<SpeculativeFuzzyFind> SpecFuzzyFind; if (CodeCompleteOpts.Index && CodeCompleteOpts.SpeculativeIndexRequest) { SpecFuzzyFind.emplace(); { @@ -222,7 +221,7 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos, auto FS = FSProvider.getFileSystem(); auto *Index = this->Index; auto Action = [Pos, FS, PCHs, Index](Path File, Callback<SignatureHelp> CB, - Expected<InputsAndPreamble> IP) { + llvm::Expected<InputsAndPreamble> IP) { if (!IP) return CB(IP.takeError()); @@ -239,43 +238,44 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos, Bind(Action, File.str(), std::move(CB))); } -Expected<tooling::Replacements> -ClangdServer::formatRange(StringRef Code, PathRef File, Range Rng) { - Expected<size_t> Begin = positionToOffset(Code, Rng.start); +llvm::Expected<tooling::Replacements> +ClangdServer::formatRange(llvm::StringRef Code, PathRef File, Range Rng) { + llvm::Expected<size_t> Begin = positionToOffset(Code, Rng.start); if (!Begin) return Begin.takeError(); - Expected<size_t> End = positionToOffset(Code, Rng.end); + llvm::Expected<size_t> End = positionToOffset(Code, Rng.end); if (!End) return End.takeError(); return formatCode(Code, File, {tooling::Range(*Begin, *End - *Begin)}); } -Expected<tooling::Replacements> ClangdServer::formatFile(StringRef Code, - PathRef File) { +llvm::Expected<tooling::Replacements> +ClangdServer::formatFile(llvm::StringRef Code, PathRef File) { // Format everything. return formatCode(Code, File, {tooling::Range(0, Code.size())}); } -Expected<tooling::Replacements> -ClangdServer::formatOnType(StringRef Code, PathRef File, Position Pos) { +llvm::Expected<tooling::Replacements> +ClangdServer::formatOnType(llvm::StringRef Code, PathRef File, Position Pos) { // Look for the previous opening brace from the character position and // format starting from there. - Expected<size_t> CursorPos = positionToOffset(Code, Pos); + llvm::Expected<size_t> CursorPos = positionToOffset(Code, Pos); if (!CursorPos) return CursorPos.takeError(); - size_t PreviousLBracePos = StringRef(Code).find_last_of('{', *CursorPos); - if (PreviousLBracePos == StringRef::npos) + size_t PreviousLBracePos = + llvm::StringRef(Code).find_last_of('{', *CursorPos); + if (PreviousLBracePos == llvm::StringRef::npos) PreviousLBracePos = *CursorPos; size_t Len = *CursorPos - PreviousLBracePos; return formatCode(Code, File, {tooling::Range(PreviousLBracePos, Len)}); } -void ClangdServer::rename(PathRef File, Position Pos, StringRef NewName, +void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName, Callback<std::vector<tooling::Replacement>> CB) { auto Action = [Pos](Path File, std::string NewName, Callback<std::vector<tooling::Replacement>> CB, - Expected<InputsAndAST> InpAST) { + llvm::Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); auto &AST = InpAST->AST; @@ -323,15 +323,16 @@ void ClangdServer::rename(PathRef File, Position Pos, StringRef NewName, } void ClangdServer::dumpAST(PathRef File, - unique_function<void(std::string)> Callback) { - auto Action = [](decltype(Callback) Callback, Expected<InputsAndAST> InpAST) { + llvm::unique_function<void(std::string)> Callback) { + auto Action = [](decltype(Callback) Callback, + llvm::Expected<InputsAndAST> InpAST) { if (!InpAST) { llvm::consumeError(InpAST.takeError()); return Callback("<no-ast>"); } std::string Result; - raw_string_ostream ResultOS(Result); + llvm::raw_string_ostream ResultOS(Result); clangd::dumpAST(InpAST->AST, ResultOS); ResultOS.flush(); @@ -344,7 +345,7 @@ void ClangdServer::dumpAST(PathRef File, void ClangdServer::findDefinitions(PathRef File, Position Pos, Callback<std::vector<Location>> CB) { auto Action = [Pos, this](Callback<std::vector<Location>> CB, - Expected<InputsAndAST> InpAST) { + llvm::Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::findDefinitions(InpAST->AST, Pos, Index)); @@ -353,13 +354,13 @@ void ClangdServer::findDefinitions(PathRef File, Position Pos, WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB))); } -Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { +llvm::Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { - StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx", - ".c++", ".m", ".mm"}; - StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"}; + llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx", + ".c++", ".m", ".mm"}; + llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"}; - StringRef PathExt = sys::path::extension(Path); + llvm::StringRef PathExt = llvm::sys::path::extension(Path); // Lookup in a list of known extensions. auto SourceIter = @@ -381,28 +382,28 @@ Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { // Array to lookup extensions for the switch. An opposite of where original // extension was found. - ArrayRef<StringRef> NewExts; + llvm::ArrayRef<llvm::StringRef> NewExts; if (IsSource) NewExts = HeaderExtensions; else NewExts = SourceExtensions; // Storage for the new path. - SmallString<128> NewPath = StringRef(Path); + llvm::SmallString<128> NewPath = llvm::StringRef(Path); // Instance of vfs::FileSystem, used for file existence checks. auto FS = FSProvider.getFileSystem(); // Loop through switched extension candidates. - for (StringRef NewExt : NewExts) { - sys::path::replace_extension(NewPath, NewExt); + for (llvm::StringRef NewExt : NewExts) { + llvm::sys::path::replace_extension(NewPath, NewExt); if (FS->exists(NewPath)) return NewPath.str().str(); // First str() to convert from SmallString to // StringRef, second to convert from StringRef // to std::string // Also check NewExt in upper-case, just in case. - sys::path::replace_extension(NewPath, NewExt.upper()); + llvm::sys::path::replace_extension(NewPath, NewExt.upper()); if (FS->exists(NewPath)) return NewPath.str().str(); } @@ -410,9 +411,9 @@ Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { return None; } -Expected<tooling::Replacements> -ClangdServer::formatCode(StringRef Code, PathRef File, - ArrayRef<tooling::Range> Ranges) { +llvm::Expected<tooling::Replacements> +ClangdServer::formatCode(llvm::StringRef Code, PathRef File, + llvm::ArrayRef<tooling::Range> Ranges) { // Call clang-format. auto FS = FSProvider.getFileSystem(); auto Style = format::getStyle(format::DefaultFormatStyle, File, @@ -435,7 +436,7 @@ ClangdServer::formatCode(StringRef Code, PathRef File, void ClangdServer::findDocumentHighlights( PathRef File, Position Pos, Callback<std::vector<DocumentHighlight>> CB) { auto Action = [Pos](Callback<std::vector<DocumentHighlight>> CB, - Expected<InputsAndAST> InpAST) { + llvm::Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::findDocumentHighlights(InpAST->AST, Pos)); @@ -445,9 +446,9 @@ void ClangdServer::findDocumentHighlights( } void ClangdServer::findHover(PathRef File, Position Pos, - Callback<Optional<Hover>> CB) { - auto Action = [Pos](Callback<Optional<Hover>> CB, - Expected<InputsAndAST> InpAST) { + Callback<llvm::Optional<Hover>> CB) { + auto Action = [Pos](Callback<llvm::Optional<Hover>> CB, + llvm::Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::getHover(InpAST->AST, Pos)); @@ -458,7 +459,7 @@ void ClangdServer::findHover(PathRef File, Position Pos, tooling::CompileCommand ClangdServer::getCompileCommand(PathRef File) { trace::Span Span("GetCompileCommand"); - Optional<tooling::CompileCommand> C = CDB.getCompileCommand(File); + llvm::Optional<tooling::CompileCommand> C = CDB.getCompileCommand(File); if (!C) // FIXME: Suppress diagnostics? Let the user know? C = CDB.getFallbackCommand(File); @@ -474,7 +475,8 @@ void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) { } void ClangdServer::workspaceSymbols( - StringRef Query, int Limit, Callback<std::vector<SymbolInformation>> CB) { + llvm::StringRef Query, int Limit, + Callback<std::vector<SymbolInformation>> CB) { std::string QueryCopy = Query; WorkScheduler.run( "getWorkspaceSymbols", @@ -486,7 +488,7 @@ void ClangdServer::workspaceSymbols( std::move(CB))); } -void ClangdServer::documentSymbols(StringRef File, +void ClangdServer::documentSymbols(llvm::StringRef File, Callback<std::vector<DocumentSymbol>> CB) { auto Action = [](Callback<std::vector<DocumentSymbol>> CB, llvm::Expected<InputsAndAST> InpAST) { @@ -501,7 +503,7 @@ void ClangdServer::documentSymbols(StringRef File, void ClangdServer::findReferences(PathRef File, Position Pos, Callback<std::vector<Location>> CB) { auto Action = [Pos, this](Callback<std::vector<Location>> CB, - Expected<InputsAndAST> InpAST) { + llvm::Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::findReferences(InpAST->AST, Pos, Index)); @@ -513,7 +515,7 @@ void ClangdServer::findReferences(PathRef File, Position Pos, void ClangdServer::symbolInfo(PathRef File, Position Pos, Callback<std::vector<SymbolDetails>> CB) { auto Action = [Pos](Callback<std::vector<SymbolDetails>> CB, - Expected<InputsAndAST> InpAST) { + llvm::Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::getSymbolInfo(InpAST->AST, Pos)); @@ -528,7 +530,7 @@ ClangdServer::getUsedBytesPerFile() const { } LLVM_NODISCARD bool -ClangdServer::blockUntilIdleForTest(Optional<double> TimeoutSeconds) { +ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) { return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) && (!BackgroundIdx || BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds)); |

