Skip to content

Commit 5922ee0

Browse files
authored
Fix a bug related to textDocumentation/implementation (#27)
* Reproduce a bug where we emit multiple `implementationResult` for the same symbol * Fix a bug for textDocument/implementation Previously, we emitted multiple `implementationResult` because we used the wrong `symbolInformationIDs`.
1 parent 749d605 commit 5922ee0

File tree

4 files changed

+56
-29
lines changed

4 files changed

+56
-29
lines changed

bindings/go/scip/convert.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func ConvertSCIPToLSIF(index *Index) ([]reader.Element, error) {
9292
type graph struct {
9393
ID int
9494
Elements []reader.Element
95-
symbolToResultSet map[string]symbolInformationIDs
95+
symbolToResultSet map[string]*symbolInformationIDs
9696
inverseRelationships map[string][]*Relationship
9797
packageToGraphID map[string]int
9898
}
@@ -110,7 +110,7 @@ func newGraph() graph {
110110
return graph{
111111
ID: 0,
112112
Elements: []reader.Element{},
113-
symbolToResultSet: map[string]symbolInformationIDs{},
113+
symbolToResultSet: map[string]*symbolInformationIDs{},
114114
packageToGraphID: map[string]int{},
115115
inverseRelationships: map[string][]*Relationship{},
116116
}
@@ -134,7 +134,7 @@ func (g *graph) emitPackage(pkg *Package) int {
134134

135135
// emitResultSet emits the associated resultSet, definitionResult, referenceResult, implementationResult and hoverResult
136136
// for the provided scip.SymbolInformation.
137-
func (g *graph) emitResultSet(info *SymbolInformation, monikerKind string) symbolInformationIDs {
137+
func (g *graph) emitResultSet(info *SymbolInformation, monikerKind string) *symbolInformationIDs {
138138
if ids, ok := g.symbolToResultSet[info.Symbol]; ok {
139139
return ids
140140
}
@@ -146,7 +146,7 @@ func (g *graph) emitResultSet(info *SymbolInformation, monikerKind string) symbo
146146
if hasDefinition {
147147
definitionResult = g.emitVertex("definitionResult", nil)
148148
}
149-
ids := symbolInformationIDs{
149+
ids := &symbolInformationIDs{
150150
ResultSet: g.emitVertex("resultSet", reader.ResultSet{}),
151151
DefinitionResult: definitionResult,
152152
ReferenceResult: g.emitVertex("referenceResult", nil),
@@ -171,7 +171,7 @@ func (g *graph) emitDocument(index *Index, doc *Document) {
171171
documentID := g.emitVertex("document", uri)
172172

173173
documentSymbolTable := map[string]*SymbolInformation{}
174-
localSymbolInformationTable := map[string]symbolInformationIDs{}
174+
localSymbolInformationTable := map[string]*symbolInformationIDs{}
175175
for _, info := range doc.Symbols {
176176
documentSymbolTable[info.Symbol] = info
177177

@@ -220,7 +220,7 @@ func (g *graph) emitDocument(index *Index, doc *Document) {
220220
}
221221

222222
// emitRelationships emits "referenceResults" and "implementationResult" based on the value of scip.SymbolInformation.Relationships
223-
func (g *graph) emitRelationships(rangeID, documentID int, resultIDs symbolInformationIDs, localResultIDs map[string]symbolInformationIDs, info *SymbolInformation) {
223+
func (g *graph) emitRelationships(rangeID, documentID int, resultIDs *symbolInformationIDs, localResultIDs map[string]*symbolInformationIDs, info *SymbolInformation) {
224224
var allReferenceResultIds []int
225225
relationships := g.inverseRelationships[info.Symbol]
226226
for _, relationship := range relationships {
@@ -240,7 +240,7 @@ func (g *graph) emitRelationships(rangeID, documentID int, resultIDs symbolInfor
240240
}
241241
}
242242

243-
func (g *graph) emitRelationship(relationship *Relationship, rangeID, documentID int, localResultIDs map[string]symbolInformationIDs) []int {
243+
func (g *graph) emitRelationship(relationship *Relationship, rangeID, documentID int, localResultIDs map[string]*symbolInformationIDs) []int {
244244
relationshipIDs := g.getOrInsertSymbolInformationIDs(relationship.Symbol, localResultIDs)
245245

246246
if relationship.IsImplementation {
@@ -373,7 +373,7 @@ func interpretSCIPRange(scipRange []int32) (startLine, startCharacter, endLine,
373373
return 0, 0, 0, 0, errors.Newf("invalid SCIP range %v", scipRange)
374374
}
375375

376-
func (g *graph) getOrInsertSymbolInformationIDs(symbol string, localResultSetTable map[string]symbolInformationIDs) symbolInformationIDs {
376+
func (g *graph) getOrInsertSymbolInformationIDs(symbol string, localResultSetTable map[string]*symbolInformationIDs) *symbolInformationIDs {
377377
resultSetTable := g.symbolToResultSet
378378
if IsLocalSymbol(symbol) {
379379
resultSetTable = localResultSetTable
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Test how to implement a symbol within the same workspace.
22
definition animal#
33
definition dog# implements animal#
4+
definition cat# implements animal#

cmd/tests/snapshots/output/implementation/animal.repro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77
# documentation signature of dog#
88
# relationship animal.repro/animal# implementation
99
# ^^^^^^^ reference animal.repro/animal#
10+
definition cat# implements animal#
11+
# ^^^^ definition animal.repro/cat#
12+
# documentation signature of cat#
13+
# relationship animal.repro/animal# implementation
14+
# ^^^^^^^ reference animal.repro/animal#
1015

cmd/tests/snapshots/output/implementation/dump.lsif

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,50 @@
1313
{"id":13,"type":"vertex","label":"definitionResult"}
1414
{"id":14,"type":"vertex","label":"resultSet"}
1515
{"id":15,"type":"vertex","label":"referenceResult"}
16-
{"id":16,"type":"vertex","label":"hoverResult","result":{"contents":{"kind":"markdown","value":"signature of dog#"}}}
16+
{"id":16,"type":"vertex","label":"hoverResult","result":{"contents":{"kind":"markdown","value":"signature of cat#"}}}
1717
{"id":17,"type":"edge","label":"textDocument/definition","inV":13,"outV":14}
1818
{"id":18,"type":"edge","label":"textDocument/references","inV":15,"outV":14}
1919
{"id":19,"type":"edge","label":"textDocument/hover","inV":16,"outV":14}
20-
{"id":20,"type":"vertex","label":"moniker","identifier":"reprolang repro_manager implementation 1.0.0 animal.repro/dog#","kind":"export","scheme":"reprolang"}
20+
{"id":20,"type":"vertex","label":"moniker","identifier":"reprolang repro_manager implementation 1.0.0 animal.repro/cat#","kind":"export","scheme":"reprolang"}
2121
{"id":21,"type":"edge","label":"moniker","inV":20,"outV":14}
2222
{"id":22,"type":"edge","label":"packageInformation","inV":11,"outV":20}
23-
{"id":23,"type":"vertex","label":"document","uri":"file:/root/animal.repro"}
24-
{"id":24,"type":"vertex","label":"range","start":{"line":1,"character":11},"end":{"line":1,"character":18}}
25-
{"id":25,"type":"edge","label":"next","inV":3,"outV":24}
26-
{"id":26,"type":"edge","label":"item","inVs":[24],"outV":2,"document":23}
27-
{"id":27,"type":"vertex","label":"implementationResult"}
28-
{"id":28,"type":"edge","label":"textDocument/implementation","inV":27,"outV":14}
29-
{"id":29,"type":"edge","label":"item","inVs":[24],"outV":27,"document":23}
30-
{"id":30,"type":"edge","label":"item","inVs":[24],"outV":4,"document":23}
31-
{"id":31,"type":"vertex","label":"range","start":{"line":2,"character":11},"end":{"line":2,"character":15}}
32-
{"id":32,"type":"edge","label":"next","inV":14,"outV":31}
33-
{"id":33,"type":"edge","label":"item","inVs":[31],"outV":13,"document":23}
34-
{"id":34,"type":"vertex","label":"implementationResult"}
35-
{"id":35,"type":"edge","label":"textDocument/implementation","inV":34,"outV":3}
36-
{"id":36,"type":"edge","label":"item","inVs":[31],"outV":34,"document":23}
37-
{"id":37,"type":"edge","label":"item","inVs":[31],"outV":15,"document":23}
38-
{"id":38,"type":"vertex","label":"range","start":{"line":2,"character":27},"end":{"line":2,"character":34}}
39-
{"id":39,"type":"edge","label":"next","inV":3,"outV":38}
40-
{"id":40,"type":"edge","label":"item","inVs":[38],"outV":4,"document":23}
41-
{"id":41,"type":"edge","label":"contains","inVs":[24,31,38],"outV":23}
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","value":"signature of dog#"}}}
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":"moniker","identifier":"reprolang repro_manager implementation 1.0.0 animal.repro/dog#","kind":"export","scheme":"reprolang"}
31+
{"id":31,"type":"edge","label":"moniker","inV":30,"outV":24}
32+
{"id":32,"type":"edge","label":"packageInformation","inV":11,"outV":30}
33+
{"id":33,"type":"vertex","label":"document","uri":"file:/root/animal.repro"}
34+
{"id":34,"type":"vertex","label":"range","start":{"line":1,"character":11},"end":{"line":1,"character":18}}
35+
{"id":35,"type":"edge","label":"next","inV":3,"outV":34}
36+
{"id":36,"type":"edge","label":"item","inVs":[34],"outV":2,"document":33}
37+
{"id":37,"type":"vertex","label":"implementationResult"}
38+
{"id":38,"type":"edge","label":"textDocument/implementation","inV":37,"outV":14}
39+
{"id":39,"type":"edge","label":"item","inVs":[34],"outV":37,"document":33}
40+
{"id":40,"type":"vertex","label":"implementationResult"}
41+
{"id":41,"type":"edge","label":"textDocument/implementation","inV":40,"outV":24}
42+
{"id":42,"type":"edge","label":"item","inVs":[34],"outV":40,"document":33}
43+
{"id":43,"type":"edge","label":"item","inVs":[34],"outV":4,"document":33}
44+
{"id":44,"type":"vertex","label":"range","start":{"line":2,"character":11},"end":{"line":2,"character":15}}
45+
{"id":45,"type":"edge","label":"next","inV":24,"outV":44}
46+
{"id":46,"type":"edge","label":"item","inVs":[44],"outV":23,"document":33}
47+
{"id":47,"type":"vertex","label":"implementationResult"}
48+
{"id":48,"type":"edge","label":"textDocument/implementation","inV":47,"outV":3}
49+
{"id":49,"type":"edge","label":"item","inVs":[44],"outV":47,"document":33}
50+
{"id":50,"type":"edge","label":"item","inVs":[44],"outV":25,"document":33}
51+
{"id":51,"type":"vertex","label":"range","start":{"line":2,"character":27},"end":{"line":2,"character":34}}
52+
{"id":52,"type":"edge","label":"next","inV":3,"outV":51}
53+
{"id":53,"type":"edge","label":"item","inVs":[51],"outV":4,"document":33}
54+
{"id":54,"type":"vertex","label":"range","start":{"line":3,"character":11},"end":{"line":3,"character":15}}
55+
{"id":55,"type":"edge","label":"next","inV":14,"outV":54}
56+
{"id":56,"type":"edge","label":"item","inVs":[54],"outV":13,"document":33}
57+
{"id":57,"type":"edge","label":"item","inVs":[54],"outV":47,"document":33}
58+
{"id":58,"type":"edge","label":"item","inVs":[54],"outV":15,"document":33}
59+
{"id":59,"type":"vertex","label":"range","start":{"line":3,"character":27},"end":{"line":3,"character":34}}
60+
{"id":60,"type":"edge","label":"next","inV":3,"outV":59}
61+
{"id":61,"type":"edge","label":"item","inVs":[59],"outV":4,"document":33}
62+
{"id":62,"type":"edge","label":"contains","inVs":[34,44,51,54,59],"outV":33}

0 commit comments

Comments
 (0)