Skip to content

Commit 7ff845e

Browse files
authored
rust: add symbol support and move generated code (#44)
* add symbol support and move generated code for rust * proto: add Macro * optional: always get some documentation to add * fix: handle namespace
1 parent e3ff8a9 commit 7ff845e

File tree

15 files changed

+1608
-1061
lines changed

15 files changed

+1608
-1061
lines changed

bindings/go/scip/scip.pb.go

Lines changed: 206 additions & 202 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ func (s *symbolParser) parseDescriptor() (*Descriptor, error) {
160160
return &Descriptor{Name: name, Suffix: Descriptor_Type}, nil
161161
case ':':
162162
return &Descriptor{Name: name, Suffix: Descriptor_Meta}, nil
163+
case '!':
164+
return &Descriptor{Name: name, Suffix: Descriptor_Macro}, nil
163165
default:
164166
}
165167
}

bindings/go/scip/symbol_formatter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package scip
22

3-
import "strings"
3+
import (
4+
"strings"
5+
)
46

57
// SymbolFormatter configures how to format an SCIP symbol.
68
// Excluding parts of the symbol can be helpful for testing purposes. For example, snapshot tests may hardcode
@@ -81,6 +83,9 @@ func (f *SymbolFormatter) FormatSymbol(symbol *Symbol) string {
8183
case Descriptor_Meta:
8284
descriptor.WriteString(desc.Name)
8385
descriptor.WriteRune(':')
86+
case Descriptor_Macro:
87+
descriptor.WriteString(desc.Name)
88+
descriptor.WriteRune('!')
8489
case Descriptor_Local:
8590
descriptor.WriteString(desc.Name)
8691
}

bindings/go/scip/symbol_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ func TestParseSymbol(t *testing.T) {
5959
},
6060
},
6161
},
62+
{
63+
Symbol: "rust-analyzer cargo std 1.0.0 macros/println!",
64+
Expected: &Symbol{
65+
Scheme: "rust-analyzer",
66+
Package: &Package{Manager: "cargo", Name: "std", Version: "1.0.0"},
67+
Descriptors: []*Descriptor{
68+
{Name: "macros", Suffix: Descriptor_Package},
69+
{Name: "println", Suffix: Descriptor_Macro},
70+
},
71+
},
72+
},
6273
}
6374
for _, test := range tests {
6475
t.Run(test.Symbol, func(t *testing.T) {

bindings/go/scip/testutil/format.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ func FormatSnapshot(
106106
if info, ok := symtab[occ.Symbol]; ok && isDefinition {
107107
prefix := "\n" + commentSyntax + strings.Repeat(" ", int(pos.Start.Character))
108108
for _, documentation := range info.Documentation {
109+
// At least get the first line of documentation if there is leading whitespace
110+
documentation = strings.TrimSpace(documentation)
111+
109112
b.WriteString(prefix)
110113
b.WriteString("documentation ")
111114
truncatedDocumentation := documentation

bindings/rust/Cargo.lock

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

bindings/rust/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ rust-version = "1.60.0"
1313
# Keep in sync with dev/proto-generate.sh
1414
protobuf = "=3.1.0"
1515

16+
[dev-dependencies]
17+
pretty_assertions = "1.2.1"
18+
1619
[lib]
17-
name = "rust"
18-
path = "src/scip.rs"
20+
name = "scip"
21+
path = "src/mod.rs"

bindings/rust/src/generated/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @generated
2+
3+
pub mod scip;

0 commit comments

Comments
 (0)