diff --git a/scip_indexer/SCIPIndexer.cc b/scip_indexer/SCIPIndexer.cc index 198c8d82e..92cb79993 100644 --- a/scip_indexer/SCIPIndexer.cc +++ b/scip_indexer/SCIPIndexer.cc @@ -290,14 +290,19 @@ class SCIPState { core::Loc occLoc, const SmallVec &docs, const SmallVec &rels) { ENFORCE(!symbolString.empty()); - - auto emitted = this->saveSymbolInfo(file, symbolString, docs, rels); - occLoc = trimColonColonPrefix(gs, occLoc); + auto range = sorbet::scip_indexer::fromSorbetLoc(gs, occLoc); + if (range.size() == 4) { + // Don't emit multiline occurrences; generally this indicates a bug in the indexer. + // FIXME: This causes us to miss the definition for the initialize method + // in the struct.rb test case. + return absl::OkStatus(); + } + auto emitted = this->saveSymbolInfo(file, symbolString, docs, rels); scip::Occurrence occurrence; occurrence.set_symbol(symbolString); occurrence.set_symbol_roles(scip::SymbolRole::Definition); - for (auto val : sorbet::scip_indexer::fromSorbetLoc(gs, occLoc)) { + for (auto val : range) { occurrence.add_range(val); } switch (emitted) { @@ -320,7 +325,12 @@ class SCIPState { scip::Occurrence occurrence; occurrence.set_symbol(symbolString); occurrence.set_symbol_roles(symbol_roles); - for (auto val : sorbet::scip_indexer::fromSorbetLoc(gs, occLoc)) { + auto range = sorbet::scip_indexer::fromSorbetLoc(gs, occLoc); + if (range.size() == 4) { + // Don't emit multiline occurrences; generally this indicates a bug in the indexer. + return; + } + for (auto val : range) { occurrence.add_range(val); } for (auto &doc : overrideDocs) { diff --git a/test/scip/testdata/struct.snapshot.rb b/test/scip/testdata/struct.snapshot.rb index 9e2deba69..9d5dcf6fd 100644 --- a/test/scip/testdata/struct.snapshot.rb +++ b/test/scip/testdata/struct.snapshot.rb @@ -50,10 +50,6 @@ def f #^^^^^ reference [..] POINT# #^^^^^ definition [..] POINT# #^^^^^ definition [..] POINT# -#^^^^^^^^^^^^^^^^^^^^ reference [..] Struct# -#^^^^^^^^^^^^^^^^^^^^ definition local 2~#119448696 -#^^^^^^^^^^^^^^^^^^^^ definition local 5~#119448696 -#^^^^^^^^^^^^^^^^^^^^ definition [..] POINT#initialize(). # ^ definition [..] POINT#`x=`(). # ^ definition [..] POINT#x(). # ^ reference [..] BasicObject# diff --git a/test/scip_test_runner.cc b/test/scip_test_runner.cc index 5e2b732eb..5e07681a9 100644 --- a/test/scip_test_runner.cc +++ b/test/scip_test_runner.cc @@ -311,6 +311,7 @@ struct SCIPRange final { auto &r = protoRange; if (r.size() == 4) { *this = SCIPRange(SCIPPosition{r[0] + 1, r[1] + 1}, SCIPPosition{r[2] + 1, r[3] + 1}); + return; } *this = SCIPRange(SCIPPosition{r[0] + 1, r[1] + 1}, SCIPPosition{r[0] + 1, r[2] + 1}); } @@ -366,6 +367,7 @@ void formatSnapshot(const scip::Document &document, FormatOptions options, std:: auto occ = occurrences[occ_i]; auto range = SCIPRange(occ.range()); if (range.isMultiline()) { // FIXME(varun): Handle multiline occurrences. + ENFORCE(false, "Got multiline occurrence which shouldn't have been emitted: {}", range.toString()); continue; } bool isDefinition = ((unsigned(occ.symbol_roles()) & unsigned(scip::SymbolRole::Definition)) > 0);