Skip to content

Add snippets #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions LICENSE-APACHE
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,13 @@ Apache License


END OF TERMS AND CONDITIONS

---

The contents of snippets.json are derived from Ruby LSP:

Copyright (c) 2022-present, Shopify Inc.
https://github.com/Shopify/ruby-lsp

Released under the MIT license
https://github.com/Shopify/ruby-lsp/blob/main/vscode/LICENSE.txt
1 change: 1 addition & 0 deletions extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.4.6"
schema_version = 1
authors = ["Vitaly Slobodin <[email protected]>"]
repository = "https://github.com/zed-extensions/ruby"
snippets = "snippets.json"

[language_servers.solargraph]
name = "Solargraph"
Expand Down
160 changes: 160 additions & 0 deletions snippets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"New Minitest spec": {
"prefix": ["Minitest"],
"body": [
"# frozen_string_literal: true",
"",
"require \"spec_helper\"",
"",
"class $1 < Minitest::Spec",
" describe \"$2\" do",
" it \"$3\" do",
" $0",
" assert(true)",
" end",
" end",
"end",
""
],
"description": "New Minitest class using the spec syntax."
},
"New Minitest test": {
"prefix": ["Minitest"],
"body": [
"# frozen_string_literal: true",
"",
"require \"test_helper\"",
"",
"class $1 < Minitest::Test",
" def test_$2",
" $0",
" assert(true)",
" end",
"end",
""
],
"description": "New Minitest class using the test syntax."
},
"New Rspec test": {
"prefix": ["Rspec"],
"body": [
"# frozen_string_literal: true",
"",
"describe $1 do",
" describe \"$2\" do",
" it \"$3\" do",
" $0",
" expect(true).to eq(true)",
" end",
" end",
"end",
""
],
"description": "New Minitest class using the spec syntax."
},
"New class": {
"prefix": ["class"],
"body": ["class $1", " def initialize", " $0", " end", "end", ""],
"description": "New Ruby class."
},
"New module": {
"prefix": ["module"],
"body": ["module $1", " def $2", " $0", " end", "end", ""],
"description": "New Ruby module."
},
"Begin rescue block": {
"prefix": ["begin"],
"body": ["begin", " $0", "rescue $1", "end", ""],
"description": "New Ruby begin block with rescue."
},
"Begin rescue ensure": {
"prefix": ["begin"],
"body": ["begin", " $0", "rescue $1", "ensure", "end", ""],
"description": "New Ruby begin block with rescue and ensure."
},
"Each inline": {
"prefix": ["each"],
"body": ["each { |$1| $0 }"],
"description": "New Ruby inline each loop."
},
"Each block": {
"prefix": ["each"],
"body": ["each do |$1|", " $0", "end"],
"description": "New Ruby each loop."
},
"Map inline": {
"prefix": ["map"],
"body": ["map { |$1| $0 }"],
"description": "New Ruby inline map loop."
},
"Map block": {
"prefix": ["map"],
"body": ["map do |$1|", " $0", "end"],
"description": "New Ruby map loop."
},
"Flat map inline": {
"prefix": ["flat_map"],
"body": ["flat_map { |$1| $0 }"],
"description": "New Ruby inline flat_map loop."
},
"Flat Map block": {
"prefix": ["flat_map"],
"body": ["flat_map do |$1|", " $0", "end"],
"description": "New Ruby flat_map loop."
},
"Select inline": {
"prefix": ["select"],
"body": ["select { |$1| $0 }"],
"description": "New Ruby inline select loop."
},
"Select block": {
"prefix": ["select"],
"body": ["select do |$1|", " $0", "end"],
"description": "New Ruby select loop."
},
"Find inline": {
"prefix": ["find"],
"body": ["find { |$1| $0 }"],
"description": "New Ruby inline find loop."
},
"Find block": {
"prefix": ["find"],
"body": ["find do |$1|", " $0", "end"],
"description": "New Ruby find loop."
},
"Define method method": {
"prefix": ["def"],
"body": ["def $1", " $0", "end"],
"description": "New method."
},
"Define singleton method": {
"prefix": ["defs"],
"body": ["def self.$1", " $0", "end"],
"description": "New singleton method."
},
"Define attribute accessor": {
"prefix": ["attr"],
"body": ["attr_accessor :$1"],
"description": "New attribute accessor."
},
"Define attribute reader": {
"prefix": ["attr"],
"body": ["attr_reader :$1"],
"description": "New attribute reader."
},
"Define attribute writer": {
"prefix": ["attr"],
"body": ["attr_writer :$1"],
"description": "New attribute writer."
},
"If else": {
"prefix": ["if"],
"body": ["if $1", " $0", "else", "end"],
"description": "New if statement with else."
},
"If elsif": {
"prefix": ["if"],
"body": ["if $1", " $0", "elsif $2", " $0", "end"],
"description": "New if statement with elsif."
}
}