Skip to content

Commit 12459c7

Browse files
authored
Fix a bug where goto definition did not work when SymbolInformation was missing (#36)
* Reproduce the bug where SymbolInformation is missing * Fix the bug * Remove debugging lines * Add back the actual if statement
1 parent 21301fa commit 12459c7

File tree

7 files changed

+78
-0
lines changed

7 files changed

+78
-0
lines changed

bindings/go/scip/convert.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ func ConvertSCIPToLSIF(index *Index) ([]reader.Element, error) {
7878
g.symbolToResultSet[exportedSymbol.Symbol] = g.emitResultSet(exportedSymbol, "export")
7979
}
8080
}
81+
for _, occ := range document.Occurrences {
82+
if !SymbolRole_Definition.Matches(occ) {
83+
continue
84+
}
85+
if IsLocalSymbol(occ.Symbol) {
86+
continue
87+
}
88+
if _, ok := g.symbolToResultSet[occ.Symbol]; ok {
89+
continue
90+
}
91+
g.symbolToResultSet[occ.Symbol] = g.emitResultSet(&SymbolInformation{Symbol: occ.Symbol}, "export")
92+
}
8193
}
8294

8395
// Pass 2: emit ranges for all documents.
@@ -194,6 +206,19 @@ func (g *graph) emitDocument(index *Index, doc *Document) {
194206
}
195207
}
196208

209+
for _, occ := range doc.Occurrences {
210+
if !SymbolRole_Definition.Matches(occ) {
211+
continue
212+
}
213+
if !IsLocalSymbol(occ.Symbol) {
214+
continue
215+
}
216+
if _, ok := localSymbolInformationTable[occ.Symbol]; ok {
217+
continue
218+
}
219+
localSymbolInformationTable[occ.Symbol] = g.emitResultSet(&SymbolInformation{Symbol: occ.Symbol}, "local")
220+
}
221+
197222
var rangeIDs []int
198223
for _, occ := range doc.Occurrences {
199224
rangeID, err := g.emitRange(occ.Range)

cmd/tests/reprolang/bindings/go/repro/scip.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package repro
22

33
import (
44
"sort"
5+
"strings"
56

67
"github.com/sourcegraph/scip/bindings/go/scip"
78
)
@@ -17,6 +18,9 @@ func (i *identifier) occurrence(roles scip.SymbolRole) *scip.Occurrence {
1718
func (s *reproSourceFile) symbols() []*scip.SymbolInformation {
1819
var result []*scip.SymbolInformation
1920
for _, def := range s.definitions {
21+
if strings.Index(def.name.value, "NoSymbolInformation") >= 0 {
22+
continue
23+
}
2024
documentation := []string{"signature of " + def.name.value}
2125
if def.docstring != "" {
2226
documentation = append(documentation, def.docstring)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
definition NoSymbolInformation#
2+
reference NoSymbolInformation#
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
definition localNoSymbolInformation
2+
reference localNoSymbolInformation
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{"id":1,"version":"0.4.3","projectRoot":"file:/root","positionEncoding":"utf-8","toolInfo":{"name":"reprolang","version":"1.0.0"},"type":"vertex","label":"metaData"}
2+
{"id":2,"type":"vertex","label":"definitionResult"}
3+
{"id":3,"type":"vertex","label":"resultSet"}
4+
{"id":4,"type":"vertex","label":"referenceResult"}
5+
{"id":5,"type":"vertex","label":"hoverResult","result":{"contents":{"kind":"markdown"}}}
6+
{"id":6,"type":"edge","label":"textDocument/definition","inV":2,"outV":3}
7+
{"id":7,"type":"edge","label":"textDocument/references","inV":4,"outV":3}
8+
{"id":8,"type":"edge","label":"textDocument/hover","inV":5,"outV":3}
9+
{"id":9,"type":"vertex","label":"moniker","identifier":"reprolang repro_manager missing-symbol-information 1.0.0 globals.repro/NoSymbolInformation#","kind":"export","scheme":"reprolang"}
10+
{"id":10,"type":"edge","label":"moniker","inV":9,"outV":3}
11+
{"id":11,"name":"missing-symbol-information","version":"1.0.0","manager":"repro_manager","type":"vertex","label":"packageInformation"}
12+
{"id":12,"type":"edge","label":"packageInformation","inV":11,"outV":9}
13+
{"id":13,"type":"vertex","label":"document","uri":"file:/root/globals.repro"}
14+
{"id":14,"type":"vertex","label":"range","start":{"line":0,"character":11},"end":{"line":0,"character":31}}
15+
{"id":15,"type":"edge","label":"next","inV":3,"outV":14}
16+
{"id":16,"type":"edge","label":"item","inVs":[14],"outV":2,"document":13}
17+
{"id":17,"type":"edge","label":"item","inVs":[14],"outV":4,"document":13}
18+
{"id":18,"type":"vertex","label":"range","start":{"line":1,"character":10},"end":{"line":1,"character":30}}
19+
{"id":19,"type":"edge","label":"next","inV":3,"outV":18}
20+
{"id":20,"type":"edge","label":"item","inVs":[18],"outV":4,"document":13}
21+
{"id":21,"type":"edge","label":"contains","inVs":[14,18],"outV":13}
22+
{"id":22,"type":"vertex","label":"document","uri":"file:/root/locals.repro"}
23+
{"id":23,"type":"vertex","label":"definitionResult"}
24+
{"id":24,"type":"vertex","label":"resultSet"}
25+
{"id":25,"type":"vertex","label":"referenceResult"}
26+
{"id":26,"type":"vertex","label":"hoverResult","result":{"contents":{"kind":"markdown"}}}
27+
{"id":27,"type":"edge","label":"textDocument/definition","inV":23,"outV":24}
28+
{"id":28,"type":"edge","label":"textDocument/references","inV":25,"outV":24}
29+
{"id":29,"type":"edge","label":"textDocument/hover","inV":26,"outV":24}
30+
{"id":30,"type":"vertex","label":"range","start":{"line":0,"character":11},"end":{"line":0,"character":35}}
31+
{"id":31,"type":"edge","label":"next","inV":24,"outV":30}
32+
{"id":32,"type":"edge","label":"item","inVs":[30],"outV":23,"document":22}
33+
{"id":33,"type":"edge","label":"item","inVs":[30],"outV":25,"document":22}
34+
{"id":34,"type":"vertex","label":"range","start":{"line":1,"character":10},"end":{"line":1,"character":34}}
35+
{"id":35,"type":"edge","label":"next","inV":24,"outV":34}
36+
{"id":36,"type":"edge","label":"item","inVs":[34],"outV":25,"document":22}
37+
{"id":37,"type":"edge","label":"contains","inVs":[30,34],"outV":22}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
definition NoSymbolInformation#
2+
# ^^^^^^^^^^^^^^^^^^^^ definition globals.repro/NoSymbolInformation#
3+
reference NoSymbolInformation#
4+
# ^^^^^^^^^^^^^^^^^^^^ reference globals.repro/NoSymbolInformation#
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
definition localNoSymbolInformation
2+
# ^^^^^^^^^^^^^^^^^^^^^^^^ definition local NoSymbolInformation
3+
reference localNoSymbolInformation
4+
# ^^^^^^^^^^^^^^^^^^^^^^^^ reference local NoSymbolInformation

0 commit comments

Comments
 (0)