-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Snippet wrap #296
Snippet wrap #296
Changes from all commits
8dd40cf
61fc7bc
357719e
180f374
cfa46fc
df99a07
a52473f
2a84b42
f411204
b9e1ac1
90d5a5b
8b86f10
7ccafc2
1df155c
6388499
b1a53e2
2e9f7b1
58c5b83
d741029
30b8163
36035c6
5722322
3da4762
541fd3f
07fdfcf
7205c61
1810d62
45e4f82
a0a190d
20a2717
f74bd50
bac3d38
7d716be
a8926a5
6adc0af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"ifElseStatement": { | ||
"definitions": [ | ||
{ | ||
"scope": { | ||
"langIds": [ | ||
"typescript", | ||
"typescriptreact", | ||
"javascript", | ||
"javascriptreact", | ||
"cpp", | ||
"c", | ||
"java", | ||
"csharp" | ||
] | ||
}, | ||
"body": [ | ||
"if ($condition) {", | ||
"\t$consequence", | ||
"} else {", | ||
"\t$alternative", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"scope": { | ||
"langIds": [ | ||
"python" | ||
] | ||
}, | ||
"body": [ | ||
"if $condition:", | ||
"\t$consequence", | ||
"else:", | ||
"\t$alternative" | ||
] | ||
} | ||
], | ||
"description": "If else statement", | ||
"variables": { | ||
"consequence": { | ||
"wrapperScopeType": "statement" | ||
}, | ||
"alternative": { | ||
"wrapperScopeType": "statement" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"ifStatement": { | ||
"definitions": [ | ||
{ | ||
"scope": { | ||
"langIds": [ | ||
"typescript", | ||
"typescriptreact", | ||
"javascript", | ||
"javascriptreact", | ||
"cpp", | ||
"c", | ||
"java", | ||
"csharp" | ||
] | ||
}, | ||
"body": [ | ||
"if ($condition) {", | ||
"\t$consequence", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"scope": { | ||
"langIds": [ | ||
"python" | ||
] | ||
}, | ||
"body": [ | ||
"if $condition:", | ||
"\t$consequence" | ||
] | ||
} | ||
], | ||
"description": "If statement", | ||
"variables": { | ||
"consequence": { | ||
"wrapperScopeType": "statement" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"tryCatchStatement": { | ||
"definitions": [ | ||
{ | ||
"scope": { | ||
"langIds": [ | ||
"typescript", | ||
"typescriptreact", | ||
"javascript", | ||
"javascriptreact", | ||
"cpp", | ||
"c", | ||
"java", | ||
"csharp" | ||
] | ||
}, | ||
"body": [ | ||
"try {", | ||
"\t$body", | ||
"} catch ($error) {", | ||
"\t$exceptBody", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"scope": { | ||
"langIds": [ | ||
"python" | ||
] | ||
}, | ||
"body": [ | ||
"try:", | ||
"\t$body", | ||
"except $error:", | ||
"\t$exceptBody" | ||
] | ||
} | ||
], | ||
"description": "Try catch statement", | ||
"variables": { | ||
"body": { | ||
"wrapperScopeType": "statement" | ||
}, | ||
"exceptBody": { | ||
"wrapperScopeType": "statement" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Cursorless snippets | ||
|
||
Cursorless has experimental support for snippets. Currently these snippets are just used for wrapping targets. | ||
|
||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,9 +400,27 @@ | |
"verticalOffset": 0 | ||
} | ||
} | ||
}, | ||
"cursorless.experimental.snippetsDir": { | ||
"description": "Directory containing snippets for use in cursorless", | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"languages": [ | ||
{ | ||
"id": "json", | ||
"extensions": [ | ||
".cursorless-snippets" | ||
] | ||
} | ||
], | ||
"jsonValidation": [ | ||
{ | ||
"fileMatch": "*.cursorless-snippets", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extension is a bit verbose; open to suggestions. Need some way to indicate that the file should be checked by the schema on the next line so that user gets autocomplete |
||
"url": "./schemas/cursorless-snippets.json" | ||
} | ||
] | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "npm run -S esbuild-base -- --minify", | ||
|
@@ -420,7 +438,7 @@ | |
"@types/glob": "^7.1.3", | ||
"@types/js-yaml": "^4.0.2", | ||
"@types/mocha": "^8.0.4", | ||
"@types/node": "^12.11.7", | ||
"@types/node": "^16.11.3", | ||
"@types/sinon": "^10.0.2", | ||
"@types/vscode": "^1.53.0", | ||
"@typescript-eslint/eslint-plugin": "^4.9.0", | ||
|
@@ -432,12 +450,12 @@ | |
"js-yaml": "^4.1.0", | ||
"mocha": "^8.1.3", | ||
"sinon": "^11.1.1", | ||
"typescript": "^4.1.2", | ||
"typescript": "^4.4.4", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note the typescript version bump |
||
"vscode-test": "^1.4.1" | ||
}, | ||
"dependencies": { | ||
"@types/lodash": "^4.14.168", | ||
"immutability-helper": "^3.1.1", | ||
"lodash": "^4.17.21" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Snippets for use in cursorless", | ||
"type": "object", | ||
"additionalProperties": { | ||
"type": "object", | ||
"properties": { | ||
"definitions": { | ||
"type": "array", | ||
"descriptions": "List of possible definitions for this snippet", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"scope": { | ||
"type": "object", | ||
"description": "Scopes where this snippet is active", | ||
"properties": { | ||
"langIds": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"scopeType": { | ||
"$ref": "#/$defs/scopeType", | ||
"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." | ||
} | ||
} | ||
}, | ||
"body": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Inline snippet text using VSCode snippet syntax; entries joined by newline. Named variables of the form $foo can be used as wrappers" | ||
} | ||
}, | ||
"required": [ | ||
"body" | ||
] | ||
} | ||
}, | ||
"variables": { | ||
"type": "object", | ||
"description": "For each named variable in the snippet, provides extra information about the variable.", | ||
"additionalProperties": { | ||
"type": "object", | ||
"properties": { | ||
"wrapperScopeType": { | ||
"$ref": "#/$defs/scopeType", | ||
"description": "Default to this scope type when wrapping a target without scope type specified" | ||
}, | ||
"description": { | ||
"type": "string", | ||
"description": "Description of the snippet variable" | ||
} | ||
} | ||
} | ||
}, | ||
"description": { | ||
"type": "string", | ||
"description": "Description of the snippet" | ||
} | ||
} | ||
}, | ||
"$defs": { | ||
"scopeType": { | ||
"type": "string", | ||
"enum": [ | ||
"argumentOrParameter", | ||
"anonymousFunction", | ||
"attribute", | ||
"class", | ||
"className", | ||
"collectionItem", | ||
"collectionKey", | ||
"comment", | ||
"functionCall", | ||
"functionName", | ||
"ifStatement", | ||
"list", | ||
"map", | ||
"name", | ||
"namedFunction", | ||
"regularExpression", | ||
"statement", | ||
"string", | ||
"type", | ||
"value", | ||
"xmlBothTags", | ||
"xmlElement", | ||
"xmlEndTag", | ||
"xmlStartTag" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ interface MarkEntry { | |
} | ||
|
||
class BringMoveSwap implements Action { | ||
targetPreferences: ActionPreferences[] = [ | ||
getTargetPreferences: () => ActionPreferences[] = () => [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now have a function to give action a chance to see args |
||
{ insideOutsideType: null }, | ||
{ insideOutsideType: null }, | ||
]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy way to update snapshots