@@ -191,10 +191,10 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
191
191
192
192
// Macros are simple: there's no declaration/definition distinction.
193
193
// As a consequence, there's no need to look them up in the index either.
194
- SourceLocation MaybeMacroLocation = SM.getMacroArgExpandedLocation (
194
+ SourceLocation IdentStartLoc = SM.getMacroArgExpandedLocation (
195
195
getBeginningOfIdentifier (Pos, AST.getSourceManager (), AST.getLangOpts ()));
196
196
std::vector<LocatedSymbol> Result;
197
- if (auto M = locateMacroAt (MaybeMacroLocation , AST.getPreprocessor ())) {
197
+ if (auto M = locateMacroAt (IdentStartLoc , AST.getPreprocessor ())) {
198
198
if (auto Loc = makeLocation (AST.getASTContext (),
199
199
M->Info ->getDefinitionLoc (), *MainFilePath)) {
200
200
LocatedSymbol Macro;
@@ -234,6 +234,18 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
234
234
for (const Decl *D : getDeclAtPosition (AST, SourceLoc, Relations)) {
235
235
const Decl *Def = getDefinition (D);
236
236
const Decl *Preferred = Def ? Def : D;
237
+
238
+ // If we're at the point of declaration of a template specialization,
239
+ // it's more useful to navigate to the template declaration.
240
+ if (SM.getMacroArgExpandedLocation (Preferred->getLocation ()) ==
241
+ IdentStartLoc) {
242
+ if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Preferred)) {
243
+ D = CTSD->getSpecializedTemplate ();
244
+ Def = getDefinition (D);
245
+ Preferred = Def ? Def : D;
246
+ }
247
+ }
248
+
237
249
auto Loc = makeLocation (AST.getASTContext (),
238
250
spellingLocIfSpelled (findName (Preferred), SM),
239
251
*MainFilePath);
@@ -373,8 +385,8 @@ std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
373
385
// different kinds, deduplicate them.
374
386
std::vector<DocumentHighlight> Result;
375
387
for (const auto &Ref : References) {
376
- if (auto Range = getTokenRange (AST. getSourceManager (),
377
- AST.getLangOpts (), Ref.Loc )) {
388
+ if (auto Range =
389
+ getTokenRange (AST. getSourceManager (), AST.getLangOpts (), Ref.Loc )) {
378
390
DocumentHighlight DH;
379
391
DH.range = *Range;
380
392
if (Ref.Role & index::SymbolRoleSet (index::SymbolRole::Write))
0 commit comments