Skip to content

Commit 909df93

Browse files
cli: Add MVP implementation for SCIP view command. (#91)
1 parent ccf05f7 commit 909df93

File tree

6 files changed

+74
-3
lines changed

6 files changed

+74
-3
lines changed

Development.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@
3737

3838
## Debugging
3939

40-
Protobuf output can be inspected using `protoc`:
40+
Protobuf output can be inspected using `scip view`:
41+
42+
```
43+
scip print /path/to/index.scip
44+
```
45+
46+
This may be a bit verbose. The default Protobuf output is more compact,
47+
and can be inspected using `protoc`:
4148

4249
```
4350
protoc --decode=scip.Index -I /path/to/scip scip.proto < index.scip

Readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ OPTIONS:
9090
--to value Output path for LSIF index (default: dump.lsif)
9191
```
9292

93+
### `scip print`
94+
95+
```
96+
NAME:
97+
scip print - Print a SCIP index in a human-readable format for debugging
98+
99+
USAGE:
100+
scip print [command options] [arguments...]
101+
102+
DESCRIPTION:
103+
WARNING: The output may change over time.
104+
Do not rely on the output of this command in scripts
105+
106+
OPTIONS:
107+
--help, -h show help (default: false)
108+
```
109+
93110
### `scip snapshot`
94111

95112
```

cmd/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ func commands() []*cli.Command {
1919
convert := convertCommand()
2020
snapshot := snapshotCommand()
2121
stats := statsCommand()
22-
return []*cli.Command{&convert, &snapshot, &stats}
22+
print := printCommand()
23+
return []*cli.Command{&convert, &snapshot, &stats, &print}
2324
}
2425

2526
func scipApp() cli.App {
@@ -54,6 +55,6 @@ func fromFlag(storage *string) *cli.StringFlag {
5455
Name: "from",
5556
Usage: "Path to SCIP index file",
5657
Destination: storage,
57-
Value: "index.scip",
58+
Value: "index.scip",
5859
}
5960
}

cmd/print.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"github.com/k0kubun/pp/v3"
5+
"github.com/urfave/cli/v2"
6+
"math"
7+
8+
"github.com/sourcegraph/sourcegraph/lib/errors"
9+
)
10+
11+
func printCommand() cli.Command {
12+
snapshot := cli.Command{
13+
Name: "print",
14+
Usage: "Print a SCIP index in a human-readable format for debugging",
15+
Description: `WARNING: The output may change over time.
16+
Do not rely on the output of this command in scripts`,
17+
Action: func(c *cli.Context) error {
18+
indexPath := c.Args().Get(0)
19+
if indexPath == "" {
20+
return errors.New("missing argument for path to SCIP index")
21+
}
22+
return printMain(indexPath)
23+
},
24+
}
25+
return snapshot
26+
}
27+
28+
func printMain(indexPath string) error {
29+
index, err := readFromOption(indexPath)
30+
if err != nil {
31+
return err
32+
}
33+
pp.BufferFoldThreshold = math.MaxInt
34+
prettyPrinter := pp.New()
35+
prettyPrinter.SetExportedOnly(true)
36+
_, err = prettyPrinter.Print(index)
37+
return err
38+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/google/go-cmp v0.5.7
88
github.com/hexops/gotextdiff v1.0.3
99
github.com/hhatto/gocloc v0.4.2
10+
github.com/k0kubun/pp/v3 v3.1.0
1011
github.com/pseudomuto/protoc-gen-doc v1.5.1
1112
github.com/smacker/go-tree-sitter v0.0.0-20220209044044-0d3022e933c3
1213
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220511160847-5a43d3ea24eb
@@ -46,6 +47,8 @@ require (
4647
github.com/klauspost/pgzip v1.2.5 // indirect
4748
github.com/kr/pretty v0.3.0 // indirect
4849
github.com/kr/text v0.2.0 // indirect
50+
github.com/mattn/go-colorable v0.1.12 // indirect
51+
github.com/mattn/go-isatty v0.0.14 // indirect
4952
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5053
github.com/modern-go/reflect2 v1.0.2 // indirect
5154
github.com/mwitkow/go-proto-validators v0.0.0-20180403085117-0950a7990007 // indirect

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0b
185185
github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
186186
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
187187
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
188+
github.com/k0kubun/pp/v3 v3.1.0 h1:ifxtqJkRZhw3h554/z/8zm6AAbyO4LLKDlA5eV+9O8Q=
189+
github.com/k0kubun/pp/v3 v3.1.0/go.mod h1:vIrP5CF0n78pKHm2Ku6GVerpZBJvscg48WepUYEk2gw=
188190
github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4CqbAk=
189191
github.com/kataras/golog v0.0.10/go.mod h1:yJ8YKCmyL+nWjERB90Qwn+bdyBZsaQwU3bTVFgkFIp8=
190192
github.com/kataras/iris/v12 v12.0.1/go.mod h1:udK4vLQKkdDqMGJJVd/msuMtN6hpYJhg/lSzuxjhO+U=
@@ -219,10 +221,13 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
219221
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
220222
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
221223
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
224+
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
225+
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
222226
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
223227
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
224228
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
225229
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
230+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
226231
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
227232
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
228233
github.com/mediocregopher/mediocre-go-lib v0.0.0-20181029021733-cb65787f37ed/go.mod h1:dSsfyI2zABAdhcbvkXqgxOxrCsbYeHCPgrZkku60dSg=

0 commit comments

Comments
 (0)