@@ -114,7 +114,7 @@ const NamedDecl *getDefinition(const NamedDecl *D) {
114114 return nullptr ; // except cases above
115115}
116116
117- void logIfOverflow (const SymbolLocation &Loc) {
117+ void logIfOverflow (const SymbolNameLocation &Loc) {
118118 if (Loc.Start .hasOverflow () || Loc.End .hasOverflow ())
119119 log (" Possible overflow in symbol location: {0}" , Loc);
120120}
@@ -123,7 +123,7 @@ void logIfOverflow(const SymbolLocation &Loc) {
123123// TUPath is used to resolve the path of URI.
124124// FIXME: figure out a good home for it, and share the implementation with
125125// FindSymbols.
126- std::optional<Location> toLSPLocation (const SymbolLocation &Loc,
126+ std::optional<Location> toLSPLocation (const SymbolNameLocation &Loc,
127127 llvm::StringRef TUPath) {
128128 if (!Loc)
129129 return std::nullopt ;
@@ -148,8 +148,9 @@ std::optional<Location> toLSPLocation(const SymbolLocation &Loc,
148148 return LSPLoc;
149149}
150150
151- SymbolLocation toIndexLocation (const Location &Loc, std::string &URIStorage) {
152- SymbolLocation SymLoc;
151+ SymbolNameLocation toIndexLocation (const Location &Loc,
152+ std::string &URIStorage) {
153+ SymbolNameLocation SymLoc;
153154 URIStorage = Loc.uri .uri ();
154155 SymLoc.FileURI = URIStorage.c_str ();
155156 SymLoc.Start .setLine (Loc.range .start .line );
@@ -160,17 +161,17 @@ SymbolLocation toIndexLocation(const Location &Loc, std::string &URIStorage) {
160161}
161162
162163// Returns the preferred location between an AST location and an index location.
163- SymbolLocation getPreferredLocation (const Location &ASTLoc,
164- const SymbolLocation &IdxLoc,
165- std::string &Scratch) {
164+ SymbolNameLocation getPreferredLocation (const Location &ASTLoc,
165+ const SymbolNameLocation &IdxLoc,
166+ std::string &Scratch) {
166167 // Also use a mock symbol for the index location so that other fields (e.g.
167168 // definition) are not factored into the preference.
168169 Symbol ASTSym, IdxSym;
169170 ASTSym.ID = IdxSym.ID = SymbolID (" mock_symbol_id" );
170- ASTSym.CanonicalDeclaration = toIndexLocation (ASTLoc, Scratch);
171- IdxSym.CanonicalDeclaration = IdxLoc;
171+ ASTSym.CanonicalDeclaration . NameLocation = toIndexLocation (ASTLoc, Scratch);
172+ IdxSym.CanonicalDeclaration . NameLocation = IdxLoc;
172173 auto Merged = mergeSymbol (ASTSym, IdxSym);
173- return Merged.CanonicalDeclaration ;
174+ return Merged.CanonicalDeclaration . NameLocation ;
174175}
175176
176177std::vector<std::pair<const NamedDecl *, DeclRelationSet>>
@@ -323,16 +324,17 @@ std::vector<LocatedSymbol> findImplementors(llvm::DenseSet<SymbolID> IDs,
323324 Req.Subjects = std::move (IDs);
324325 std::vector<LocatedSymbol> Results;
325326 Index->relations (Req, [&](const SymbolID &Subject, const Symbol &Object) {
326- auto DeclLoc =
327- indexToLSPLocation (Object. CanonicalDeclaration , MainFilePath);
327+ auto DeclLoc = indexToLSPLocation (Object. CanonicalDeclaration . NameLocation ,
328+ MainFilePath);
328329 if (!DeclLoc) {
329330 elog (" Find overrides: {0}" , DeclLoc.takeError ());
330331 return ;
331332 }
332333 Results.emplace_back ();
333334 Results.back ().Name = Object.Name .str ();
334335 Results.back ().PreferredDeclaration = *DeclLoc;
335- auto DefLoc = indexToLSPLocation (Object.Definition , MainFilePath);
336+ auto DefLoc =
337+ indexToLSPLocation (Object.Definition .NameLocation , MainFilePath);
336338 if (!DefLoc) {
337339 elog (" Failed to convert location: {0}" , DefLoc.takeError ());
338340 return ;
@@ -364,23 +366,26 @@ void enhanceLocatedSymbolsFromIndex(llvm::MutableArrayRef<LocatedSymbol> Result,
364366 if (R.Definition ) { // from AST
365367 // Special case: if the AST yielded a definition, then it may not be
366368 // the right *declaration*. Prefer the one from the index.
367- if (auto Loc = toLSPLocation (Sym.CanonicalDeclaration , MainFilePath))
369+ if (auto Loc = toLSPLocation (Sym.CanonicalDeclaration .NameLocation ,
370+ MainFilePath))
368371 R.PreferredDeclaration = *Loc;
369372
370373 // We might still prefer the definition from the index, e.g. for
371374 // generated symbols.
372375 if (auto Loc = toLSPLocation (
373- getPreferredLocation (*R.Definition , Sym.Definition , Scratch),
376+ getPreferredLocation (*R.Definition , Sym.Definition .NameLocation ,
377+ Scratch),
374378 MainFilePath))
375379 R.Definition = *Loc;
376380 } else {
377- R.Definition = toLSPLocation (Sym.Definition , MainFilePath);
381+ R.Definition = toLSPLocation (Sym.Definition . NameLocation , MainFilePath);
378382
379383 // Use merge logic to choose AST or index declaration.
380- if (auto Loc = toLSPLocation (
381- getPreferredLocation (R.PreferredDeclaration ,
382- Sym.CanonicalDeclaration , Scratch),
383- MainFilePath))
384+ if (auto Loc =
385+ toLSPLocation (getPreferredLocation (
386+ R.PreferredDeclaration ,
387+ Sym.CanonicalDeclaration .NameLocation , Scratch),
388+ MainFilePath))
384389 R.PreferredDeclaration = *Loc;
385390 }
386391 });
@@ -606,7 +611,7 @@ std::vector<LocatedSymbol> locateSymbolTextually(const SpelledWord &Word,
606611 return ;
607612
608613 auto MaybeDeclLoc =
609- indexToLSPLocation (Sym.CanonicalDeclaration , MainFilePath);
614+ indexToLSPLocation (Sym.CanonicalDeclaration . NameLocation , MainFilePath);
610615 if (!MaybeDeclLoc) {
611616 log (" locateSymbolNamedTextuallyAt: {0}" , MaybeDeclLoc.takeError ());
612617 return ;
@@ -616,7 +621,8 @@ std::vector<LocatedSymbol> locateSymbolTextually(const SpelledWord &Word,
616621 Located.Name = (Sym.Name + Sym.TemplateSpecializationArgs ).str ();
617622 Located.ID = Sym.ID ;
618623 if (Sym.Definition ) {
619- auto MaybeDefLoc = indexToLSPLocation (Sym.Definition , MainFilePath);
624+ auto MaybeDefLoc =
625+ indexToLSPLocation (Sym.Definition .NameLocation , MainFilePath);
620626 if (!MaybeDefLoc) {
621627 log (" locateSymbolNamedTextuallyAt: {0}" , MaybeDefLoc.takeError ());
622628 return ;
@@ -1495,9 +1501,10 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
14951501 Results.HasMore = true ;
14961502 return ;
14971503 }
1498- const auto LSPLocDecl =
1499- toLSPLocation (Object.CanonicalDeclaration , MainFilePath);
1500- const auto LSPLocDef = toLSPLocation (Object.Definition , MainFilePath);
1504+ const auto LSPLocDecl = toLSPLocation (
1505+ Object.CanonicalDeclaration .NameLocation , MainFilePath);
1506+ const auto LSPLocDef =
1507+ toLSPLocation (Object.Definition .NameLocation , MainFilePath);
15011508 if (LSPLocDecl && LSPLocDecl != LSPLocDef) {
15021509 ReferencesResult::Reference Result;
15031510 Result.Loc = {std::move (*LSPLocDecl), std::nullopt };
@@ -1754,11 +1761,9 @@ static std::optional<HierarchyItem> symbolToHierarchyItem(const Symbol &S,
17541761 HierarchyItem HI;
17551762 HI.name = std::string (S.Name );
17561763 HI.kind = indexSymbolKindToSymbolKind (S.SymInfo .Kind );
1757- HI.selectionRange = Loc->range ;
1758- // FIXME: Populate 'range' correctly
1759- // (https://github.com/clangd/clangd/issues/59).
1760- HI.range = HI.selectionRange ;
1761- HI.uri = Loc->uri ;
1764+ HI.selectionRange = Loc->first .range ;
1765+ HI.range = Loc->second ;
1766+ HI.uri = Loc->first .uri ;
17621767
17631768 return HI;
17641769}
0 commit comments