ckandeler updated this revision to Diff 363083. ckandeler added a comment. Addressed comments.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D107137/new/ https://reviews.llvm.org/D107137 Files: clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/Hover.h clang-tools-extra/clangd/unittests/HoverTests.cpp Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2750,6 +2750,15 @@ // In test::Bar int foo = 3)", + }, + { + [](HoverInfo &HI) { + HI.Name = "stdio.h"; + HI.Definition = "/usr/include/stdio.h", "/"; + }, + R"(stdio.h + +/usr/include/stdio.h)", }}; for (const auto &C : Cases) { Index: clang-tools-extra/clangd/Hover.h =================================================================== --- clang-tools-extra/clangd/Hover.h +++ clang-tools-extra/clangd/Hover.h @@ -58,7 +58,7 @@ std::string Documentation; /// Source code containing the definition of the symbol. std::string Definition; - + const char *DefinitionLanguage = "cpp"; /// Access specifier for declarations inside class/struct/unions, empty for /// others. std::string AccessSpecifier; Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -905,6 +905,22 @@ if (TokensTouchingCursor.empty()) return llvm::None; + // Show full header file path if cursor is on include directive. + if (const auto MainFilePath + = getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM)) { + for (const auto &Inc : AST.getIncludeStructure().MainFileIncludes) { + if (Inc.Resolved.empty() || Inc.HashLine != Pos.line) + continue; + HoverInfo HI; + HI.Name = std::string(llvm::sys::path::filename(Inc.Resolved)); + // FIXME: We don't have a fitting value for Kind. + HI.Definition = URIForFile::canonicalize(Inc.Resolved, *MainFilePath) + .file().str(); + HI.DefinitionLanguage = ""; + return HI; + } + } + // To be used as a backup for highlighting the selected token, we use back as // it aligns better with biases elsewhere (editors tend to send the position // for the left of the hovered token). @@ -981,6 +997,7 @@ markup::Document HoverInfo::present() const { markup::Document Output; + // Header contains a text of the form: // variable `var` // @@ -1081,7 +1098,8 @@ : Definition; // Note that we don't print anything for global namespace, to not annoy // non-c++ projects or projects that are not making use of namespaces. - Output.addCodeBlock(ScopeComment + DefinitionWithAccess); + Output.addCodeBlock(ScopeComment + DefinitionWithAccess, + DefinitionLanguage); } return Output;
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2750,6 +2750,15 @@ // In test::Bar int foo = 3)", + }, + { + [](HoverInfo &HI) { + HI.Name = "stdio.h"; + HI.Definition = "/usr/include/stdio.h", "/"; + }, + R"(stdio.h + +/usr/include/stdio.h)", }}; for (const auto &C : Cases) { Index: clang-tools-extra/clangd/Hover.h =================================================================== --- clang-tools-extra/clangd/Hover.h +++ clang-tools-extra/clangd/Hover.h @@ -58,7 +58,7 @@ std::string Documentation; /// Source code containing the definition of the symbol. std::string Definition; - + const char *DefinitionLanguage = "cpp"; /// Access specifier for declarations inside class/struct/unions, empty for /// others. std::string AccessSpecifier; Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -905,6 +905,22 @@ if (TokensTouchingCursor.empty()) return llvm::None; + // Show full header file path if cursor is on include directive. + if (const auto MainFilePath + = getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM)) { + for (const auto &Inc : AST.getIncludeStructure().MainFileIncludes) { + if (Inc.Resolved.empty() || Inc.HashLine != Pos.line) + continue; + HoverInfo HI; + HI.Name = std::string(llvm::sys::path::filename(Inc.Resolved)); + // FIXME: We don't have a fitting value for Kind. + HI.Definition = URIForFile::canonicalize(Inc.Resolved, *MainFilePath) + .file().str(); + HI.DefinitionLanguage = ""; + return HI; + } + } + // To be used as a backup for highlighting the selected token, we use back as // it aligns better with biases elsewhere (editors tend to send the position // for the left of the hovered token). @@ -981,6 +997,7 @@ markup::Document HoverInfo::present() const { markup::Document Output; + // Header contains a text of the form: // variable `var` // @@ -1081,7 +1098,8 @@ : Definition; // Note that we don't print anything for global namespace, to not annoy // non-c++ projects or projects that are not making use of namespaces. - Output.addCodeBlock(ScopeComment + DefinitionWithAccess); + Output.addCodeBlock(ScopeComment + DefinitionWithAccess, + DefinitionLanguage); } return Output;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits