Conversation
|
@AndreasArvidsson looks like this is failing because the snippet inserts |
package.json
Outdated
| } | ||
| }, | ||
| "cursorless.wrapperSnippetPreferences": { | ||
| "description": "Allows snippets to signal what their default scope types etcetera should be", |
There was a problem hiding this comment.
Down the road we may allow signalling things like selectionType, etc, so I figured let's have this be a map
package.json
Outdated
| "properties": { | ||
| "scopeType": { | ||
| "type": "string", | ||
| "enum": [ |
There was a problem hiding this comment.
This enum will get stale, but I don't think it will cause any serious problems, and the autocomplete will be nice
snippets/cpp.json
Outdated
| @@ -0,0 +1,26 @@ | |||
| { | |||
There was a problem hiding this comment.
Decided to duplicate these snippets between languages as I'd imagine they'll start to diverge. but easy to just use one file as well
|
|
||
| class BringMoveSwap implements Action { | ||
| targetPreferences: ActionPreferences[] = [ | ||
| getTargetPreferences: () => ActionPreferences[] = () => [ |
There was a problem hiding this comment.
We now have a function to give action a chance to see args
src/actions/WrapWithSnippet.ts
Outdated
|
|
||
| export default class WrapWithSnippet implements Action { | ||
| getTargetPreferences( | ||
| partialTargets: PartialTarget[], |
There was a problem hiding this comment.
We have this arg here so that below FIXME can be implemented in the future. Mixed feelings about letting action see this thing but not sure how else to let it do something like figure out which editor a target is referring to
There was a problem hiding this comment.
- pass in context object with callbacks instead
| @@ -0,0 +1,47 @@ | |||
| spokenForm: try catch wrap this | |||
| }); | ||
| const editor = await vscode.window.showTextDocument(document); | ||
|
|
||
| if (!fixture.initialState.documentContents.includes("\n")) { |
There was a problem hiding this comment.
This seemed reasonable to me and doesn't break your line ending tests
| ); | ||
| if (process.env.CURSORLESS_TEST_UPDATE_FIXTURES == "true") { | ||
| const outputFixture = { ...fixture, finalState: resultState, returnValue }; | ||
| await fsp.writeFile(file, serialize(outputFixture)); |
There was a problem hiding this comment.
Easy way to update snapshots
| "preLaunchTask": "${defaultBuildTask}" | ||
| }, | ||
| { | ||
| "name": "Update fixtures", |
There was a problem hiding this comment.
Easy way to update snapshots
a0d5e21 to
b492207
Compare
pokey
left a comment
There was a problem hiding this comment.
- remove prefixes so just
ifStatement - double-check that can say "if wrap token air"
package.json
Outdated
| } | ||
| } | ||
| }, | ||
| "cursorless.wrapperSnippetPreferences": { |
There was a problem hiding this comment.
- have a
cursorless.snippetssetting with just adefaultScopeTypeproperty.
|
|
||
| export class Sort implements Action { | ||
| targetPreferences: ActionPreferences[] = [{ insideOutsideType: "inside" }]; | ||
| getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }]; |
There was a problem hiding this comment.
- see if i can get rid of type here
src/actions/WrapWithSnippet.ts
Outdated
|
|
||
| export default class WrapWithSnippet implements Action { | ||
| getTargetPreferences( | ||
| partialTargets: PartialTarget[], |
There was a problem hiding this comment.
- pass in context object with callbacks instead
package.json
Outdated
| "ifElseStatement": { | ||
| "definitions": [ | ||
| { | ||
| "scope": { | ||
| "langIds": [ | ||
| "typescript", | ||
| "typescriptreact", | ||
| "javascript", | ||
| "javascriptreact", | ||
| "cpp", | ||
| "c", | ||
| "java", | ||
| "csharp" | ||
| ] | ||
| }, | ||
| "body": [ | ||
| "if ($condition) {\n\t$consequence\n} else {\n\t$alternative\n}" | ||
| ] | ||
| }, | ||
| { | ||
| "scope": { | ||
| "langIds": [ | ||
| "python" | ||
| ] | ||
| }, | ||
| "body": [ | ||
| "if $condition:\n\t$consequence\nelse:\n\t$alternative" | ||
| ] | ||
| } | ||
| ], | ||
| "defaultScopeTypes": { | ||
| "consequence": "statement", | ||
| "alternative": "statement" | ||
| }, | ||
| "description": "If else statement" | ||
| } |
There was a problem hiding this comment.
@AndreasArvidsson wdyt? See how we have a single snippet for if / else?
package.json
Outdated
| "type": "string" | ||
| } | ||
| }, | ||
| "scopeType": { |
There was a problem hiding this comment.
This scopeType isn't yet supported, but will allow us to differentiate "snip funk" in a class vs top-level in the future, as discussed
package.json
Outdated
| } | ||
| } | ||
| }, | ||
| "cursorless.experimental.snippets": { |
There was a problem hiding this comment.
Tagged the setting as experimental
package.json
Outdated
| "type": "object", | ||
| "default": { | ||
| "ifStatement": { | ||
| "definitions": [], |
There was a problem hiding this comment.
We put the definitions elsewhere so that the user can easily put their own, which take precedence over built-in ones
| const selectionType = | ||
| maybeSelectionType ?? actionPreferences.selectionType ?? "token"; | ||
| maybeSelectionType ?? | ||
| (target.modifier == null ? actionPreferences.selectionType : null) ?? |
There was a problem hiding this comment.
Basically a hack until we merge scopeType and selectionType using pipeline support
| @@ -0,0 +1,436 @@ | |||
| /*--------------------------------------------------------------------------------------------- | |||
There was a problem hiding this comment.
We vendor in vscode snippet parser. I don't feel great about it. But I think it should be ok as snippet syntax shouldn't change too fast
| ], | ||
| "jsonValidation": [ | ||
| { | ||
| "fileMatch": "*.cursorless-snippets", |
There was a problem hiding this comment.
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
| "mocha": "^8.1.3", | ||
| "sinon": "^11.1.1", | ||
| "typescript": "^4.1.2", | ||
| "typescript": "^4.4.4", |
There was a problem hiding this comment.
Note the typescript version bump
| sourceMark, | ||
| addDecorations, | ||
| experimental: { | ||
| registerThirdPartySnippets: graph.snippets.registerThirdPartySnippets, |
There was a problem hiding this comment.
Seemed super easy to support third-party snippets so I just decided implement it
| this.registerThirdPartySnippets = | ||
| this.registerThirdPartySnippets.bind(this); | ||
|
|
||
| const timer = setInterval( |
There was a problem hiding this comment.
Note that we just poll the user snippet dir, but we check modification times and don't do anything if nothing has changed
| @@ -0,0 +1,15 @@ | |||
| import Actions from "../actions"; | |||
There was a problem hiding this comment.
We use factories now so that we can add the extension context, which is not a class
Closes #21
cursorless.wrappers.scopeTypesfor settingsthatmark