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 49f9c4b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 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
10 changes: 9 additions & 1 deletion cmd/scip/tests/reprolang/bindings/go/repro/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package repro

import (
"context"
stderrors "errors"

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

Expand Down Expand Up @@ -69,8 +71,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 = stderrors.Join(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
@@ -1,6 +1,7 @@
package repro

import (
stderrors "errors"
"fmt"

"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 = stderrors.Join(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 = stderrors.Join(err, ref.name.resolveSymbol(s.localScope, context))
}
return err
}

// newGlobalSymbol returns an SCIP symbol for the given definition.
Expand Down

0 comments on commit 49f9c4b

Please sign in to comment.