Skip to content

Fix a bug related to textDocumentation/implementation #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bindings/go/scip/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func ConvertSCIPToLSIF(index *Index) ([]reader.Element, error) {
type graph struct {
ID int
Elements []reader.Element
symbolToResultSet map[string]symbolInformationIDs
symbolToResultSet map[string]*symbolInformationIDs
inverseRelationships map[string][]*Relationship
packageToGraphID map[string]int
}
Expand All @@ -110,7 +110,7 @@ func newGraph() graph {
return graph{
ID: 0,
Elements: []reader.Element{},
symbolToResultSet: map[string]symbolInformationIDs{},
symbolToResultSet: map[string]*symbolInformationIDs{},
packageToGraphID: map[string]int{},
inverseRelationships: map[string][]*Relationship{},
}
Expand All @@ -134,7 +134,7 @@ func (g *graph) emitPackage(pkg *Package) int {

// emitResultSet emits the associated resultSet, definitionResult, referenceResult, implementationResult and hoverResult
// for the provided scip.SymbolInformation.
func (g *graph) emitResultSet(info *SymbolInformation, monikerKind string) symbolInformationIDs {
func (g *graph) emitResultSet(info *SymbolInformation, monikerKind string) *symbolInformationIDs {
if ids, ok := g.symbolToResultSet[info.Symbol]; ok {
return ids
}
Expand All @@ -146,7 +146,7 @@ func (g *graph) emitResultSet(info *SymbolInformation, monikerKind string) symbo
if hasDefinition {
definitionResult = g.emitVertex("definitionResult", nil)
}
ids := symbolInformationIDs{
ids := &symbolInformationIDs{
ResultSet: g.emitVertex("resultSet", reader.ResultSet{}),
DefinitionResult: definitionResult,
ReferenceResult: g.emitVertex("referenceResult", nil),
Expand All @@ -171,7 +171,7 @@ func (g *graph) emitDocument(index *Index, doc *Document) {
documentID := g.emitVertex("document", uri)

documentSymbolTable := map[string]*SymbolInformation{}
localSymbolInformationTable := map[string]symbolInformationIDs{}
localSymbolInformationTable := map[string]*symbolInformationIDs{}
for _, info := range doc.Symbols {
documentSymbolTable[info.Symbol] = info

Expand Down Expand Up @@ -220,7 +220,7 @@ func (g *graph) emitDocument(index *Index, doc *Document) {
}

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

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

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

func (g *graph) getOrInsertSymbolInformationIDs(symbol string, localResultSetTable map[string]symbolInformationIDs) symbolInformationIDs {
func (g *graph) getOrInsertSymbolInformationIDs(symbol string, localResultSetTable map[string]*symbolInformationIDs) *symbolInformationIDs {
resultSetTable := g.symbolToResultSet
if IsLocalSymbol(symbol) {
resultSetTable = localResultSetTable
Expand Down
1 change: 1 addition & 0 deletions cmd/tests/snapshots/input/implementation/animal.repro
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Test how to implement a symbol within the same workspace.
definition animal#
definition dog# implements animal#
definition cat# implements animal#
5 changes: 5 additions & 0 deletions cmd/tests/snapshots/output/implementation/animal.repro
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
# documentation signature of dog#
# relationship animal.repro/animal# implementation
# ^^^^^^^ reference animal.repro/animal#
definition cat# implements animal#
# ^^^^ definition animal.repro/cat#
# documentation signature of cat#
# relationship animal.repro/animal# implementation
# ^^^^^^^ reference animal.repro/animal#

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