Skip to content

Commit 1633ac1

Browse files
authored
Snippet wrap (#296)
* Initial working version * Almost done * Change languageId * Remove accidental file * Attempt at complex version * Initial version using integer placeholders * Working using names * Fix tests * Fix tests * Fix schema * Fixes * Fix python tests * Cleanup yaml formatting * Support snippet overrides * Fix inference * Cleanup * CI fix * Cleanup * Remove yarn-error.log * Update schema docs * More dock * Support user snippets dir * use json schema ref * Fix schema * Wrap with snippet cleanup * Cleanup * More cleanup * Change `/` to `.` for placeholder indication * Reformat * Fix comment * Fix tests * Add basic docs * Change snippet format * Fixes * Add description field
1 parent 2c4d273 commit 1633ac1

File tree

85 files changed

+3399
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3399
-392
lines changed

.eslintrc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@
2121
],
2222
"no-throw-literal": "warn",
2323
"semi": "off"
24-
}
24+
},
25+
"ignorePatterns": [
26+
"**/vendor/**/*.ts",
27+
"**/vendor/**/*.js"
28+
]
2529
}

.vscode/launch.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@
3636
"${workspaceFolder}/out/test/**/*.js"
3737
],
3838
"preLaunchTask": "${defaultBuildTask}"
39+
},
40+
{
41+
"name": "Update fixtures",
42+
"type": "extensionHost",
43+
"request": "launch",
44+
"env": {
45+
"CURSORLESS_TEST": "true",
46+
"CURSORLESS_TEST_UPDATE_FIXTURES": "true",
47+
},
48+
"args": [
49+
"--disable-extension",
50+
"asvetliakov.vscode-neovim",
51+
"--extensionDevelopmentPath=${workspaceFolder}",
52+
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
53+
],
54+
"outFiles": [
55+
"${workspaceFolder}/out/test/**/*.js"
56+
],
57+
"preLaunchTask": "${defaultBuildTask}"
3958
}
4059
]
4160
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"ifElseStatement": {
3+
"definitions": [
4+
{
5+
"scope": {
6+
"langIds": [
7+
"typescript",
8+
"typescriptreact",
9+
"javascript",
10+
"javascriptreact",
11+
"cpp",
12+
"c",
13+
"java",
14+
"csharp"
15+
]
16+
},
17+
"body": [
18+
"if ($condition) {",
19+
"\t$consequence",
20+
"} else {",
21+
"\t$alternative",
22+
"}"
23+
]
24+
},
25+
{
26+
"scope": {
27+
"langIds": [
28+
"python"
29+
]
30+
},
31+
"body": [
32+
"if $condition:",
33+
"\t$consequence",
34+
"else:",
35+
"\t$alternative"
36+
]
37+
}
38+
],
39+
"description": "If else statement",
40+
"variables": {
41+
"consequence": {
42+
"wrapperScopeType": "statement"
43+
},
44+
"alternative": {
45+
"wrapperScopeType": "statement"
46+
}
47+
}
48+
}
49+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"ifStatement": {
3+
"definitions": [
4+
{
5+
"scope": {
6+
"langIds": [
7+
"typescript",
8+
"typescriptreact",
9+
"javascript",
10+
"javascriptreact",
11+
"cpp",
12+
"c",
13+
"java",
14+
"csharp"
15+
]
16+
},
17+
"body": [
18+
"if ($condition) {",
19+
"\t$consequence",
20+
"}"
21+
]
22+
},
23+
{
24+
"scope": {
25+
"langIds": [
26+
"python"
27+
]
28+
},
29+
"body": [
30+
"if $condition:",
31+
"\t$consequence"
32+
]
33+
}
34+
],
35+
"description": "If statement",
36+
"variables": {
37+
"consequence": {
38+
"wrapperScopeType": "statement"
39+
}
40+
}
41+
}
42+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"tryCatchStatement": {
3+
"definitions": [
4+
{
5+
"scope": {
6+
"langIds": [
7+
"typescript",
8+
"typescriptreact",
9+
"javascript",
10+
"javascriptreact",
11+
"cpp",
12+
"c",
13+
"java",
14+
"csharp"
15+
]
16+
},
17+
"body": [
18+
"try {",
19+
"\t$body",
20+
"} catch ($error) {",
21+
"\t$exceptBody",
22+
"}"
23+
]
24+
},
25+
{
26+
"scope": {
27+
"langIds": [
28+
"python"
29+
]
30+
},
31+
"body": [
32+
"try:",
33+
"\t$body",
34+
"except $error:",
35+
"\t$exceptBody"
36+
]
37+
}
38+
],
39+
"description": "Try catch statement",
40+
"variables": {
41+
"body": {
42+
"wrapperScopeType": "statement"
43+
},
44+
"exceptBody": {
45+
"wrapperScopeType": "statement"
46+
}
47+
}
48+
}
49+
}

