Skip to content
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

fix: skip exported symbols with no definition #72

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions bindings/go/scip/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,24 @@ func ConvertSCIPToLSIF(index *Index) ([]reader.Element, error) {
},
)

// Emit a warning with the symbols for a document that were exported
// but had no definition. Only display one message so that there are fewer warnings
// displayed to users.
exportedSymbolsWithNoDefinition := []string{}

// Pass 1: create result sets for global symbols.
for _, importedSymbol := range index.ExternalSymbols {
g.symbolToResultSet[importedSymbol.Symbol] = g.emitResultSet(importedSymbol, "import")
}
for _, document := range index.Documents {
for _, exportedSymbol := range document.Symbols {
// If an exported symbol is not defined in a document,
// do not emit a definition for this symbol.
if !document.HasDefinition(exportedSymbol) {
exportedSymbolsWithNoDefinition = append(exportedSymbolsWithNoDefinition, exportedSymbol.Symbol)
continue
}

g.registerInverseRelationships(exportedSymbol)
if IsGlobalSymbol(exportedSymbol.Symbol) {
// Local symbols are skipped here because we handle them in the
Expand All @@ -97,6 +109,14 @@ func ConvertSCIPToLSIF(index *Index) ([]reader.Element, error) {
g.emitDocument(index, document)
}

// TODO: We could instead pass back a list of warnings to be displayed by callers?
// I don't really like just printing to stdout here (additionally, these could be coallesced between documents)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we shouldn't be printing to stdout here. For example, having this output in src CLI would not be useful when looking at logs. Instead, any I/O should be happening within scip CLI.

if len(exportedSymbolsWithNoDefinition) > 0 {
fmt.Println("[scip-go] Warning: The following exported symbols were ignored because they were missing a definition")
fmt.Println(" (did you intend to put this symbol into Index.external_symbols?)")
fmt.Println(exportedSymbolsWithNoDefinition)
}

return g.Elements, nil
}

Expand Down
11 changes: 11 additions & 0 deletions bindings/go/scip/document.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package scip

func (d *Document) HasDefinition(symbol *SymbolInformation) bool {
for _, occ := range d.Occurrences {
if occ.Symbol == symbol.Symbol && SymbolRole_Definition.Matches(occ) {
return true
}
}

return false
}