Skip to content

Commit 2260bb1

Browse files
docs: Document local-id syntax (#206)
1 parent e02b917 commit 2260bb1

File tree

9 files changed

+1650
-1554
lines changed

9 files changed

+1650
-1554
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: ./.github/actions/asdf
1717
with:
1818
rust: true
19-
- run: cargo check
19+
- run: cargo test
2020
working-directory: bindings/rust
2121
- run: cargo check
2222
working-directory: cmd/scip/tests/reprolang

bindings/go/scip/scip.pb.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/go/scip/symbol.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,42 @@ import (
88
"github.com/sourcegraph/sourcegraph/lib/errors"
99
)
1010

11+
// IsGlobalSymbol returns true if the symbol is obviously not a local symbol.
12+
//
13+
// CAUTION: Does not perform full validation of the symbol string's contents.
1114
func IsGlobalSymbol(symbol string) bool {
1215
return !IsLocalSymbol(symbol)
1316
}
1417

18+
// IsLocalSymbol returns true if the symbol is obviously not a global symbol.
19+
//
20+
// CAUTION: Does not perform full validation of the symbol string's contents.
1521
func IsLocalSymbol(symbol string) bool {
1622
return strings.HasPrefix(symbol, "local ")
1723
}
1824

25+
func isSimpleIdentifier(s string) bool {
26+
for _, c := range s {
27+
if ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') ||
28+
c == '$' || c == '+' || c == '-' || c == '_' {
29+
continue
30+
}
31+
return false
32+
}
33+
return true
34+
}
35+
36+
func tryParseLocalSymbol(symbol string) (string, error) {
37+
if !strings.HasPrefix(symbol, "local ") {
38+
return "", nil
39+
}
40+
suffix := symbol[6:]
41+
if len(suffix) > 0 && isSimpleIdentifier(suffix) {
42+
return suffix, nil
43+
}
44+
return "", errors.Newf("expected format 'local <simple-identifier>' but got: %v", symbol)
45+
}
46+
1947
// ParseSymbol parses an SCIP string into the Symbol message.
2048
func ParseSymbol(symbol string) (*Symbol, error) {
2149
return ParsePartialSymbol(symbol, true)
@@ -24,14 +52,18 @@ func ParseSymbol(symbol string) (*Symbol, error) {
2452
// ParsePartialSymbol parses an SCIP string into the Symbol message
2553
// with the option to exclude the `.Descriptor` field.
2654
func ParsePartialSymbol(symbol string, includeDescriptors bool) (*Symbol, error) {
55+
local, err := tryParseLocalSymbol(symbol)
56+
if err != nil {
57+
return nil, err
58+
}
59+
if local != "" {
60+
return newLocalSymbol(local), nil
61+
}
2762
s := newSymbolParser(symbol)
2863
scheme, err := s.acceptSpaceEscapedIdentifier("scheme")
2964
if err != nil {
3065
return nil, err
3166
}
32-
if scheme == "local" {
33-
return newLocalSymbol(string(s.Symbol[s.index:])), nil
34-
}
3567
manager, err := s.acceptSpaceEscapedIdentifier("package manager")
3668
if err != nil {
3769
return nil, err

bindings/go/scip/symbol_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ func TestParseSymbol(t *testing.T) {
8282
}
8383
}
8484

85-
func TestParseSymbolNoCrash(t *testing.T) {
85+
func TestParseSymbolError(t *testing.T) {
8686
for _, symbolName := range []string{
87+
"",
8788
"lsif-java maven package 1.0.0",
8889
"lsif-java maven package 1.0.0 java/io/File#Entry.trailingstring",
8990
"lsif-java maven package 1.0.0 java/io/File#Entry.unrecognizedSuffix@",
91+
"local 🧠",
92+
"local ",
93+
"local &&&",
9094
} {
9195

9296
if _, err := ParseSymbol(symbolName); err == nil {

0 commit comments

Comments
 (0)