Skip to content

Commit

Permalink
fix: Propagate errors when creating repro SCIP index
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src committed Dec 13, 2024
1 parent d1f063d commit 476eae6
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 15 deletions.
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

0 comments on commit 476eae6

Please sign in to comment.