@@ -114,14 +114,14 @@ 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}
121121
122122// Convert a SymbolLocation to LSP's Location.
123123// TUPath is used to resolve the path of URI.
124- std::optional<Location> toLSPLocation (const SymbolLocation &Loc,
124+ std::optional<Location> toLSPLocation (const SymbolNameLocation &Loc,
125125 llvm::StringRef TUPath) {
126126 if (!Loc)
127127 return std::nullopt ;
@@ -134,8 +134,9 @@ std::optional<Location> toLSPLocation(const SymbolLocation &Loc,
134134 return *LSPLoc;
135135}
136136
137- SymbolLocation toIndexLocation (const Location &Loc, std::string &URIStorage) {
138- SymbolLocation SymLoc;
137+ SymbolNameLocation toIndexLocation (const Location &Loc,
138+ std::string &URIStorage) {
139+ SymbolNameLocation SymLoc;
139140 URIStorage = Loc.uri .uri ();
140141 SymLoc.FileURI = URIStorage.c_str ();
141142 SymLoc.Start .setLine (Loc.range .start .line );
@@ -146,17 +147,17 @@ SymbolLocation toIndexLocation(const Location &Loc, std::string &URIStorage) {
146147}
147148
148149// Returns the preferred location between an AST location and an index location.
149- SymbolLocation getPreferredLocation (const Location &ASTLoc,
150- const SymbolLocation &IdxLoc,
151- std::string &Scratch) {
150+ SymbolNameLocation getPreferredLocation (const Location &ASTLoc,
151+ const SymbolNameLocation &IdxLoc,
152+ std::string &Scratch) {
152153 // Also use a mock symbol for the index location so that other fields (e.g.
153154 // definition) are not factored into the preference.
154155 Symbol ASTSym, IdxSym;
155156 ASTSym.ID = IdxSym.ID = SymbolID (" mock_symbol_id" );
156- ASTSym.CanonicalDeclaration = toIndexLocation (ASTLoc, Scratch);
157- IdxSym.CanonicalDeclaration = IdxLoc;
157+ ASTSym.CanonicalDeclaration . NameLocation = toIndexLocation (ASTLoc, Scratch);
158+ IdxSym.CanonicalDeclaration . NameLocation = IdxLoc;
158159 auto Merged = mergeSymbol (ASTSym, IdxSym);
159- return Merged.CanonicalDeclaration ;
160+ return Merged.CanonicalDeclaration . NameLocation ;
160161}
161162
162163std::vector<std::pair<const NamedDecl *, DeclRelationSet>>
@@ -309,16 +310,17 @@ std::vector<LocatedSymbol> findImplementors(llvm::DenseSet<SymbolID> IDs,
309310 Req.Subjects = std::move (IDs);
310311 std::vector<LocatedSymbol> Results;
311312 Index->relations (Req, [&](const SymbolID &Subject, const Symbol &Object) {
312- auto DeclLoc =
313- indexToLSPLocation (Object. CanonicalDeclaration , MainFilePath);
313+ auto DeclLoc = indexToLSPLocation (Object. CanonicalDeclaration . NameLocation ,
314+ MainFilePath);
314315 if (!DeclLoc) {
315316 elog (" Find overrides: {0}" , DeclLoc.takeError ());
316317 return ;
317318 }
318319 Results.emplace_back ();
319320 Results.back ().Name = Object.Name .str ();
320321 Results.back ().PreferredDeclaration = *DeclLoc;
321- auto DefLoc = indexToLSPLocation (Object.Definition , MainFilePath);
322+ auto DefLoc =
323+ indexToLSPLocation (Object.Definition .NameLocation , MainFilePath);
322324 if (!DefLoc) {
323325 elog (" Failed to convert location: {0}" , DefLoc.takeError ());
324326 return ;
@@ -350,23 +352,26 @@ void enhanceLocatedSymbolsFromIndex(llvm::MutableArrayRef<LocatedSymbol> Result,
350352 if (R.Definition ) { // from AST
351353 // Special case: if the AST yielded a definition, then it may not be
352354 // the right *declaration*. Prefer the one from the index.
353- if (auto Loc = toLSPLocation (Sym.CanonicalDeclaration , MainFilePath))
355+ if (auto Loc = toLSPLocation (Sym.CanonicalDeclaration .NameLocation ,
356+ MainFilePath))
354357 R.PreferredDeclaration = *Loc;
355358
356359 // We might still prefer the definition from the index, e.g. for
357360 // generated symbols.
358361 if (auto Loc = toLSPLocation (
359- getPreferredLocation (*R.Definition , Sym.Definition , Scratch),
362+ getPreferredLocation (*R.Definition , Sym.Definition .NameLocation ,
363+ Scratch),
360364 MainFilePath))
361365 R.Definition = *Loc;
362366 } else {
363- R.Definition = toLSPLocation (Sym.Definition , MainFilePath);
367+ R.Definition = toLSPLocation (Sym.Definition . NameLocation , MainFilePath);
364368
365369 // Use merge logic to choose AST or index declaration.
366- if (auto Loc = toLSPLocation (
367- getPreferredLocation (R.PreferredDeclaration ,
368- Sym.CanonicalDeclaration , Scratch),
369- MainFilePath))
370+ if (auto Loc =
371+ toLSPLocation (getPreferredLocation (
372+ R.PreferredDeclaration ,
373+ Sym.CanonicalDeclaration .NameLocation , Scratch),
374+ MainFilePath))
370375 R.PreferredDeclaration = *Loc;
371376 }
372377 });
@@ -592,7 +597,7 @@ std::vector<LocatedSymbol> locateSymbolTextually(const SpelledWord &Word,
592597 return ;
593598
594599 auto MaybeDeclLoc =
595- indexToLSPLocation (Sym.CanonicalDeclaration , MainFilePath);
600+ indexToLSPLocation (Sym.CanonicalDeclaration . NameLocation , MainFilePath);
596601 if (!MaybeDeclLoc) {
597602 log (" locateSymbolNamedTextuallyAt: {0}" , MaybeDeclLoc.takeError ());
598603 return ;
@@ -602,7 +607,8 @@ std::vector<LocatedSymbol> locateSymbolTextually(const SpelledWord &Word,
602607 Located.Name = (Sym.Name + Sym.TemplateSpecializationArgs ).str ();
603608 Located.ID = Sym.ID ;
604609 if (Sym.Definition ) {
605- auto MaybeDefLoc = indexToLSPLocation (Sym.Definition , MainFilePath);
610+ auto MaybeDefLoc =
611+ indexToLSPLocation (Sym.Definition .NameLocation , MainFilePath);
606612 if (!MaybeDefLoc) {
607613 log (" locateSymbolNamedTextuallyAt: {0}" , MaybeDefLoc.takeError ());
608614 return ;
@@ -1481,9 +1487,10 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
14811487 Results.HasMore = true ;
14821488 return ;
14831489 }
1484- const auto LSPLocDecl =
1485- toLSPLocation (Object.CanonicalDeclaration , MainFilePath);
1486- const auto LSPLocDef = toLSPLocation (Object.Definition , MainFilePath);
1490+ const auto LSPLocDecl = toLSPLocation (
1491+ Object.CanonicalDeclaration .NameLocation , MainFilePath);
1492+ const auto LSPLocDef =
1493+ toLSPLocation (Object.Definition .NameLocation , MainFilePath);
14871494 if (LSPLocDecl && LSPLocDecl != LSPLocDef) {
14881495 ReferencesResult::Reference Result;
14891496 Result.Loc = {std::move (*LSPLocDecl), std::nullopt };
@@ -1742,11 +1749,9 @@ static std::optional<HierarchyItem> symbolToHierarchyItem(const Symbol &S,
17421749 HI.name = std::string (S.Name );
17431750 HI.detail = (S.Scope + S.Name ).str ();
17441751 HI.kind = indexSymbolKindToSymbolKind (S.SymInfo .Kind );
1745- HI.selectionRange = Loc->range ;
1746- // FIXME: Populate 'range' correctly
1747- // (https://github.com/clangd/clangd/issues/59).
1748- HI.range = HI.selectionRange ;
1749- HI.uri = Loc->uri ;
1752+ HI.selectionRange = Loc->first .range ;
1753+ HI.range = Loc->second ;
1754+ HI.uri = Loc->first .uri ;
17501755
17511756 return HI;
17521757}
0 commit comments