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: Propagate errors when creating repro SCIP index #296

Merged
merged 1 commit into from
Dec 13, 2024
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
6 changes: 3 additions & 3 deletions cmd/scip/lint.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"errors"
stderrors "errors"
"fmt"
"sort"
"strings"
Expand All @@ -21,7 +21,7 @@ func lintCommand() cli.Command {
Action: func(c *cli.Context) error {
indexPath := c.Args().Get(0)
if indexPath == "" {
return errors.New("missing argument for path to SCIP index")
return stderrors.New("missing argument for path to SCIP index")
}
return lintMain(indexPath)
},
Expand All @@ -34,7 +34,7 @@ func lintMain(indexPath string) error {
if err != nil {
return err
}
return errors.Join(lintMainPure(scipIndex).data...)
return stderrors.Join(lintMainPure(scipIndex).data...)
}

func lintMainPure(scipIndex *scip.Index) errorSet {
Expand Down
6 changes: 4 additions & 2 deletions cmd/scip/tests/reprolang/bindings/go/repro/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/cockroachdb/errors"
sitter "github.com/smacker/go-tree-sitter"

"github.com/sourcegraph/scip/bindings/go/scip"
Expand Down Expand Up @@ -77,16 +78,17 @@ func NewRangePositionFromNode(node *sitter.Node) *scip.Range {
}
}

func (i *identifier) resolveSymbol(localScope *reproScope, context *reproContext) {
func (i *identifier) resolveSymbol(localScope *reproScope, context *reproContext) error {
scope := context.globalScope
if i.isLocalSymbol() {
scope = localScope
}
symbol, ok := scope.names[i.value]
if !ok {
symbol = "local ERROR_UNRESOLVED_SYMBOL"
return errors.Newf("could not resolve local symbol %q", i.value)
}
i.symbol = symbol
return nil
}

func (i *identifier) isLocalSymbol() bool {
Expand Down
9 changes: 8 additions & 1 deletion cmd/scip/tests/reprolang/bindings/go/repro/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package repro
import (
"context"

"github.com/cockroachdb/errors"
"github.com/sourcegraph/scip/bindings/go/scip"
)

Expand Down Expand Up @@ -69,8 +70,14 @@ func Index(
}

// Phase 3: resolve names for references
var allErrs error
for _, file := range reproSources {
file.resolveReferences(ctx)
if err := file.resolveReferences(ctx); err != nil {
allErrs = errors.CombineErrors(allErrs, errors.Wrapf(err, "file %q", file.Source.AbsolutePath))
}
}
if allErrs != nil {
return nil, allErrs
}

// Phase 4: emit SCIP
Expand Down
9 changes: 6 additions & 3 deletions cmd/scip/tests/reprolang/bindings/go/repro/namer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package repro
import (
"fmt"

"github.com/cockroachdb/errors"
"github.com/sourcegraph/scip/bindings/go/scip"
)

Expand Down Expand Up @@ -58,13 +59,14 @@ func (s *reproSourceFile) enterDefinitions(context *reproContext) {
}

// resolveReferences updates the .symbol field for all names of reference identifiers.
func (s *reproSourceFile) resolveReferences(context *reproContext) {
func (s *reproSourceFile) resolveReferences(context *reproContext) error {
var err error
resolveIdents := func(rel relationships) {
for _, ident := range rel.identifiers() {
if ident == nil {
continue
}
ident.resolveSymbol(s.localScope, context)
err = errors.CombineErrors(err, ident.resolveSymbol(s.localScope, context))
}
}
for _, def := range s.definitions {
Expand All @@ -74,8 +76,9 @@ func (s *reproSourceFile) resolveReferences(context *reproContext) {
resolveIdents(rel.relations)
}
for _, ref := range s.references {
ref.name.resolveSymbol(s.localScope, context)
err = errors.CombineErrors(err, ref.name.resolveSymbol(s.localScope, context))
}
return err
}

// newGlobalSymbol returns an SCIP symbol for the given definition.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
definition hello().
4 changes: 2 additions & 2 deletions cmd/scip/tests/snapshots/input/local-document/local2.repro
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
reference localExample

definition localExample
reference localExample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reference a global symbol from another workspace.
reference global global-workspace hello.repro/hello().
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference local ERROR_UNRESOLVED_SYMBOL
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference global-workspace hello.repro/hello().
reference global duplicates duplicate.repro/readFileSync.
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference duplicates duplicate.repro/readFileSync.

4 changes: 4 additions & 0 deletions cmd/scip/tests/snapshots/output/global-workspace/hello.repro
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
definition hello().
# ^^^^^^^^ definition hello.repro/hello().
# documentation
# > signature of hello().
8 changes: 5 additions & 3 deletions cmd/scip/tests/snapshots/output/local-document/local2.repro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
definition localExample
# ^^^^^^^^^^^^ definition local Example
# documentation
# > signature of localExample
reference localExample
# ^^^^^^^^^^^^ reference local ERROR_UNRESOLVED_SYMBOL


# ^^^^^^^^^^^^ reference local Example
Loading