Skip to content

Commit 3935113

Browse files
feat: Add SymbolRole for representing forward declarations (#217)
* feat: Add ForwardDeclaration SymbolRole * fix: Format forward_declaration separately in snapshot logic * test: Add forward decls to repro grammar + test case * feat: Add lint rule for bad forward decls * Rename forward declaration role -> forward definition
1 parent 4e535ae commit 3935113

File tree

19 files changed

+1802
-1563
lines changed

19 files changed

+1802
-1563
lines changed

bindings/go/scip/convert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (g *graph) emitDocument(index *Index, doc *Document) {
230230
rangeIDs = append(rangeIDs, rangeID)
231231
resultIDs := g.getOrInsertSymbolInformationIDs(occ.Symbol, localSymbolInformationTable)
232232
g.emitEdge("next", reader.Edge{OutV: rangeID, InV: resultIDs.ResultSet})
233-
isDefinition := occ.SymbolRoles&int32(SymbolRole_Definition) != 0
233+
isDefinition := SymbolRole_Definition.Matches(occ)
234234
if isDefinition && resultIDs.DefinitionResult > 0 {
235235
g.emitEdge("item", reader.Edge{OutV: resultIDs.DefinitionResult, InVs: []int{rangeID}, Document: documentID})
236236
symbolInfo, ok := documentSymbolTable[occ.Symbol]

bindings/go/scip/scip.pb.go

+169-160
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/go/scip/testutil/format.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ func FormatSnapshot(
110110
}
111111
b.WriteRune(' ')
112112
role := "reference"
113-
isDefinition := occ.SymbolRoles&int32(scip.SymbolRole_Definition) > 0
113+
isDefinition := scip.SymbolRole_Definition.Matches(occ)
114114
if isDefinition {
115115
role = "definition"
116+
} else if scip.SymbolRole_ForwardDefinition.Matches(occ) {
117+
role = "forward_definition"
116118
}
117119
b.WriteString(role)
118120
b.WriteRune(' ')

bindings/haskell/src/Proto/Scip.hs

+570-550
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/rust/src/generated/scip.rs

+556-543
Large diffs are not rendered by default.

bindings/typescript/scip.ts

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/scip/lint.go

+14
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ func (st *symbolTable) addOccurrence(path string, occ *scip.Occurrence) error {
204204
if occ.Symbol == "" {
205205
return emptyStringError{what: "symbol", context: fmt.Sprintf("occurrence at %s @ %s", path, scipRangeToString(*scip.NewRange(occ.Range)))}
206206
}
207+
if scip.SymbolRole_Definition.Matches(occ) && scip.SymbolRole_ForwardDefinition.Matches(occ) {
208+
return forwardDefIsDefinitionError{occ.Symbol, path, *scip.NewRange(occ.Range)}
209+
}
207210
tryInsertOccurrence := func(occMap fileOccurrenceMap) error {
208211
occKey := scipOccurrenceKey(occ)
209212
if fileOccs, ok := occMap[path]; ok {
@@ -327,6 +330,17 @@ func (e missingSymbolForOccurrenceError) Error() string {
327330
" in external symbols or any document", e.path, scipRangeToString(e.occ), e.symbol)
328331
}
329332

333+
type forwardDefIsDefinitionError struct {
334+
symbol string
335+
path string
336+
range_ scip.Range
337+
}
338+
339+
func (e forwardDefIsDefinitionError) Error() string {
340+
return fmt.Sprintf("error: forward declaration for %v at %v @ %v was marked as definition",
341+
e.symbol, e.path, scipRangeToString(e.range_))
342+
}
343+
330344
type duplicateOccurrenceWarning struct {
331345
symbol string
332346
path string

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ func (r *relationships) identifiers() []*identifier {
2727
}
2828

2929
type referenceStatement struct {
30-
name *identifier
30+
name *identifier
31+
isForwardDef bool
3132
}
3233

3334
type identifier struct {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ func (s *reproSourceFile) loadStatements() {
6262
}
6363
case "reference_statement":
6464
s.references = append(s.references, &referenceStatement{
65-
name: newIdentifier(s, child.ChildByFieldName("name")),
65+
name: newIdentifier(s, child.ChildByFieldName("name")),
66+
isForwardDef: child.ChildByFieldName("forward_definition") != nil,
6667
})
6768
}
6869
}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ func (s *reproSourceFile) occurrences() []*scip.Occurrence {
6363
emit(rel.relations)
6464
}
6565
for _, ref := range s.references {
66-
result = append(result, ref.name.occurrence(scip.SymbolRole_UnspecifiedSymbolRole))
66+
role := scip.SymbolRole_UnspecifiedSymbolRole
67+
if ref.isForwardDef {
68+
role = scip.SymbolRole_ForwardDefinition
69+
}
70+
result = append(result, ref.name.occurrence(role))
6771
}
6872
return result
6973
}

cmd/scip/tests/reprolang/grammar.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ module.exports = grammar({
2222
field('name', $.identifier),
2323
field('roles', repeat($._definition_relations))
2424
),
25-
reference_statement: $ => seq('reference', field('name', $.identifier)),
25+
reference_statement: $ =>
26+
seq(
27+
'reference',
28+
field('forward_definition', optional('forward_definition')),
29+
field('name', $.identifier)
30+
),
2631
_definition_relations: $ =>
2732
choice(
2833
$.implementation_relation,

cmd/scip/tests/reprolang/src/grammar.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/scip/tests/reprolang/src/node-types.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)