-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Properly handle snippet migration with multiple different snippets in one file and noop phrase #2838
Conversation
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.
This looks fine, but it needs a test. Are there no existing tests for snippet migrator? Seems complex enough to justify tests, and easy to write, no? Just input / output fixture and compare output to expected?
I can write a few tests. |
@pokey Tests added |
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.
Looks good. I can't decide how I feel about the way you've represented the expected outputs. I can see both sides. I would lean towards just using the final output, as we're kind of locked into that given its use by end users, so I'm not sure how much benefit we get from abstracting it away. But I can see the benefit of your representation too and I don't think it's worth the effort to change even if end output is better
Fwiw here is diff from snippet migrator on main
for my snippets:
diff --git a/core/snippets/snippets/binder.snippet b/core/snippets/snippets/binder.snippet
index 40f53803..0373dce0 100644
--- a/core/snippets/snippets/binder.snippet
+++ b/core/snippets/snippets/binder.snippet
@@ -2,6 +2,8 @@ name: bindClassFunction
description: Bind function or arg
phrase: binder
insertionScope: statement
+
+$name.wrapperPhrase: binder
---
language: typescript | javascript | typescriptreact | javascriptreact
diff --git a/core/snippets/snippets/ifElseStatement.snippet b/core/snippets/snippets/ifElseStatement.snippet
index 04acb670..b6a5c0e2 100644
--- a/core/snippets/snippets/ifElseStatement.snippet
+++ b/core/snippets/snippets/ifElseStatement.snippet
@@ -1,5 +1,8 @@
name: ifElseStatement
phrase: if else
+
+$alternative.wrapperPhrase: else
+$consequence.wrapperPhrase: if else
---
language: shellscript
diff --git a/core/snippets/snippets/ifStatement_CONFLICT.snippet b/core/snippets/snippets/ifStatement_CONFLICT.snippet
index cb3970b3..c0ff6f58 100644
--- a/core/snippets/snippets/ifStatement_CONFLICT.snippet
+++ b/core/snippets/snippets/ifStatement_CONFLICT.snippet
@@ -3,6 +3,7 @@ phrase: if
$condition.wrapperPhrase: condition
$condition.wrapperScope: statement
+$consequence.wrapperPhrase: if
---
language: typescript | typescriptreact | javascript | javascriptreact | cpp | c | java | csharp
diff --git a/core/snippets/snippets/link.snippet b/core/snippets/snippets/link.snippet
index cdc0b337..e983bf99 100644
--- a/core/snippets/snippets/link.snippet
+++ b/core/snippets/snippets/link.snippet
@@ -1,6 +1,8 @@
name: link
description: Link
phrase: link
+
+$text.wrapperPhrase: link
---
language: markdown
diff --git a/core/snippets/snippets/map.snippet b/core/snippets/snippets/map.snippet
index b8c81a34..fe113cf6 100644
--- a/core/snippets/snippets/map.snippet
+++ b/core/snippets/snippets/map.snippet
@@ -1,6 +1,8 @@
name: map
description: Map
phrase: map
+
+$value.wrapperPhrase: map
---
language: javascript | typescript | typescriptreact | javascriptreact
diff --git a/core/snippets/snippets/tryCatchStatement_CONFLICT.snippet b/core/snippets/snippets/tryCatchStatement_CONFLICT.snippet
index bb926470..499f2ac1 100644
--- a/core/snippets/snippets/tryCatchStatement_CONFLICT.snippet
+++ b/core/snippets/snippets/tryCatchStatement_CONFLICT.snippet
@@ -1,5 +1,7 @@
name: tryCatchStatement
phrase: try
+
+$body.wrapperPhrase: try
---
language: typescript | typescriptreact | javascript | javascriptreact
diff --git a/core/snippets/snippets/typescript_CONFLICT.snippet b/core/snippets/snippets/typescript_CONFLICT.snippet
index 57ea5849..b1524873 100644
--- a/core/snippets/snippets/typescript_CONFLICT.snippet
+++ b/core/snippets/snippets/typescript_CONFLICT.snippet
@@ -1,43 +1,61 @@
-name: letDeclarationWithType
-description: Let variable declaration with type
-phrase: let type
-insertionScope: statement
-
-$value.wrapperPhrase: let type
-$value.wrapperScope: statement
----
-
+name: mobxConstructor
+description: Constructor using makeAutoObservable
language: typescript | javascript | typescriptreact | javascriptreact
+insertionScope: namedFunction
-
constructor($parameters) {
makeAutoObservable(this);
}
---
+name: constantDeclaration
+description: Constant variable declaration
language: typescript | javascript | typescriptreact | javascriptreact
+phrase: con
+insertionScope: statement
$name.insertionFormatter: PRIVATE_CAMEL_CASE
+$value.wrapperPhrase: con
+$value.wrapperScope: statement
-
const $name = ${value/^([^;]*);?$/$1/};
---
+name: constantDeclarationWithType
+description: Constant variable declaration with type
language: typescript | javascript | typescriptreact | javascriptreact
+phrase: con type
+insertionScope: statement
$name.insertionFormatter: PRIVATE_CAMEL_CASE
+$value.wrapperPhrase: con type
+$value.wrapperScope: statement
-
const $name: $type = ${value/^([^;]*);?$/$1/};
---
+name: letDeclaration
+description: Let variable declaration
language: typescript | javascript | typescriptreact | javascriptreact
+phrase: let
+insertionScope: statement
$name.insertionFormatter: PRIVATE_CAMEL_CASE
+$value.wrapperPhrase: let
+$value.wrapperScope: statement
-
let $name = ${value/^([^;]*);?$/$1/};
---
+name: letDeclarationWithType
+description: Let variable declaration with type
language: typescript | javascript | typescriptreact | javascriptreact
+phrase: let type
+insertionScope: statement
$name.insertionFormatter: PRIVATE_CAMEL_CASE
+$value.wrapperPhrase: let type
+$value.wrapperScope: statement
-
let $name: $type = ${value/^([^;]*);?$/$1/};
---
data/fixtures/cursorless-snippets/multipleSnippets.cursorless-snippets
Outdated
Show resolved
Hide resolved
|
Fixes #2836
Fixes #2840
Input
Output