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 4 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
328 changes: 168 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_ForwardDeclaration.Matches(occ) {
role = "forward_declaration"
}
b.WriteString(role)
b.WriteRune(' ')
Expand Down
1,119 changes: 569 additions & 550 deletions bindings/haskell/src/Proto/Scip.hs

Large diffs are not rendered by default.

1,355 changes: 683 additions & 672 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_ForwardDeclaration.Matches(occ) {
return forwardDeclIsDefinitionError{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 forwardDeclIsDefinitionError struct {
symbol string
path string
range_ scip.Range
}

func (e forwardDeclIsDefinitionError) 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
isForwardDecl 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")),
isForwardDecl: child.ChildByFieldName("forward_decl") != 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.isForwardDecl {
role = scip.SymbolRole_ForwardDeclaration
}
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_decl', optional('forward_decl')),
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