[clangd] Avoid round-trip from SourceLocation to clangd::Range and back in SymbolCollector::handleMacros() (#127757)
This commit is contained in:
@@ -18,10 +18,13 @@
|
||||
namespace clang {
|
||||
namespace clangd {
|
||||
|
||||
Range MacroOccurrence::toRange(const SourceManager &SM) const {
|
||||
CharSourceRange MacroOccurrence::toSourceRange(const SourceManager &SM) const {
|
||||
auto MainFile = SM.getMainFileID();
|
||||
return halfOpenToRange(
|
||||
SM, syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM));
|
||||
return syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM);
|
||||
}
|
||||
|
||||
Range MacroOccurrence::toRange(const SourceManager &SM) const {
|
||||
return halfOpenToRange(SM, toSourceRange(SM));
|
||||
}
|
||||
|
||||
void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
|
||||
|
||||
@@ -31,6 +31,7 @@ struct MacroOccurrence {
|
||||
// True if the occurence is used in a conditional directive, e.g. #ifdef MACRO
|
||||
bool InConditionalDirective;
|
||||
|
||||
CharSourceRange toSourceRange(const SourceManager &SM) const;
|
||||
Range toRange(const SourceManager &SM) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -713,7 +713,8 @@ void SymbolCollector::handleMacros(const MainFileMacros &MacroRefsToIndex) {
|
||||
// Add macro references.
|
||||
for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) {
|
||||
for (const auto &MacroRef : IDToRefs.second) {
|
||||
const auto &Range = MacroRef.toRange(SM);
|
||||
const auto &SR = MacroRef.toSourceRange(SM);
|
||||
auto Range = halfOpenToRange(SM, SR);
|
||||
bool IsDefinition = MacroRef.IsDefinition;
|
||||
Ref R;
|
||||
R.Location.Start.setLine(Range.start.line);
|
||||
@@ -726,9 +727,7 @@ void SymbolCollector::handleMacros(const MainFileMacros &MacroRefsToIndex) {
|
||||
if (IsDefinition) {
|
||||
Symbol S;
|
||||
S.ID = IDToRefs.first;
|
||||
auto StartLoc = cantFail(sourceLocationInMainFile(SM, Range.start));
|
||||
auto EndLoc = cantFail(sourceLocationInMainFile(SM, Range.end));
|
||||
S.Name = toSourceCode(SM, SourceRange(StartLoc, EndLoc));
|
||||
S.Name = toSourceCode(SM, SR.getAsRange());
|
||||
S.SymInfo.Kind = index::SymbolKind::Macro;
|
||||
S.SymInfo.SubKind = index::SymbolSubKind::None;
|
||||
S.SymInfo.Properties = index::SymbolPropertySet();
|
||||
|
||||
Reference in New Issue
Block a user