diff --git a/LICENSE-APACHE b/LICENSE-APACHE index f5f68b6..2392b09 100644 --- a/LICENSE-APACHE +++ b/LICENSE-APACHE @@ -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 diff --git a/extension.toml b/extension.toml index f0cf46a..802f0d3 100644 --- a/extension.toml +++ b/extension.toml @@ -5,6 +5,7 @@ version = "0.4.6" schema_version = 1 authors = ["Vitaly Slobodin "] repository = "https://github.com/zed-extensions/ruby" +snippets = "snippets.json" [language_servers.solargraph] name = "Solargraph" diff --git a/snippets.json b/snippets.json new file mode 100644 index 0000000..8873f2f --- /dev/null +++ b/snippets.json @@ -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." + } +}