Skip to content
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

Merged
merged 35 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8dd40cf
Initial working version
pokey Oct 15, 2021
61fc7bc
Almost done
pokey Oct 15, 2021
357719e
Change languageId
pokey Oct 15, 2021
180f374
Remove accidental file
pokey Oct 15, 2021
cfa46fc
Attempt at complex version
pokey Oct 17, 2021
df99a07
Initial version using integer placeholders
pokey Oct 21, 2021
a52473f
Working using names
pokey Oct 21, 2021
2a84b42
Fix tests
pokey Oct 21, 2021
f411204
Fix tests
pokey Oct 21, 2021
b9e1ac1
Fix schema
pokey Oct 21, 2021
90d5a5b
Fixes
pokey Oct 21, 2021
8b86f10
Fix python tests
pokey Oct 21, 2021
7ccafc2
Cleanup yaml formatting
pokey Oct 21, 2021
1df155c
Support snippet overrides
pokey Oct 21, 2021
6388499
Fix inference
pokey Oct 21, 2021
b1a53e2
Cleanup
pokey Oct 21, 2021
2e9f7b1
CI fix
pokey Oct 21, 2021
58c5b83
Cleanup
pokey Oct 21, 2021
d741029
Remove yarn-error.log
pokey Oct 21, 2021
30b8163
Update schema docs
pokey Oct 21, 2021
36035c6
More dock
pokey Oct 22, 2021
5722322
Support user snippets dir
pokey Oct 23, 2021
3da4762
use json schema ref
pokey Oct 23, 2021
541fd3f
Fix schema
pokey Oct 23, 2021
07fdfcf
Wrap with snippet cleanup
pokey Oct 23, 2021
7205c61
Cleanup
pokey Oct 23, 2021
1810d62
More cleanup
pokey Oct 23, 2021
45e4f82
Change `/` to `.` for placeholder indication
pokey Oct 23, 2021
a0a190d
Reformat
pokey Oct 23, 2021
20a2717
Fix comment
pokey Oct 23, 2021
f74bd50
Fix tests
pokey Oct 23, 2021
bac3d38
Add basic docs
pokey Oct 23, 2021
7d716be
Change snippet format
pokey Oct 25, 2021
a8926a5
Fixes
pokey Oct 25, 2021
6adc0af
Add description field
pokey Oct 25, 2021
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
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
],
"no-throw-literal": "warn",
"semi": "off"
}
},
"ignorePatterns": [
"**/vendor/**/*.ts",
"**/vendor/**/*.js"
]
}
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Update fixtures",
Copy link
Member Author

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

"type": "extensionHost",
"request": "launch",
"env": {
"CURSORLESS_TEST": "true",
"CURSORLESS_TEST_UPDATE_FIXTURES": "true",
},
"args": [
"--disable-extension",
"asvetliakov.vscode-neovim",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
45 changes: 45 additions & 0 deletions cursorless-snippets/ifElseStatement.cursorless-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"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"
]
}
],
"defaultScopeTypes": {
"consequence": "statement",
"alternative": "statement"
},
"description": "If else statement"
}
}
40 changes: 40 additions & 0 deletions cursorless-snippets/ifStatement.cursorless-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"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"
]
}
],
"defaultScopeTypes": {
"consequence": "statement"
},
"description": "If statement"
}
}
45 changes: 45 additions & 0 deletions cursorless-snippets/tryCatchStatement.cursorless-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"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"
]
}
],
"defaultScopeTypes": {
"body": "statement",
"exceptBody": "statement"
},
"description": "Try catch statement"
}
}
Binary file added images/nestWrapNearPastDrum.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tryWrapFine.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 22 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member Author

Choose a reason for hiding this comment

The 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",
Expand All @@ -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",
Expand All @@ -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",
Copy link
Member Author

Choose a reason for hiding this comment

The 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"
}
}
}
87 changes: 87 additions & 0 deletions schemas/cursorless-snippets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"$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; entries joined by newline"
}
},
"required": [
"body"
]
}
},
"defaultScopeTypes": {
"type": "object",
"description": "For each named variable in the snippet, uses the given scope type from this map when wrapping a target without scope type specified",
"additionalProperties": {
"$ref": "#/$defs/scopeType"
}
},
"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"
]
}
}
}
2 changes: 1 addition & 1 deletion src/actions/BringMoveSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface MarkEntry {
}

class BringMoveSwap implements Action {
targetPreferences: ActionPreferences[] = [
getTargetPreferences: () => ActionPreferences[] = () => [
Copy link
Member Author

Choose a reason for hiding this comment

The 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 },
];
Expand Down
2 changes: 1 addition & 1 deletion src/actions/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { ensureSingleTarget } from "../util/targetUtils";

export default class Call implements Action {
targetPreferences: ActionPreferences[] = [
getTargetPreferences: () => ActionPreferences[] = () => [
{ insideOutsideType: "inside" },
{ insideOutsideType: "inside" },
];
Expand Down
2 changes: 1 addition & 1 deletion src/actions/Clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ensureSingleEditor } from "../util/targetUtils";
import { setSelectionsAndFocusEditor } from "../util/setSelectionsAndFocusEditor";

export default class Clear implements Action {
targetPreferences: ActionPreferences[] = [{ insideOutsideType: "inside" }];
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }];

constructor(private graph: Graph) {
this.run = this.run.bind(this);
Expand Down
2 changes: 1 addition & 1 deletion src/actions/CommandAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { callFunctionAndUpdateSelections } from "../util/updateSelections";
import { ensureSingleEditor } from "../util/targetUtils";

export default class CommandAction implements Action {
targetPreferences: ActionPreferences[] = [{ insideOutsideType: "inside" }];
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }];
private ensureSingleEditor: boolean;

constructor(
Expand Down
2 changes: 1 addition & 1 deletion src/actions/CopyLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import unifyRanges from "../util/unifyRanges";
import expandToContainingLine from "../util/expandToContainingLine";

class CopyLines implements Action {
targetPreferences: ActionPreferences[] = [{ insideOutsideType: "inside" }];
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }];

constructor(private graph: Graph, private isUp: boolean) {
this.run = this.run.bind(this);
Expand Down
2 changes: 1 addition & 1 deletion src/actions/CutCopyPaste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getOutsideOverflow } from "../util/targetUtils";
import { zip } from "lodash";

export class Cut implements Action {
targetPreferences: ActionPreferences[] = [{ insideOutsideType: null }];
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: null }];

constructor(private graph: Graph) {
this.run = this.run.bind(this);
Expand Down
2 changes: 1 addition & 1 deletion src/actions/Delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { flatten } from "lodash";
import { performEditsAndUpdateSelections } from "../util/updateSelections";

export default class Delete implements Action {
targetPreferences: ActionPreferences[] = [{ insideOutsideType: "outside" }];
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "outside" }];

constructor(private graph: Graph) {
this.run = this.run.bind(this);
Expand Down
2 changes: 1 addition & 1 deletion src/actions/EditNewLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { commands, Selection } from "vscode";

class EditNewLine implements Action {
targetPreferences: ActionPreferences[] = [{ insideOutsideType: "inside" }];
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }];

constructor(private graph: Graph, private isAbove: boolean) {
this.run = this.run.bind(this);
Expand Down
2 changes: 1 addition & 1 deletion src/actions/ExtractVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ensureSingleTarget } from "../util/targetUtils";
import { commands } from "vscode";

export default class ExtractVariable implements Action {
targetPreferences: ActionPreferences[] = [{ insideOutsideType: "inside" }];
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }];

constructor(private graph: Graph) {
this.run = this.run.bind(this);
Expand Down
Loading