@@ -259,9 +259,11 @@ void MacroIndexer::emitExternalSymbols(bool deterministic,
259
259
TuIndexer::TuIndexer (const clang::SourceManager &sourceManager,
260
260
const clang::LangOptions &langOptions,
261
261
const clang::ASTContext &astContext,
262
- SymbolFormatter &symbolFormatter)
262
+ SymbolFormatter &symbolFormatter,
263
+ GetStableFileId getStableFileId)
263
264
: sourceManager(sourceManager), langOptions(langOptions),
264
- astContext (astContext), symbolFormatter(symbolFormatter), documentMap() {}
265
+ astContext (astContext), symbolFormatter(symbolFormatter), documentMap(),
266
+ getStableFileId(getStableFileId) {}
265
267
266
268
void TuIndexer::saveBindingDecl (const clang::BindingDecl &bindingDecl) {
267
269
auto optSymbol = this ->symbolFormatter .getBindingSymbol (bindingDecl);
@@ -669,38 +671,52 @@ void TuIndexer::emitDocumentOccurrencesAndSymbols(
669
671
}
670
672
671
673
std::pair<FileLocalSourceRange, clang::FileID>
672
- TuIndexer::getTokenExpansionRange (clang::SourceLocation startLoc) const {
673
- startLoc = this -> sourceManager . getExpansionLoc (startLoc);
674
+ TuIndexer::getTokenExpansionRange (
675
+ clang::SourceLocation startExpansionLoc) const {
674
676
auto tokenLength = clang::Lexer::MeasureTokenLength (
675
- startLoc , this ->sourceManager , this ->langOptions );
677
+ startExpansionLoc , this ->sourceManager , this ->langOptions );
676
678
ENFORCE (tokenLength > 0 );
677
- auto endLoc = startLoc .getLocWithOffset (tokenLength);
679
+ auto endLoc = startExpansionLoc .getLocWithOffset (tokenLength);
678
680
return FileLocalSourceRange::fromNonEmpty (this ->sourceManager ,
679
- {startLoc , endLoc});
681
+ {startExpansionLoc , endLoc});
680
682
}
681
683
682
684
void TuIndexer::saveReference (std::string_view symbol,
683
685
clang::SourceLocation loc, int32_t extraRoles) {
686
+ auto expansionLoc = this ->sourceManager .getExpansionLoc (loc);
687
+ auto fileId = this ->sourceManager .getFileID (expansionLoc);
688
+ auto optStableFileId = this ->getStableFileId (fileId);
689
+ if (!optStableFileId.has_value () || !optStableFileId->isInProject ) {
690
+ return ;
691
+ }
684
692
ENFORCE ((extraRoles & scip::SymbolRole::Definition) == 0 ,
685
693
" use saveDefinition instead" );
686
- (void )this ->saveOccurrence (symbol, loc , extraRoles);
694
+ (void )this ->saveOccurrence (symbol, expansionLoc , extraRoles);
687
695
}
688
696
689
697
void TuIndexer::saveDefinition (
690
698
std::string_view symbol, clang::SourceLocation loc,
691
699
std::optional<scip::SymbolInformation> &&optSymbolInfo,
692
700
int32_t extraRoles) {
693
- auto &doc = this ->saveOccurrence (symbol, loc,
694
- extraRoles | scip::SymbolRole::Definition);
695
- if (optSymbolInfo.has_value ()) {
696
- doc.symbolInfos .emplace (symbol, std::move (optSymbolInfo.value ()));
701
+ auto expansionLoc = this ->sourceManager .getExpansionLoc (loc);
702
+ auto fileId = this ->sourceManager .getFileID (expansionLoc);
703
+ auto optStableFileId = this ->getStableFileId (fileId);
704
+ if (!optStableFileId.has_value ()) {
705
+ return ;
706
+ }
707
+ if (optStableFileId->isInProject ) {
708
+ auto &doc = this ->saveOccurrence (symbol, expansionLoc,
709
+ extraRoles | scip::SymbolRole::Definition);
710
+ if (optSymbolInfo.has_value ()) {
711
+ doc.symbolInfos .emplace (symbol, std::move (optSymbolInfo.value ()));
712
+ }
697
713
}
698
714
}
699
715
700
716
PartialDocument &TuIndexer::saveOccurrence (std::string_view symbol,
701
- clang::SourceLocation loc ,
717
+ clang::SourceLocation expansionLoc ,
702
718
int32_t allRoles) {
703
- auto [range, fileId] = this ->getTokenExpansionRange (loc );
719
+ auto [range, fileId] = this ->getTokenExpansionRange (expansionLoc );
704
720
scip::Occurrence occ;
705
721
range.addToOccurrence (occ);
706
722
occ.set_symbol (symbol.data (), symbol.size ());
0 commit comments