diff options
| author | Sam McCall <sam.mccall@gmail.com> | 2018-10-20 15:30:37 +0000 |
|---|---|---|
| committer | Sam McCall <sam.mccall@gmail.com> | 2018-10-20 15:30:37 +0000 |
| commit | c008af646620f6718384c2cd95f58a7311fe10fb (patch) | |
| tree | 4961c6079af876f19462df09f9a0d0fa1176a824 /clang-tools-extra/clangd/ClangdServer.cpp | |
| parent | 0c35aa114d34c4f8add2a532de3a797ef0c1b667 (diff) | |
| download | bcm5719-llvm-c008af646620f6718384c2cd95f58a7311fe10fb.tar.gz bcm5719-llvm-c008af646620f6718384c2cd95f58a7311fe10fb.zip | |
[clangd] Namespace style cleanup in cpp files. NFC.
Standardize on the most common namespace setup in our *.cpp files:
using namespace llvm;
namespace clang {
namespace clangd {
void foo(StringRef) { ... }
And remove redundant llvm:: qualifiers. (Except for cases like
make_unique where this causes problems with std:: and ADL).
This choice is pretty arbitrary, but some broad consistency is nice.
This is going to conflict with everything. Sorry :-/
Squash the other configurations:
A)
using namespace llvm;
using namespace clang;
using namespace clangd;
void clangd::foo(StringRef);
This is in some of the older files. (It prevents accidentally defining a
new function instead of one in the header file, for what that's worth).
B)
namespace clang {
namespace clangd {
void foo(llvm::StringRef) { ... }
This is fine, but in practice the using directive often gets added over time.
C)
namespace clang {
namespace clangd {
using namespace llvm; // inside the namespace
This was pretty common, but is a bit misleading: name lookup preferrs
clang::clangd::foo > clang::foo > llvm:: foo (no matter where the using
directive is).
llvm-svn: 344850
Diffstat (limited to 'clang-tools-extra/clangd/ClangdServer.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/ClangdServer.cpp | 80 |
1 files changed, 41 insertions, 39 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index b0b1af1bbe4..cd1fb33efe6 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -34,13 +34,13 @@ #include <future> #include <mutex> -using namespace clang; -using namespace clang::clangd; - +using namespace llvm; +namespace clang { +namespace clangd { namespace { -void ignoreError(llvm::Error Err) { - handleAllErrors(std::move(Err), [](const llvm::ErrorInfoBase &) {}); +void ignoreError(Error Err) { + handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {}); } std::string getStandardResourceDir() { @@ -51,7 +51,7 @@ std::string getStandardResourceDir() { class RefactoringResultCollector final : public tooling::RefactoringResultConsumer { public: - void handleError(llvm::Error Err) override { + void handleError(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 @@ -164,13 +164,13 @@ void ClangdServer::codeComplete(PathRef File, Position Pos, auto Task = [PCHs, Pos, FS, CodeCompleteOpts, this](Path File, Callback<CodeCompleteResult> CB, - llvm::Expected<InputsAndPreamble> IP) { + Expected<InputsAndPreamble> IP) { if (!IP) return CB(IP.takeError()); if (isCancelled()) - return CB(llvm::make_error<CancelledError>()); + return CB(make_error<CancelledError>()); - llvm::Optional<SpeculativeFuzzyFind> SpecFuzzyFind; + Optional<SpeculativeFuzzyFind> SpecFuzzyFind; if (CodeCompleteOpts.Index && CodeCompleteOpts.SpeculativeIndexRequest) { SpecFuzzyFind.emplace(); { @@ -211,7 +211,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, - llvm::Expected<InputsAndPreamble> IP) { + Expected<InputsAndPreamble> IP) { if (!IP) return CB(IP.takeError()); @@ -228,28 +228,28 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos, Bind(Action, File.str(), std::move(CB))); } -llvm::Expected<tooling::Replacements> +Expected<tooling::Replacements> ClangdServer::formatRange(StringRef Code, PathRef File, Range Rng) { - llvm::Expected<size_t> Begin = positionToOffset(Code, Rng.start); + Expected<size_t> Begin = positionToOffset(Code, Rng.start); if (!Begin) return Begin.takeError(); - llvm::Expected<size_t> End = positionToOffset(Code, Rng.end); + Expected<size_t> End = positionToOffset(Code, Rng.end); if (!End) return End.takeError(); return formatCode(Code, File, {tooling::Range(*Begin, *End - *Begin)}); } -llvm::Expected<tooling::Replacements> ClangdServer::formatFile(StringRef Code, - PathRef File) { +Expected<tooling::Replacements> ClangdServer::formatFile(StringRef Code, + PathRef File) { // Format everything. return formatCode(Code, File, {tooling::Range(0, Code.size())}); } -llvm::Expected<tooling::Replacements> +Expected<tooling::Replacements> ClangdServer::formatOnType(StringRef Code, PathRef File, Position Pos) { // Look for the previous opening brace from the character position and // format starting from there. - llvm::Expected<size_t> CursorPos = positionToOffset(Code, Pos); + Expected<size_t> CursorPos = positionToOffset(Code, Pos); if (!CursorPos) return CursorPos.takeError(); size_t PreviousLBracePos = StringRef(Code).find_last_of('{', *CursorPos); @@ -260,7 +260,7 @@ ClangdServer::formatOnType(StringRef Code, PathRef File, Position Pos) { return formatCode(Code, File, {tooling::Range(PreviousLBracePos, Len)}); } -void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName, +void ClangdServer::rename(PathRef File, Position Pos, StringRef NewName, Callback<std::vector<tooling::Replacement>> CB) { auto Action = [Pos](Path File, std::string NewName, Callback<std::vector<tooling::Replacement>> CB, @@ -312,16 +312,15 @@ void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName, } void ClangdServer::dumpAST(PathRef File, - llvm::unique_function<void(std::string)> Callback) { - auto Action = [](decltype(Callback) Callback, - llvm::Expected<InputsAndAST> InpAST) { + unique_function<void(std::string)> Callback) { + auto Action = [](decltype(Callback) Callback, Expected<InputsAndAST> InpAST) { if (!InpAST) { ignoreError(InpAST.takeError()); return Callback("<no-ast>"); } std::string Result; - llvm::raw_string_ostream ResultOS(Result); + raw_string_ostream ResultOS(Result); clangd::dumpAST(InpAST->AST, ResultOS); ResultOS.flush(); @@ -334,7 +333,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, - llvm::Expected<InputsAndAST> InpAST) { + Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::findDefinitions(InpAST->AST, Pos, Index)); @@ -343,13 +342,13 @@ void ClangdServer::findDefinitions(PathRef File, Position Pos, WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB))); } -llvm::Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { +Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx", ".c++", ".m", ".mm"}; StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"}; - StringRef PathExt = llvm::sys::path::extension(Path); + StringRef PathExt = sys::path::extension(Path); // Lookup in a list of known extensions. auto SourceIter = @@ -367,7 +366,7 @@ llvm::Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { // We can only switch between the known extensions. if (!IsSource && !IsHeader) - return llvm::None; + return None; // Array to lookup extensions for the switch. An opposite of where original // extension was found. @@ -385,23 +384,23 @@ llvm::Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { // Loop through switched extension candidates. for (StringRef NewExt : NewExts) { - llvm::sys::path::replace_extension(NewPath, NewExt); + 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. - llvm::sys::path::replace_extension(NewPath, NewExt.upper()); + sys::path::replace_extension(NewPath, NewExt.upper()); if (FS->exists(NewPath)) return NewPath.str().str(); } - return llvm::None; + return None; } -llvm::Expected<tooling::Replacements> -ClangdServer::formatCode(llvm::StringRef Code, PathRef File, +Expected<tooling::Replacements> +ClangdServer::formatCode(StringRef Code, PathRef File, ArrayRef<tooling::Range> Ranges) { // Call clang-format. auto FS = FSProvider.getFileSystem(); @@ -425,7 +424,7 @@ ClangdServer::formatCode(llvm::StringRef Code, PathRef File, void ClangdServer::findDocumentHighlights( PathRef File, Position Pos, Callback<std::vector<DocumentHighlight>> CB) { auto Action = [Pos](Callback<std::vector<DocumentHighlight>> CB, - llvm::Expected<InputsAndAST> InpAST) { + Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::findDocumentHighlights(InpAST->AST, Pos)); @@ -435,9 +434,9 @@ void ClangdServer::findDocumentHighlights( } void ClangdServer::findHover(PathRef File, Position Pos, - Callback<llvm::Optional<Hover>> CB) { - auto Action = [Pos](Callback<llvm::Optional<Hover>> CB, - llvm::Expected<InputsAndAST> InpAST) { + Callback<Optional<Hover>> CB) { + auto Action = [Pos](Callback<Optional<Hover>> CB, + Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::getHover(InpAST->AST, Pos)); @@ -466,7 +465,7 @@ void ClangdServer::consumeDiagnostics(PathRef File, DocVersion Version, tooling::CompileCommand ClangdServer::getCompileCommand(PathRef File) { trace::Span Span("GetCompileCommand"); - llvm::Optional<tooling::CompileCommand> C = CDB.getCompileCommand(File); + Optional<tooling::CompileCommand> C = CDB.getCompileCommand(File); if (!C) // FIXME: Suppress diagnostics? Let the user know? C = CDB.getFallbackCommand(File); @@ -490,7 +489,7 @@ void ClangdServer::workspaceSymbols( void ClangdServer::documentSymbols( StringRef File, Callback<std::vector<SymbolInformation>> CB) { auto Action = [](Callback<std::vector<SymbolInformation>> CB, - llvm::Expected<InputsAndAST> InpAST) { + Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::getDocumentSymbols(InpAST->AST)); @@ -502,7 +501,7 @@ void ClangdServer::documentSymbols( void ClangdServer::findReferences(PathRef File, Position Pos, Callback<std::vector<Location>> CB) { auto Action = [Pos, this](Callback<std::vector<Location>> CB, - llvm::Expected<InputsAndAST> InpAST) { + Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); CB(clangd::findReferences(InpAST->AST, Pos, Index)); @@ -517,6 +516,9 @@ ClangdServer::getUsedBytesPerFile() const { } LLVM_NODISCARD bool -ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) { +ClangdServer::blockUntilIdleForTest(Optional<double> TimeoutSeconds) { return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)); } + +} // namespace clangd +} // namespace clang |

