Skip to content

Commit

Permalink
reprolang: Add flag to use abspaths in LSIF indexes. (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src authored Sep 23, 2022
1 parent 4526d1f commit b8dda7d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,24 @@ Protobuf output can be inspected using `protoc`:
```
protoc --decode=scip.Index -I /path/to/scip scip.proto < index.scip
```

## Testing and adding new SCIP semantics

It is helpful to use reprolang to check the existing code navigation behavior,
to design new code navigation behavior,
or to investigate the effect of the SCIP to LSIF desugaring.
The LSIF index for reprolang code is much smaller,
which aids debugging.

To do this, add a test file (and implement any new functionality) first.
Then, regenerate the LSIF index with absolute paths.

```bash
go test ./cmd -update-snapshots -debug-snapshot-abspaths
```

The LSIF index can be uploaded to a local Sourcegraph instance using:

```bash
PACKAGE=MY_PACKAGE_NAME SRC_ACCESS_TOKEN=MY_TOKEN SRC_ENDPOINT=https://sourcegraph.test:3443 src code-intel upload -file="cmd/tests/snapshots/output/$PACKAGE/dump.lsif" -root="cmd/tests/snapshots/input/$PACKAGE"
```
11 changes: 10 additions & 1 deletion cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"flag"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -50,6 +51,8 @@ func TestReadmeInSync(t *testing.T) {
}
}

var debugSnapshotAbspaths = flag.Bool("debug-snapshot-abspaths", false, "use absolute paths in snapshot outputs, useful for making uploads to test code navigation")

// TestSCIPSnapshots runs all the snapshot tests.
func TestSCIPSnapshots(t *testing.T) {
cwd, err := os.Getwd()
Expand Down Expand Up @@ -86,7 +89,13 @@ func TestSCIPSnapshots(t *testing.T) {
symbolFormatter.IncludePackageName = func(name string) bool { return name != testName }
snapshots, err := testutil.FormatSnapshots(index, "#", symbolFormatter)
require.Nil(t, err)
index.Metadata.ProjectRoot = "file:/root"
if debugSnapshotAbspaths != nil && *debugSnapshotAbspaths {
inputDirAbsPath, err := filepath.Abs(inputDirectory)
require.Nil(t, err)
index.Metadata.ProjectRoot = inputDirAbsPath
} else {
index.Metadata.ProjectRoot = "file:/root"
}
lsif, err := scip.ConvertSCIPToLSIF(index)
require.Nil(t, err)
var obtained bytes.Buffer
Expand Down

0 comments on commit b8dda7d

Please sign in to comment.