From 4621387d9d0e76037ad605765e51884914df1da2 Mon Sep 17 00:00:00 2001 From: Kirill Bobyrev Date: Wed, 28 Jun 2017 20:57:28 +0000 Subject: [PATCH] [clangd] Cleanup ClangdUnit.cpp, update docs; NFC * Enforce 80 characters limit where appropriate * Use slightly more descriptive names for searched locations * Update docs to reflect D34269, which adds "Go To Declaration" functionality llvm-svn: 306598 --- clang-tools-extra/clangd/ClangdUnit.cpp | 30 ++++++++++++------------- clang-tools-extra/docs/clangd.rst | 4 ++-- clang-tools-extra/test/CMakeLists.txt | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp index 61bfe0bc25fb..70e36b5000e9 100644 --- a/clang-tools-extra/clangd/ClangdUnit.cpp +++ b/clang-tools-extra/clangd/ClangdUnit.cpp @@ -36,7 +36,8 @@ ClangdUnit::ClangdUnit(PathRef FileName, StringRef Contents, // Inject the resource dir. // FIXME: Don't overwrite it if it's already there. - Commands.front().CommandLine.push_back("-resource-dir=" + std::string(ResourceDir)); + Commands.front().CommandLine.push_back("-resource-dir=" + + std::string(ResourceDir)); IntrusiveRefCntPtr Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions); @@ -277,14 +278,14 @@ class DeclarationLocationsFinder : public index::IndexDataConsumer { public: DeclarationLocationsFinder(raw_ostream &OS, const SourceLocation &SearchedLocation, ASTUnit &Unit) : - SearchedLocation(SearchedLocation), Unit(Unit) { - } + SearchedLocation(SearchedLocation), Unit(Unit) {} std::vector takeLocations() { // Don't keep the same location multiple times. // This can happen when nodes in the AST are visited twice. std::sort(DeclarationLocations.begin(), DeclarationLocations.end()); - auto last = std::unique(DeclarationLocations.begin(), DeclarationLocations.end()); + auto last = + std::unique(DeclarationLocations.begin(), DeclarationLocations.end()); DeclarationLocations.erase(last, DeclarationLocations.end()); return std::move(DeclarationLocations); } @@ -312,13 +313,13 @@ private: SourceLocation LocStart = ValSourceRange.getBegin(); SourceLocation LocEnd = Lexer::getLocForEndOfToken(ValSourceRange.getEnd(), 0, SourceMgr, LangOpts); - Position P1; - P1.line = SourceMgr.getSpellingLineNumber(LocStart) - 1; - P1.character = SourceMgr.getSpellingColumnNumber(LocStart) - 1; - Position P2; - P2.line = SourceMgr.getSpellingLineNumber(LocEnd) - 1; - P2.character = SourceMgr.getSpellingColumnNumber(LocEnd) - 1; - Range R = { P1, P2 }; + Position Begin; + Begin.line = SourceMgr.getSpellingLineNumber(LocStart) - 1; + Begin.character = SourceMgr.getSpellingColumnNumber(LocStart) - 1; + Position End; + End.line = SourceMgr.getSpellingLineNumber(LocEnd) - 1; + End.character = SourceMgr.getSpellingColumnNumber(LocEnd) - 1; + Range R = {Begin, End}; Location L; L.uri = URI::fromFile( SourceMgr.getFilename(SourceMgr.getSpellingLoc(LocStart))); @@ -326,8 +327,7 @@ private: DeclarationLocations.push_back(L); } - void finish() override - { + void finish() override { // Also handle possible macro at the searched location. Token Result; if (!Lexer::getRawToken(SearchedLocation, Result, Unit.getSourceManager(), @@ -366,8 +366,8 @@ std::vector ClangdUnit::findDefinitions(Position Pos) { SourceLocation SourceLocationBeg = getBeginningOfIdentifier(Pos, FE); - auto DeclLocationsFinder = std::make_shared(llvm::errs(), - SourceLocationBeg, *Unit); + auto DeclLocationsFinder = std::make_shared( + llvm::errs(), SourceLocationBeg, *Unit); index::IndexingOptions IndexOpts; IndexOpts.SystemSymbolFilter = index::IndexingOptions::SystemSymbolFilterKind::All; diff --git a/clang-tools-extra/docs/clangd.rst b/clang-tools-extra/docs/clangd.rst index 54e68fba127e..d7284a2b96ae 100644 --- a/clang-tools-extra/docs/clangd.rst +++ b/clang-tools-extra/docs/clangd.rst @@ -54,7 +54,7 @@ features might be eventually developed outside :program:`Clangd`. +-------------------------------------+------------+----------+ | Fix-its | Yes | Yes | +-------------------------------------+------------+----------+ -| Go to Definition | Yes | No | +| Go to Definition | Yes | Yes | +-------------------------------------+------------+----------+ | Source hover | Yes | No | +-------------------------------------+------------+----------+ @@ -103,4 +103,4 @@ look at the `LLVM Developer Policy to the `Language Server Protocol `_ itself would also be very useful, so that :program:`Clangd` can eventually implement them in a -conforming way. \ No newline at end of file +conforming way. diff --git a/clang-tools-extra/test/CMakeLists.txt b/clang-tools-extra/test/CMakeLists.txt index be652e34f96e..3aedde585f30 100644 --- a/clang-tools-extra/test/CMakeLists.txt +++ b/clang-tools-extra/test/CMakeLists.txt @@ -70,5 +70,5 @@ add_lit_testsuite(check-clang-tools "Running the Clang extra tools' regression t DEPENDS ${CLANG_TOOLS_TEST_DEPS} ARGS ${CLANG_TOOLS_TEST_EXTRA_ARGS} ) -set_target_properties(check-clang-tools PROPERTIES FOLDER "Clang extra tools' tests") +set_target_properties(check-clang-tools PROPERTIES FOLDER "Clang extra tools' tests")