Skip to content

[clangd] Support go-to-definition on type hints. The core part #86629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b8a69cb
[clangd] Support go-to-definition on type hints. The core part
zyn0217 Mar 16, 2024
fb3bbd0
Small fixes
zyn0217 Mar 26, 2024
36199ce
Add unittests
zyn0217 Mar 31, 2024
fa5fb4a
Fix an uninitialization bug
zyn0217 Mar 31, 2024
31a0daf
format
zyn0217 Mar 31, 2024
9edd0f6
Handle reference/pointer types & Preserve qualifiers & Refactor tests…
zyn0217 Apr 1, 2024
48e21a1
Forgot to format, sorry
zyn0217 Apr 1, 2024
8c8c036
Fix regressions
zyn0217 Apr 1, 2024
0e25c18
Initialize ShouldAddLinksToTagTypes
zyn0217 Apr 1, 2024
2060777
Handle TypeAliases & UsingTypes
zyn0217 Apr 12, 2024
64105c0
Merge branch 'main' into inlay-hint-label-part-impl
zyn0217 May 14, 2024
c72f62c
Merge branch 'main' into inlay-hint-label-part-impl
zyn0217 May 14, 2024
0080a2f
Merge branch 'main' into inlay-hint-label-part-impl
zyn0217 Jun 1, 2024
acbf62e
Fix printing on NNS; Always offer links; Address some of the feedback
zyn0217 Jun 1, 2024
d862ce4
Forget to print non-type specifiers. Oof
zyn0217 Jun 1, 2024
9ebbbd6
Run clang-format
zyn0217 Jun 1, 2024
fcf6b6b
Fix tests
zyn0217 Jun 1, 2024
f6b5afb
Merge branch 'main' into inlay-hint-label-part-impl
zyn0217 Jun 15, 2024
d7b0715
Use getLocation() for identifier's location. Handle enum Decls.
zyn0217 Jun 16, 2024
4e39a46
Merge branch 'main' into inlay-hint-label-part-impl
zyn0217 Jun 16, 2024
3866216
Remove unused toLocation function
zyn0217 Jun 16, 2024
645fcff
Merge branch 'main' into inlay-hint-label-part-impl
zyn0217 Jul 7, 2024
65493f0
Address some nits
zyn0217 Jul 7, 2024
1195d25
Restructure the logic in addTypeHint()
zyn0217 Jul 7, 2024
e2b843c
Special case ClassTemplateSpecializationDecl for forward declarations
zyn0217 Jul 7, 2024
6930a55
Cleanup more inline lambdas
zyn0217 Jul 7, 2024
b89cda3
Remove the dead codes
zyn0217 Jul 7, 2024
c6e691e
Respect PP.SuppressScope
zyn0217 Jul 7, 2024
71604ef
clang-format
zyn0217 Jul 7, 2024
fd1761a
Ensure go-to-def always goes to the definition
zyn0217 Jul 8, 2024
57efdd4
Handle links for structure bindings
zyn0217 Jul 8, 2024
2973958
Almost there!
zyn0217 Jul 8, 2024
d4e3ff7
Add handling for C recordTypes.
zyn0217 Jul 8, 2024
77b5525
Remove CurrentTypeRAII
zyn0217 Jul 8, 2024
1be1f75
Revert unrelated changes
zyn0217 Jul 8, 2024
35816e0
Refactor handleTemplateSpecialization
zyn0217 Jul 9, 2024
96611a3
Avoid a nullptr dereference
zyn0217 Jul 11, 2024
49f9ec5
Use getTemplateSpecializationKind() instead of getTemplateInstantiati…
zyn0217 Jul 12, 2024
5595bdf
Handle DeducedTemplateSpecializationType for CTAD
zyn0217 Jul 14, 2024
df82828
Refactor the handling of Qualifiers
zyn0217 Jul 16, 2024
dfb317e
cleanup
zyn0217 Jul 16, 2024
c7a0096
Merge branch 'main' into inlay-hint-label-part-impl
zyn0217 Jul 16, 2024
8e3826e
Fix qualifiers further more
zyn0217 Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions clang-tools-extra/clangd/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "AST.h"

#include "SourceCode.h"
#include "support/Logger.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTTypeTraits.h"
#include "clang/AST/Decl.h"
Expand Down Expand Up @@ -174,6 +175,27 @@ SourceLocation nameLocation(const clang::Decl &D, const SourceManager &SM) {
return SM.getExpansionLoc(L);
}

std::optional<Location> makeLocation(const ASTContext &AST, SourceLocation Loc,
llvm::StringRef TUPath) {
const auto &SM = AST.getSourceManager();
const auto F = SM.getFileEntryRefForID(SM.getFileID(Loc));
if (!F)
return std::nullopt;
auto FilePath = getCanonicalPath(*F, SM.getFileManager());
if (!FilePath) {
log("failed to get path!");
return std::nullopt;
}
Location L;
L.uri = URIForFile::canonicalize(*FilePath, TUPath);
// We call MeasureTokenLength here as TokenBuffer doesn't store spelled tokens
// outside the main file.
auto TokLen = Lexer::MeasureTokenLength(Loc, SM, AST.getLangOpts());
L.range = halfOpenToRange(
SM, CharSourceRange::getCharRange(Loc, Loc.getLocWithOffset(TokLen)));
return L;
}

std::string printQualifiedName(const NamedDecl &ND) {
std::string QName;
llvm::raw_string_ostream OS(QName);
Expand Down
6 changes: 6 additions & 0 deletions clang-tools-extra/clangd/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ bool isImplementationDetail(const Decl *D);
/// this function.
SourceLocation nameLocation(const clang::Decl &D, const SourceManager &SM);

/// Convert a \p SourceLocation to an LSP \p Location.
/// Expects Loc to be a SpellingLocation, will bail out otherwise as it can't
/// figure out a filename.
std::optional<Location> makeLocation(const ASTContext &AST, SourceLocation Loc,
llvm::StringRef TUPath);

/// Returns the qualified name of ND. The scope doesn't contain unwritten scopes
/// like inline namespaces.
std::string printQualifiedName(const NamedDecl &ND);
Expand Down
Loading