Skip to content

Commit d839e44

Browse files
authored
feat(codeintel): Add scip-ctags support for Magik (sourcegraph#63504)
Add symbol browsing support for the Magik language
1 parent a8ffb7a commit d839e44

8 files changed

Lines changed: 258 additions & 17 deletions

File tree

.github/workflows/scip-typescript.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v3
15-
- uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # SECURITY: pin third-party action hashes
15+
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # SECURITY: pin third-party action hashes
1616
id: pnpm-install
1717
with:
1818
version: 8.9.2
@@ -39,7 +39,7 @@ jobs:
3939
run: |
4040
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src
4141
chmod +x /usr/local/bin/src
42-
42+
4343
- name: Upload SCIP to Cloud
4444
run: src code-intel upload -github-token='${{ secrets.GITHUB_TOKEN }}' -no-progress
4545
env:
@@ -51,7 +51,7 @@ jobs:
5151
env:
5252
SRC_ENDPOINT: https://sourcegraph.sourcegraph.com/
5353
SRC_ACCESS_TOKEN: ${{ secrets.SRC_ACCESS_TOKEN_S2 }}
54-
54+
5555
- name: Upload SCIP to Demo
5656
run: src code-intel upload -github-token='${{ secrets.GITHUB_TOKEN }}' -no-progress || true
5757
env:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(source_file
2+
(package (identifier) @descriptor.namespace @kind.package)
3+
) @scope
4+
5+
; This matches global top-level assignments
6+
(fragment "_global" "_constant" (identifier) @kind.constant @descriptor.term)
7+
(fragment "_global" "_constant"? @cons
8+
(identifier) @kind.variable @descriptor.term
9+
(#not-eq? @cons "_constant"))
10+
11+
(invoke
12+
receiver: (variable) @name
13+
(symbol) @descriptor.type @kind.class
14+
(#any-of? @name "def_slotted_exemplar" "def_mixin")
15+
(#transform! ":(.*)" "$1"))
16+
17+
(method
18+
exemplarname: (_) @descriptor.type
19+
name: (_) @descriptor.method @kind.method)
20+
21+
[
22+
(procedure)
23+
(block)
24+
(iterator)
25+
(while)
26+
(try)
27+
(loop)
28+
(if)
29+
] @local

docker-images/syntax-highlighter/crates/syntax-analysis/src/languages.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,33 +208,35 @@ mod tags {
208208
}
209209

210210
create_tags_configuration!(c, ParserId::C, "c");
211-
create_tags_configuration!(javascript, ParserId::Javascript, "javascript");
212-
create_tags_configuration!(kotlin, ParserId::Kotlin, "kotlin");
213-
create_tags_configuration!(ruby, ParserId::Ruby, "ruby");
214-
create_tags_configuration!(python, ParserId::Python, "python");
215211
create_tags_configuration!(cpp, ParserId::Cpp, "cpp");
216-
create_tags_configuration!(typescript, ParserId::Typescript, "typescript");
217-
create_tags_configuration!(scala, ParserId::Scala, "scala");
218212
create_tags_configuration!(c_sharp, ParserId::C_Sharp, "c_sharp");
213+
create_tags_configuration!(go, ParserId::Go, "go");
219214
create_tags_configuration!(java, ParserId::Java, "java");
215+
create_tags_configuration!(javascript, ParserId::Javascript, "javascript");
216+
create_tags_configuration!(kotlin, ParserId::Kotlin, "kotlin");
217+
create_tags_configuration!(magik, ParserId::Magik, "magik");
218+
create_tags_configuration!(python, ParserId::Python, "python");
219+
create_tags_configuration!(ruby, ParserId::Ruby, "ruby");
220220
create_tags_configuration!(rust, ParserId::Rust, "rust");
221-
create_tags_configuration!(go, ParserId::Go, "go");
221+
create_tags_configuration!(scala, ParserId::Scala, "scala");
222+
create_tags_configuration!(typescript, ParserId::Typescript, "typescript");
222223
create_tags_configuration!(zig, ParserId::Zig, "zig");
223224

224225
pub fn get_tag_configuration(parser: ParserId) -> Option<&'static TagConfiguration> {
225226
match parser {
226227
ParserId::C => Some(c()),
227-
ParserId::Javascript => Some(javascript()),
228-
ParserId::Kotlin => Some(kotlin()),
229-
ParserId::Ruby => Some(ruby()),
230-
ParserId::Python => Some(python()),
231228
ParserId::Cpp => Some(cpp()),
232-
ParserId::Typescript => Some(typescript()),
233-
ParserId::Scala => Some(scala()),
234229
ParserId::C_Sharp => Some(c_sharp()),
230+
ParserId::Go => Some(go()),
235231
ParserId::Java => Some(java()),
232+
ParserId::Javascript => Some(javascript()),
233+
ParserId::Kotlin => Some(kotlin()),
234+
ParserId::Magik => Some(magik()),
235+
ParserId::Python => Some(python()),
236+
ParserId::Ruby => Some(ruby()),
236237
ParserId::Rust => Some(rust()),
237-
ParserId::Go => Some(go()),
238+
ParserId::Scala => Some(scala()),
239+
ParserId::Typescript => Some(typescript()),
238240
ParserId::Zig => Some(zig()),
239241
_ => None,
240242
}

docker-images/syntax-highlighter/crates/syntax-analysis/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,6 @@ mod test {
125125

126126
// Test that errors are returned in expected format
127127
generate_tags_and_snapshot!(Tags, test_tags_perl_example, "example.pl");
128+
129+
generate_tags_and_snapshot!(All, test_tags_magik, test_scip_magik, "globals.magik");
128130
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
source: crates/syntax-analysis/src/lib.rs
3+
expression: dumped
4+
---
5+
6+
_package pp
7+
// ^^ definition(Package) scip-ctags pp/
8+
9+
_global top_level_global << 1
10+
// ^^^^^^^^^^^^^^^^ definition(Variable) scip-ctags pp/top_level_global.
11+
_global _constant top_level_constant << 1
12+
// ^^^^^^^^^^^^^^^^^^ definition(Constant) scip-ctags pp/top_level_constant.
13+
14+
# Examplar Objects
15+
def_slotted_exemplar(
16+
:line_parser,
17+
// ^^^^^^^^^^^^ definition(Class) scip-ctags pp/line_parser#
18+
{
19+
{:settings, _unset},
20+
{:alias, _unset, :writable, :public}
21+
}
22+
)
23+
$
24+
25+
_method line_parser.new()
26+
// ^^^ definition(Method) scip-ctags pp/line_parser#new().
27+
_return _clone.init()
28+
_endmethod
29+
$
30+
31+
_method line_parser.init()
32+
// ^^^^ definition(Method) scip-ctags pp/line_parser#init().
33+
_global g_yes
34+
g_yes << "yes!"
35+
.settings << property_list.new()
36+
.alias << g_yes
37+
38+
_while i <= 100
39+
_loop
40+
i +<< 1
41+
_endloop
42+
43+
_for a _over _self.elements()
44+
_loop
45+
_if a.even? _is _true
46+
_then
47+
g_yes << 1
48+
_endif
49+
_endloop
50+
51+
_try _with cond
52+
a << 1
53+
_when error
54+
a << 2
55+
_endtry
56+
57+
58+
_return _self
59+
_endmethod
60+
$
61+
62+
_private _method line_parser.debug(line, props)
63+
// ^^^^^ definition(Method) scip-ctags pp/line_parser#debug().
64+
_local new_line << line
65+
_block
66+
(key, value) << (_scatter new_line.split_by(%=, _false))
67+
props[key.lowercase] << value
68+
_endblock
69+
_return props
70+
_endmethod
71+
72+
$
73+
74+
# Validate a method added to an examplar not defined in this file
75+
_method other_object.some_method()
76+
// ^^^^^^^^^^^ definition(Method) scip-ctags pp/other_object#some_method().
77+
_return 4
78+
_endmethod
79+
80+
$
81+
# Mixins
82+
def_mixin(:my_mixin)
83+
// ^^^^^^^^^ definition(Class) scip-ctags pp/my_mixin#
84+
$
85+
my_mixin.add_child(line_parser)
86+
$
87+
88+
_abstract _method my_mixin.some_thing
89+
// ^^^^^^^^^^ definition(Method) scip-ctags pp/my_mixin#some_thing().
90+
_endmethod
91+
92+
93+
_block
94+
_local some_local << 1
95+
_constant some_local_constant << 1
96+
_global some_global1, some_global2
97+
some_global1 << 1
98+
bruh = 10
99+
100+
some_proc << _proc (arg1)
101+
arg1.action()
102+
_endproc
103+
_endblock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: crates/syntax-analysis/src/lib.rs
3+
expression: "String::from_utf8_lossy(&output)"
4+
---
5+
{"_type":"tag","name":"pp","path":"globals.magik","language":"magik","line":2,"kind":"package","scope":null}
6+
{"_type":"tag","name":"some_thing","path":"globals.magik","language":"magik","line":75,"kind":"method","scope":"pp.my_mixin"}
7+
{"_type":"tag","name":"my_mixin","path":"globals.magik","language":"magik","line":70,"kind":"class","scope":"pp"}
8+
{"_type":"tag","name":"some_method","path":"globals.magik","language":"magik","line":64,"kind":"method","scope":"pp.other_object"}
9+
{"_type":"tag","name":"debug","path":"globals.magik","language":"magik","line":52,"kind":"method","scope":"pp.line_parser"}
10+
{"_type":"tag","name":"init","path":"globals.magik","language":"magik","line":22,"kind":"method","scope":"pp.line_parser"}
11+
{"_type":"tag","name":"new","path":"globals.magik","language":"magik","line":17,"kind":"method","scope":"pp.line_parser"}
12+
{"_type":"tag","name":"line_parser","path":"globals.magik","language":"magik","line":9,"kind":"class","scope":"pp"}
13+
{"_type":"tag","name":"top_level_constant","path":"globals.magik","language":"magik","line":5,"kind":"constant","scope":"pp"}
14+
{"_type":"tag","name":"top_level_global","path":"globals.magik","language":"magik","line":4,"kind":"variable","scope":"pp"}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
_package pp
3+
4+
_global top_level_global << 1
5+
_global _constant top_level_constant << 1
6+
7+
# Examplar Objects
8+
def_slotted_exemplar(
9+
:line_parser,
10+
{
11+
{:settings, _unset},
12+
{:alias, _unset, :writable, :public}
13+
}
14+
)
15+
$
16+
17+
_method line_parser.new()
18+
_return _clone.init()
19+
_endmethod
20+
$
21+
22+
_method line_parser.init()
23+
_global g_yes
24+
g_yes << "yes!"
25+
.settings << property_list.new()
26+
.alias << g_yes
27+
28+
_while i <= 100
29+
_loop
30+
i +<< 1
31+
_endloop
32+
33+
_for a _over _self.elements()
34+
_loop
35+
_if a.even? _is _true
36+
_then
37+
g_yes << 1
38+
_endif
39+
_endloop
40+
41+
_try _with cond
42+
a << 1
43+
_when error
44+
a << 2
45+
_endtry
46+
47+
48+
_return _self
49+
_endmethod
50+
$
51+
52+
_private _method line_parser.debug(line, props)
53+
_local new_line << line
54+
_block
55+
(key, value) << (_scatter new_line.split_by(%=, _false))
56+
props[key.lowercase] << value
57+
_endblock
58+
_return props
59+
_endmethod
60+
61+
$
62+
63+
# Validate a method added to an examplar not defined in this file
64+
_method other_object.some_method()
65+
_return 4
66+
_endmethod
67+
68+
$
69+
# Mixins
70+
def_mixin(:my_mixin)
71+
$
72+
my_mixin.add_child(line_parser)
73+
$
74+
75+
_abstract _method my_mixin.some_thing
76+
_endmethod
77+
78+
79+
_block
80+
_local some_local << 1
81+
_constant some_local_constant << 1
82+
_global some_global1, some_global2
83+
some_global1 << 1
84+
bruh = 10
85+
86+
some_proc << _proc (arg1)
87+
arg1.action()
88+
_endproc
89+
_endblock

internal/ctags_config/ctags_config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var supportedLanguages = map[string]struct{}{
6666
"java": {},
6767
"javascript": {},
6868
"kotlin": {},
69+
"magik": {},
6970
"python": {},
7071
"ruby": {},
7172
"rust": {},
@@ -81,6 +82,7 @@ var DefaultEngines = map[string]ParserType{
8182
"go": ScipCtags,
8283
"javascript": ScipCtags,
8384
"kotlin": ScipCtags,
85+
"magik": ScipCtags,
8486
"python": ScipCtags,
8587
"ruby": ScipCtags,
8688
"rust": ScipCtags,

0 commit comments

Comments
 (0)