docs/experimental/snippets.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Cursorless snippets
2+
3+
Cursorless has experimental support for snippets. Currently these snippets are just used for wrapping targets.
4+
5+
The best place to start is to look at the [core cursorless snippets](../../cursorless-snippets). Additionally, there is autocomplete with documentation as you're writing a snippet.

images/nestWrapNearPastDrum.gif

237 KB
Loading

images/tryWrapFine.gif

45.4 KB
Loading

package.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,27 @@
400400
"verticalOffset": 0
401401
}
402402
}
403+
},
404+
"cursorless.experimental.snippetsDir": {
405+
"description": "Directory containing snippets for use in cursorless",
406+
"type": "string"
403407
}
404408
}
405-
}
409+
},
410+
"languages": [
411+
{
412+
"id": "json",
413+
"extensions": [
414+
".cursorless-snippets"
415+
]
416+
}
417+
],
418+
"jsonValidation": [
419+
{
420+
"fileMatch": "*.cursorless-snippets",
421+
"url": "./schemas/cursorless-snippets.json"
422+
}
423+
]
406424
},
407425
"scripts": {
408426
"vscode:prepublish": "npm run -S esbuild-base -- --minify",
@@ -420,7 +438,7 @@
420438
"@types/glob": "^7.1.3",
421439
"@types/js-yaml": "^4.0.2",
422440
"@types/mocha": "^8.0.4",
423-
"@types/node": "^12.11.7",
441+
"@types/node": "^16.11.3",
424442
"@types/sinon": "^10.0.2",
425443
"@types/vscode": "^1.53.0",
426444
"@typescript-eslint/eslint-plugin": "^4.9.0",
@@ -432,12 +450,12 @@
432450
"js-yaml": "^4.1.0",
433451
"mocha": "^8.1.3",
434452
"sinon": "^11.1.1",
435-
"typescript": "^4.1.2",
453+
"typescript": "^4.4.4",
436454
"vscode-test": "^1.4.1"
437455
},
438456
"dependencies": {
439457
"@types/lodash": "^4.14.168",
440458
"immutability-helper": "^3.1.1",
441459
"lodash": "^4.17.21"
442460
}
443-
}
461+
}

schemas/cursorless-snippets.json

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Snippets for use in cursorless",
4+
"type": "object",
5+
"additionalProperties": {
6+
"type": "object",
7+
"properties": {
8+
"definitions": {
9+
"type": "array",
10+
"descriptions": "List of possible definitions for this snippet",
11+
"items": {
12+
"type": "object",
13+
"properties": {
14+
"scope": {
15+
"type": "object",
16+
"description": "Scopes where this snippet is active",
17+
"properties": {
18+
"langIds": {
19+
"type": "array",
20+
"items": {
21+
"type": "string"
22+
}
23+
},
24+
"scopeType": {
25+
"$ref": "#/$defs/scopeType",
26+
"description": "Cursorless scopes in which this snippet is active. Allows, for example, to have different snippets to define a function if you're in a class or at global scope."
27+
}
28+
}
29+
},
30+
"body": {
31+
"type": "array",
32+
"items": {
33+
"type": "string"
34+
},
35+
"description": "Inline snippet text using VSCode snippet syntax; entries joined by newline. Named variables of the form $foo can be used as wrappers"
36+
}
37+
},
38+
"required": [
39+
"body"
40+
]
41+
}
42+
},
43+
"variables": {
44+
"type": "object",
45+
"description": "For each named variable in the snippet, provides extra information about the variable.",
46+
"additionalProperties": {
47+
"type": "object",
48+
"properties": {
49+
"wrapperScopeType": {
50+
"$ref": "#/$defs/scopeType",
51+
"description": "Default to this scope type when wrapping a target without scope type specified"
52+
},
53+
"description": {
54+
"type": "string",
55+
"description": "Description of the snippet variable"
56+
}
57+
}
58+
}
59+
},
60+
"description": {
61+
"type": "string",
62+
"description": "Description of the snippet"
63+
}
64+
}
65+
},
66+
"$defs": {
67+
"scopeType": {
68+
"type": "string",
69+
"enum": [
70+
"argumentOrParameter",
71+
"anonymousFunction",
72+
"attribute",
73+
"class",
74+
"className",
75+
"collectionItem",
76+
"collectionKey",
77+
"comment",
78+
"functionCall",
79+
"functionName",
80+
"ifStatement",
81+
"list",
82+
"map",
83+
"name",
84+
"namedFunction",
85+
"regularExpression",
86+
"statement",
87+
"string",
88+
"type",
89+
"value",
90+
"xmlBothTags",
91+
"xmlElement",
92+
"xmlEndTag",
93+
"xmlStartTag"
94+
]
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)