Skip to content

Commit b8dda7d

Browse files
reprolang: Add flag to use abspaths in LSIF indexes. (#89)
1 parent 4526d1f commit b8dda7d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Development.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,24 @@ Protobuf output can be inspected using `protoc`:
4242
```
4343
protoc --decode=scip.Index -I /path/to/scip scip.proto < index.scip
4444
```
45+
46+
## Testing and adding new SCIP semantics
47+
48+
It is helpful to use reprolang to check the existing code navigation behavior,
49+
to design new code navigation behavior,
50+
or to investigate the effect of the SCIP to LSIF desugaring.
51+
The LSIF index for reprolang code is much smaller,
52+
which aids debugging.
53+
54+
To do this, add a test file (and implement any new functionality) first.
55+
Then, regenerate the LSIF index with absolute paths.
56+
57+
```bash
58+
go test ./cmd -update-snapshots -debug-snapshot-abspaths
59+
```
60+
61+
The LSIF index can be uploaded to a local Sourcegraph instance using:
62+
63+
```bash
64+
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"
65+
```

cmd/main_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bytes"
5+
"flag"
56
"fmt"
67
"os"
78
"path/filepath"
@@ -50,6 +51,8 @@ func TestReadmeInSync(t *testing.T) {
5051
}
5152
}
5253

54+
var debugSnapshotAbspaths = flag.Bool("debug-snapshot-abspaths", false, "use absolute paths in snapshot outputs, useful for making uploads to test code navigation")
55+
5356
// TestSCIPSnapshots runs all the snapshot tests.
5457
func TestSCIPSnapshots(t *testing.T) {
5558
cwd, err := os.Getwd()
@@ -86,7 +89,13 @@ func TestSCIPSnapshots(t *testing.T) {
8689
symbolFormatter.IncludePackageName = func(name string) bool { return name != testName }
8790
snapshots, err := testutil.FormatSnapshots(index, "#", symbolFormatter)
8891
require.Nil(t, err)
89-
index.Metadata.ProjectRoot = "file:/root"
92+
if debugSnapshotAbspaths != nil && *debugSnapshotAbspaths {
93+
inputDirAbsPath, err := filepath.Abs(inputDirectory)
94+
require.Nil(t, err)
95+
index.Metadata.ProjectRoot = inputDirAbsPath
96+
} else {
97+
index.Metadata.ProjectRoot = "file:/root"
98+
}
9099
lsif, err := scip.ConvertSCIPToLSIF(index)
91100
require.Nil(t, err)
92101
var obtained bytes.Buffer

0 commit comments

Comments
 (0)