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

feat: Add SymbolRole for representing forward declarations #217

Merged
merged 5 commits into from
Nov 3, 2023
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
2 changes: 1 addition & 1 deletion bindings/go/scip/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (g *graph) emitDocument(index *Index, doc *Document) {
rangeIDs = append(rangeIDs, rangeID)
resultIDs := g.getOrInsertSymbolInformationIDs(occ.Symbol, localSymbolInformationTable)
g.emitEdge("next", reader.Edge{OutV: rangeID, InV: resultIDs.ResultSet})
isDefinition := occ.SymbolRoles&int32(SymbolRole_Definition) != 0
isDefinition := SymbolRole_Definition.Matches(occ)
if isDefinition && resultIDs.DefinitionResult > 0 {
g.emitEdge("item", reader.Edge{OutV: resultIDs.DefinitionResult, InVs: []int{rangeID}, Document: documentID})
symbolInfo, ok := documentSymbolTable[occ.Symbol]
Expand Down
329 changes: 169 additions & 160 deletions bindings/go/scip/scip.pb.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion bindings/go/scip/testutil/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ func FormatSnapshot(
}
b.WriteRune(' ')
role := "reference"
isDefinition := occ.SymbolRoles&int32(scip.SymbolRole_Definition) > 0
isDefinition := scip.SymbolRole_Definition.Matches(occ)
if isDefinition {
role = "definition"
} else if scip.SymbolRole_ForwardDefinition.Matches(occ) {
role = "forward_definition"
}
b.WriteString(role)
b.WriteRune(' ')
Expand Down
1,120 changes: 570 additions & 550 deletions bindings/haskell/src/Proto/Scip.hs

Large diffs are not rendered by default.

1,099 changes: 556 additions & 543 deletions bindings/rust/src/generated/scip.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion bindings/typescript/scip.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions cmd/scip/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ func (st *symbolTable) addOccurrence(path string, occ *scip.Occurrence) error {
if occ.Symbol == "" {
return emptyStringError{what: "symbol", context: fmt.Sprintf("occurrence at %s @ %s", path, scipRangeToString(*scip.NewRange(occ.Range)))}
}
if scip.SymbolRole_Definition.Matches(occ) && scip.SymbolRole_ForwardDefinition.Matches(occ) {
return forwardDefIsDefinitionError{occ.Symbol, path, *scip.NewRange(occ.Range)}
}
tryInsertOccurrence := func(occMap fileOccurrenceMap) error {
occKey := scipOccurrenceKey(occ)
if fileOccs, ok := occMap[path]; ok {
Expand Down Expand Up @@ -327,6 +330,17 @@ func (e missingSymbolForOccurrenceError) Error() string {
" in external symbols or any document", e.path, scipRangeToString(e.occ), e.symbol)
}

type forwardDefIsDefinitionError struct {
symbol string
path string
range_ scip.Range
}

func (e forwardDefIsDefinitionError) Error() string {
return fmt.Sprintf("error: forward declaration for %v at %v @ %v was marked as definition",
e.symbol, e.path, scipRangeToString(e.range_))
}

type duplicateOccurrenceWarning struct {
symbol string
path string
Expand Down
3 changes: 2 additions & 1 deletion cmd/scip/tests/reprolang/bindings/go/repro/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func (r *relationships) identifiers() []*identifier {
}

type referenceStatement struct {
name *identifier
name *identifier
isForwardDef bool
}

type identifier struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/scip/tests/reprolang/bindings/go/repro/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func (s *reproSourceFile) loadStatements() {
}
case "reference_statement":
s.references = append(s.references, &referenceStatement{
name: newIdentifier(s, child.ChildByFieldName("name")),
name: newIdentifier(s, child.ChildByFieldName("name")),
isForwardDef: child.ChildByFieldName("forward_definition") != nil,
})
}
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/scip/tests/reprolang/bindings/go/repro/scip.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func (s *reproSourceFile) occurrences() []*scip.Occurrence {
emit(rel.relations)
}
for _, ref := range s.references {
result = append(result, ref.name.occurrence(scip.SymbolRole_UnspecifiedSymbolRole))
role := scip.SymbolRole_UnspecifiedSymbolRole
if ref.isForwardDef {
role = scip.SymbolRole_ForwardDefinition
}
result = append(result, ref.name.occurrence(role))
}
return result
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/scip/tests/reprolang/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ module.exports = grammar({
field('name', $.identifier),
field('roles', repeat($._definition_relations))
),
reference_statement: $ => seq('reference', field('name', $.identifier)),
reference_statement: $ =>
seq(
'reference',
field('forward_definition', optional('forward_definition')),
field('name', $.identifier)
),
_definition_relations: $ =>
choice(
$.implementation_relation,
Expand Down
16 changes: 16 additions & 0 deletions cmd/scip/tests/reprolang/src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions cmd/scip/tests/reprolang/src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading