Skip to content

Snippets

Soutaro Matsumoto edited this page May 2, 2024 · 2 revisions

We haven't provided completions built for language servers, but the following snippets can be used to set up your editor.

VSCode

"Configure User Snippets" from Command Palette and fill the .code-snippets file with the snippet. (VSCode docs)

Snippet
{
	"Magic comment": {
		"scope": "ruby",
		"prefix": "rbs_inline: enabled",
		"body": [
			"rbs_inline: enabled"
		],
		"description": "Enable RBS::Inline"
	},
	"Method parameter type": {
		"scope": "ruby",
		"prefix": "@rbs {variable}: {T}",
		"body": [
			"@rbs ${1:variable}: ${2:type}"
		],
		"description": "Type of method parameter"
	},
	"Method return type": {
		"scope": "ruby",
		"prefix": "@rbs returns {T}",
		"body": [
			"@rbs returns ${1:type}"
		],
		"description": "Return type of a method"
	},
	"Yields type": {
		"scope": "ruby",
		"prefix": "@rbs yields {() -> T}",
		"body": [
			"@rbs method: ${1:method-type}"
		],
		"description": "Type of a method"
	},
	"`use` directive": {
		"scope": "ruby",
		"prefix": "@rbs use {Clause}",
		"body": [
			"@rbs use ${1:clause}"
		],
		"description": "`use` directive"
	},
	"super_class": {
		"scope": "ruby",
		"prefix": "@rbs inherits {T}",
		"body": [
			"@rbs inherits ${1:super-class}"
		],
		"description": "Define super class of a class definition"
	},
	"module-self": {
		"scope": "ruby",
		"prefix": "@rbs module-self {T}",
		"body": [
			"@rbs module-self ${1:self-type}"
		],
		"description": "Define module-self constraint of a module definition"
	},
	"generics": {
		"scope": "ruby",
		"prefix": "@rbs generic {A}",
		"body": [
			"@rbs generic ${1:type parameter}"
		],
		"description": "Define generics type parameter of a class/module definition"
	},
	"ivar": {
		"scope": "ruby",
		"prefix": "@rbs @{instance_variable}: {type}",
		"body": [
			"@rbs @${1:x}: ${2:type}"
		],
		"description": "Define type of instance variables"
	},
	"selfivar": {
		"scope": "ruby",
		"prefix": "@rbs self.@{instance_variable}: {type}",
		"body": [
			"@rbs self.@${1:x}: ${2:type}"
		],
		"description": "Define type of instance variables"
	},
	"inline": {
		"scope": "ruby",
		"prefix": "@rbs!",
		"body": [
			"@rbs!",
			"$LINE_COMMENT   "
		],
		"description": "Embed any RBS declarations"
	},
	"skip": {
		"scope": "ruby",
		"prefix": "@rbs skip",
		"body": [
			"@rbs skip"
		],
		"description": "Skip following definition"
	},
	"override": {
		"scope": "ruby",
		"prefix": "@rbs override",
		"body": [
			"@rbs override"
		],
		"description": "Override existing definition"
	},
	"annotation": {
		"scope": "ruby",
		"prefix": "@rbs %a{}",
		"body": ["@rbs %a{${1}}"],
		"description": "Insert RBS annotation"
	}
}
Clone this wiki locally