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

Included diagnostics in scip snapshot output #220

Closed
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
12 changes: 11 additions & 1 deletion bindings/go/scip/testutil/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// that is suitable for snapshot testing.
func FormatSnapshots(
index *scip.Index,
includeDiagnostics bool,
commentSyntax string,
symbolFormatter scip.SymbolFormatter,
customProjectRoot string,
Expand All @@ -40,7 +41,7 @@ func FormatSnapshots(
var documentErrors error
for _, document := range index.Documents {
sourceFilePath := filepath.Join(localSourcesRoot, document.RelativePath)
snapshot, err := FormatSnapshot(document, index, commentSyntax, symbolFormatter, sourceFilePath)
snapshot, err := FormatSnapshot(document, index, includeDiagnostics, commentSyntax, symbolFormatter, sourceFilePath)
err = symbolFormatter.OnError(err)
if err != nil {
documentErrors = errors.CombineErrors(
Expand All @@ -65,6 +66,7 @@ func FormatSnapshots(
func FormatSnapshot(
document *scip.Document,
index *scip.Index,
includeDiagnostics bool,
commentSyntax string,
formatter scip.SymbolFormatter,
sourceFilePath string,
Expand Down Expand Up @@ -152,6 +154,14 @@ func FormatSnapshot(
}
}

if includeDiagnostics {
for _, diagnostic := range occ.Diagnostics {
b.WriteString(prefix)
b.WriteString("diagnostic ")
b.WriteString(diagnostic.Code)
}
}

b.WriteString("\n")
i++
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/scip/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestSCIPSnapshots(t *testing.T) {
require.Nil(t, err)
symbolFormatter := scip.DescriptorOnlyFormatter
symbolFormatter.IncludePackageName = func(name string) bool { return name != testName }
snapshots, err := testutil.FormatSnapshots(index, "#", symbolFormatter, inputDirectory)
snapshots, err := testutil.FormatSnapshots(index, false, "#", symbolFormatter, inputDirectory)
require.Nil(t, err)
if debugSnapshotAbspaths != nil && *debugSnapshotAbspaths {
inputDirAbsPath, err := filepath.Abs(inputDirectory)
Expand Down
19 changes: 13 additions & 6 deletions cmd/scip/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (
)

type snapshotFlags struct {
from string
output string
customProjectRoot string
strict bool
commentSyntax string
from string
output string
includeDiagnostics bool
customProjectRoot string
strict bool
commentSyntax string
}

func snapshotCommand() cli.Command {
Expand All @@ -44,6 +45,12 @@ and symbol information.`,
Destination: &snapshotFlags.strict,
Value: true,
},
&cli.BoolFlag{
Name: "include-diagnostics",
Usage: "Whether or not to include scip diagnostics in snapshot files",
Destination: &snapshotFlags.includeDiagnostics,
Value: false,
},
&cli.StringFlag{
Name: "comment-syntax",
Usage: "Comment syntax to use for snapshot files",
Expand Down Expand Up @@ -76,7 +83,7 @@ func snapshotMain(flags snapshotFlags) error {
return errors.Wrap(err, "use --strict=false to ignore this error")
}
}
snapshots, err := testutil.FormatSnapshots(index, flags.commentSyntax, symbolFormatter, flags.customProjectRoot)
snapshots, err := testutil.FormatSnapshots(index, flags.includeDiagnostics, flags.commentSyntax, symbolFormatter, flags.customProjectRoot)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ OPTIONS:
--to value Path to output directory for snapshot files (default: "scip-snapshot")
--project-root value Override project root in the SCIP file. For example, this can be helpful when the SCIP index was created inside a Docker image or created on another computer
--strict If true, fail fast on errors (default: true)
--include-diagnostics Whether or not to include scip diagnostics in snapshot files (default: false)
--comment-syntax value Comment syntax to use for snapshot files (default: "//")
```

Expand Down