Skip to content

Commit d42b759

Browse files
authored
Add snippets (#53)
This PR adds a set of snippets to the add-on (see https://zed.dev/docs/snippets) ~They were added to Ruby LSP in Shopify/vscode-ruby-lsp#150. I believe they were derived from [Textmate's Ruby bundle](https://github.com/textmate/ruby.tmbundle).~ (incorrect) The `vscode-ruby-lsp` repo was later combined into the `ruby-lsp` repo, so they now live at https://github.com/Shopify/ruby-lsp/blob/main/vscode/snippets.json. The file I'm adding here is an exact copy that file. I think there's a opportunity to improve the snippets, so consider this as a starting point. ~I'm currently investigating why snippets are appearing twice:~ solved by zed-industries/zed#28940 Note: It's possible that snippet completion may be later moved into the LSP: Shopify/ruby-lsp#1874 TODO: - [x] Check if the `LICENSE` needs updated to mention that these were sourced from Ruby LSP. - [x] Wait for zed-industries/zed#15846
1 parent 0cd47e0 commit d42b759

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-0
lines changed

LICENSE-APACHE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,13 @@ Apache License
220220

221221

222222
END OF TERMS AND CONDITIONS
223+
224+
---
225+
226+
The contents of snippets.json are derived from Ruby LSP:
227+
228+
Copyright (c) 2022-present, Shopify Inc.
229+
https://github.com/Shopify/ruby-lsp
230+
231+
Released under the MIT license
232+
https://github.com/Shopify/ruby-lsp/blob/main/vscode/LICENSE.txt

extension.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.11.0"
55
schema_version = 1
66
authors = ["Vitaly Slobodin <vitaliy.slobodin@gmail.com>"]
77
repository = "https://github.com/zed-extensions/ruby"
8+
snippets = "snippets.json"
89

910
[language_servers.solargraph]
1011
name = "Solargraph"

snippets.json

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
{
2+
"New Minitest spec": {
3+
"prefix": ["Minitest"],
4+
"body": [
5+
"# frozen_string_literal: true",
6+
"",
7+
"require \"spec_helper\"",
8+
"",
9+
"class $1 < Minitest::Spec",
10+
" describe \"$2\" do",
11+
" it \"$3\" do",
12+
" $0",
13+
" assert(true)",
14+
" end",
15+
" end",
16+
"end",
17+
""
18+
],
19+
"description": "New Minitest class using the spec syntax."
20+
},
21+
"New Minitest test": {
22+
"prefix": ["Minitest"],
23+
"body": [
24+
"# frozen_string_literal: true",
25+
"",
26+
"require \"test_helper\"",
27+
"",
28+
"class $1 < Minitest::Test",
29+
" def test_$2",
30+
" $0",
31+
" assert(true)",
32+
" end",
33+
"end",
34+
""
35+
],
36+
"description": "New Minitest class using the test syntax."
37+
},
38+
"New Rspec test": {
39+
"prefix": ["Rspec"],
40+
"body": [
41+
"# frozen_string_literal: true",
42+
"",
43+
"describe $1 do",
44+
" describe \"$2\" do",
45+
" it \"$3\" do",
46+
" $0",
47+
" expect(true).to eq(true)",
48+
" end",
49+
" end",
50+
"end",
51+
""
52+
],
53+
"description": "New Minitest class using the spec syntax."
54+
},
55+
"New class": {
56+
"prefix": ["class"],
57+
"body": ["class $1", " def initialize", " $0", " end", "end", ""],
58+
"description": "New Ruby class."
59+
},
60+
"New module": {
61+
"prefix": ["module"],
62+
"body": ["module $1", " def $2", " $0", " end", "end", ""],
63+
"description": "New Ruby module."
64+
},
65+
"Begin rescue block": {
66+
"prefix": ["begin"],
67+
"body": ["begin", " $0", "rescue $1", "end", ""],
68+
"description": "New Ruby begin block with rescue."
69+
},
70+
"Begin rescue ensure": {
71+
"prefix": ["begin"],
72+
"body": ["begin", " $0", "rescue $1", "ensure", "end", ""],
73+
"description": "New Ruby begin block with rescue and ensure."
74+
},
75+
"Each inline": {
76+
"prefix": ["each"],
77+
"body": ["each { |$1| $0 }"],
78+
"description": "New Ruby inline each loop."
79+
},
80+
"Each block": {
81+
"prefix": ["each"],
82+
"body": ["each do |$1|", " $0", "end"],
83+
"description": "New Ruby each loop."
84+
},
85+
"Map inline": {
86+
"prefix": ["map"],
87+
"body": ["map { |$1| $0 }"],
88+
"description": "New Ruby inline map loop."
89+
},
90+
"Map block": {
91+
"prefix": ["map"],
92+
"body": ["map do |$1|", " $0", "end"],
93+
"description": "New Ruby map loop."
94+
},
95+
"Flat map inline": {
96+
"prefix": ["flat_map"],
97+
"body": ["flat_map { |$1| $0 }"],
98+
"description": "New Ruby inline flat_map loop."
99+
},
100+
"Flat Map block": {
101+
"prefix": ["flat_map"],
102+
"body": ["flat_map do |$1|", " $0", "end"],
103+
"description": "New Ruby flat_map loop."
104+
},
105+
"Select inline": {
106+
"prefix": ["select"],
107+
"body": ["select { |$1| $0 }"],
108+
"description": "New Ruby inline select loop."
109+
},
110+
"Select block": {
111+
"prefix": ["select"],
112+
"body": ["select do |$1|", " $0", "end"],
113+
"description": "New Ruby select loop."
114+
},
115+
"Find inline": {
116+
"prefix": ["find"],
117+
"body": ["find { |$1| $0 }"],
118+
"description": "New Ruby inline find loop."
119+
},
120+
"Find block": {
121+
"prefix": ["find"],
122+
"body": ["find do |$1|", " $0", "end"],
123+
"description": "New Ruby find loop."
124+
},
125+
"Define method method": {
126+
"prefix": ["def"],
127+
"body": ["def $1", " $0", "end"],
128+
"description": "New method."
129+
},
130+
"Define singleton method": {
131+
"prefix": ["defs"],
132+
"body": ["def self.$1", " $0", "end"],
133+
"description": "New singleton method."
134+
},
135+
"Define attribute accessor": {
136+
"prefix": ["attr"],
137+
"body": ["attr_accessor :$1"],
138+
"description": "New attribute accessor."
139+
},
140+
"Define attribute reader": {
141+
"prefix": ["attr"],
142+
"body": ["attr_reader :$1"],
143+
"description": "New attribute reader."
144+
},
145+
"Define attribute writer": {
146+
"prefix": ["attr"],
147+
"body": ["attr_writer :$1"],
148+
"description": "New attribute writer."
149+
},
150+
"If else": {
151+
"prefix": ["if"],
152+
"body": ["if $1", " $0", "else", "end"],
153+
"description": "New if statement with else."
154+
},
155+
"If elsif": {
156+
"prefix": ["if"],
157+
"body": ["if $1", " $0", "elsif $2", " $0", "end"],
158+
"description": "New if statement with elsif."
159+
}
160+
}

0 commit comments

Comments
 (0)