Skip to content

Commit 217834b

Browse files
Merge pull request #5 from crystal-lang-tools/nobody/crystal-tree-sitter
Move to crystal-lang-tools/tree-sitter-crystal
2 parents 405cb76 + ff8d494 commit 217834b

File tree

13 files changed

+337
-214
lines changed

13 files changed

+337
-214
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
2-
name = "zed_crystal"
3-
version = "0.0.1"
42
edition = "2021"
3+
name = "zed_crystal"
54
publish = false
5+
version = "0.0.2"
66

77
[lib]
8-
path = "src/crystal.rs"
98
crate-type = ["cdylib"]
9+
path = "src/crystal.rs"
1010

1111
[dependencies]
1212
zed_extension_api = "0.1.0"

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# Zed Crystal Support (WIP)
1+
# Crystal Lang Support for Zed
22

3-
![](./assets/image.png)
3+
Uses the Crystal lang tree-sitter found at [crystal-lang-tools/tree-sitter-crystal](https://github.com/crystal-lang-tools/tree-sitter-crystal),
4+
which is mostly complete, and can parse the majority of Crystal's own source code without errors.
45

5-
This is very much a work in progress as the tree-sitter is developed. Utilizes the tree-sitter found [here](https://github.com/crystal-lang-tools/tree-sitter).
6+
Also uses [Crystalline](https://github.com/elbywan/crystalline) for LSP functionality, if it is available in `$PATH`.
67

7-
Dev installation:
8-
- Clone the repository, rename the folder to `crystal`
9-
- Install [crystalline](https://github.com/elbywan/crystalline/releases/tag/v0.14.1) and make sure it is on `$PATH`
10-
- In Zed, install a dev extension with Cmd+Shift+P > `install dev extension`
8+
![](./assets/image.png)

assets/image.png

-188 KB
Loading

extension.toml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ id = "crystal"
44
name = "Crystal"
55
repository = "https://github.com/crystal-lang-tools/zed-crystal"
66
schema_version = 1
7-
version = "0.0.1"
7+
version = "0.0.2"
88

9-
# Use Ruby grammar for now until Crystal grammar is more complete
10-
[grammars.ruby]
11-
repository = "https://github.com/tree-sitter/tree-sitter-ruby"
12-
commit = "7dbc1e2d0e2d752577655881f73b4573f3fe85d4"
9+
[grammars.crystal]
10+
commit = "cd3ae0751a58bca9fe875e580102578f5228a5a1"
11+
repository = "https://github.com/crystal-lang-tools/tree-sitter-crystal"
1312

1413
[language_servers.crystalline]
15-
name = "crystalline"
1614
language = "Crystal"
17-
18-
# [grammars.crystal]
19-
# commit = "61cc201c8eb3b6fd4d4eb3e0ac6c303a580eeb6b"
20-
# repository = "https://github.com/crystal-lang-tools/tree-sitter"
15+
name = "crystalline"

languages/crystal/brackets.scm

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
("[" @open "]" @close)
22
("{" @open "}" @close)
33
("\"" @open "\"" @close)
4-
("do" @open "end" @close)
4+
("{%" @open "%}" @close)
5+
("{{" @open "}}" @close)
56

6-
(block_parameters "|" @open "|" @close)
7+
(begin "begin" @open "end" @close)
8+
(block "do" @open "end" @close)
9+
10+
("|" @open "|" @close)
711
(interpolation "#{" @open "}" @close)
812

913
(if "if" @open "end" @close)
1014
(unless "unless" @open "end" @close)
11-
(begin "begin" @open "end" @close)
12-
(module "module" @open "end" @close)
13-
(_ . "def" @open "end" @close)
14-
(_ . "class" @open "end" @close)
15+
(while "while" @open "end" @close)
16+
(until "until" @open "end" @close)
17+
(case "case" @open "end" @close)
18+
19+
(annotation_def "annotation" @open "end" @close)
20+
(c_struct_def "struct" @open "end" @close)
21+
(class_def "class" @open "end" @close)
22+
(enum_def "enum" @open "end" @close)
23+
(lib_def "lib" @open "end" @close)
24+
(macro_def "macro" @open "end" @close)
25+
(method_def "def" @open "end" @close)
26+
(module_def "module" @open "end" @close)
27+
(struct_def "struct" @open "end" @close)
28+
(union_def "union" @open "end" @close)

languages/crystal/config.toml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
name = "Crystal"
2-
grammar = "ruby"
3-
path_suffixes = ["cr"]
4-
line_comments = ["# "]
51
autoclose_before = "}])"
62
brackets = [
7-
{ start = "{", end = "}", close = true, newline = true },
8-
{ start = "[", end = "]", close = true, newline = true },
9-
{ start = "(", end = ")", close = true, newline = true },
10-
{ start = "\"", end = "\"", close = true, newline = false, not_in = [
11-
"comment",
12-
"string",
13-
] },
14-
{ start = "'", end = "'", close = true, newline = false, not_in = [
15-
"comment",
16-
"string",
17-
] },
18-
{ start = "`", end = "`", close = true, newline = false, not_in = [
19-
"comment",
20-
"string",
21-
] },
3+
{start = "{", end = "}", close = true, newline = true},
4+
{start = "[", end = "]", close = true, newline = true},
5+
{start = "(", end = ")", close = true, newline = true},
6+
{start = "\"", end = "\"", close = true, newline = false, not_in = [
7+
"comment",
8+
"string",
9+
]},
10+
{start = "'", end = "'", close = true, newline = false, not_in = [
11+
"comment",
12+
"string",
13+
]},
14+
{start = "`", end = "`", close = true, newline = false, not_in = [
15+
"comment",
16+
"string",
17+
]},
2218
]
2319
collapsed_placeholder = "# ..."
20+
grammar = "crystal"
21+
line_comments = ["# "]
22+
name = "Crystal"
23+
path_suffixes = ["cr"]
2424
tab_size = 2

languages/crystal/embedding.scm

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,43 @@
22
(comment)* @context
33
.
44
[
5-
(module
6-
"module" @name
5+
(alias
6+
"alias" @name
77
name: (_) @name)
8-
(method
9-
"def" @name
10-
name: (_) @name
11-
body: (body_statement) @collapse)
12-
(class
8+
(annotation_def
9+
"annotation" @name
10+
name: (_) @name)
11+
(c_struct_def
12+
"struct" @name
13+
name: (_) @name)
14+
(class_def
1315
"class" @name
1416
name: (_) @name)
15-
(singleton_method
17+
(const_assign
18+
lhs: (_) @name)
19+
(enum_def
20+
"enum" @name
21+
name: (_) @name)
22+
(lib_def
23+
"lib" @name
24+
name: (_) @name)
25+
(macro_def
26+
"macro" @name
27+
name: (_) @name)
28+
(method_def
1629
"def" @name
17-
object: (_) @name
18-
"." @name
19-
name: (_) @name
20-
body: (body_statement) @collapse)
21-
] @item
22-
)
30+
name: (_) @name)
31+
(module_def
32+
"module" @name
33+
name: (_) @name)
34+
(struct_def
35+
"struct" @name
36+
name: (_) @name)
37+
(type_def
38+
"type" @name
39+
name: (_) @name)
40+
(union_def
41+
"union" @name
42+
name: (_) @name)
43+
] @item
44+
)

0 commit comments

Comments
 (0)