Skip to content

Migrate snippets support to community snippets, support multiple snippets#2804

Merged
AndreasArvidsson merged 42 commits into
mainfrom
snippetVariants
Feb 4, 2025
Merged

Migrate snippets support to community snippets, support multiple snippets#2804
AndreasArvidsson merged 42 commits into
mainfrom
snippetVariants

Conversation

@AndreasArvidsson

@AndreasArvidsson AndreasArvidsson commented Feb 1, 2025

Copy link
Copy Markdown
Member

#2353

The Cursorless side of talonhub/community#1718

Will allow Cursorless to fetch multiple snippets from community and decide which one to use.

Release notes

Cursorless can now get multiple snippets from community. One for each language. Cursorless can then pick the correct snippet for the document language regardless of which document is focused at the moment.

@AndreasArvidsson AndreasArvidsson requested a review from a team as a code owner February 1, 2025 05:23
Comment on lines +193 to +196
const metaSnippetText = serializeSnippetFile(snippetFile)
// Escape dollar signs in the snippet text so that they don't get used as
// placeholders in the meta snippet
.replace(/\$/g, "\\$")

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding

This does not escape backslash characters in the input.

Copilot Autofix

AI over 1 year ago

To fix the problem, we need to ensure that backslashes are properly escaped in the metaSnippetText string. This can be done by adding an additional replacement step to escape backslashes before escaping dollar signs and replacing the placeholder.

  1. Add a replacement step to escape backslashes using a regular expression with the g flag.
  2. Ensure that the order of replacements is correct: first escape backslashes, then escape dollar signs, and finally replace the placeholder.
Suggested changeset 1
packages/cursorless-engine/src/actions/GenerateSnippet/GenerateSnippet.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/cursorless-engine/src/actions/GenerateSnippet/GenerateSnippet.ts b/packages/cursorless-engine/src/actions/GenerateSnippet/GenerateSnippet.ts
--- a/packages/cursorless-engine/src/actions/GenerateSnippet/GenerateSnippet.ts
+++ b/packages/cursorless-engine/src/actions/GenerateSnippet/GenerateSnippet.ts
@@ -193,2 +193,4 @@
     const metaSnippetText = serializeSnippetFile(snippetFile)
+      // Escape backslashes in the snippet text
+      .replace(/\\/g, "\\\\")
       // Escape dollar signs in the snippet text so that they don't get used as
EOF
@@ -193,2 +193,4 @@
const metaSnippetText = serializeSnippetFile(snippetFile)
// Escape backslashes in the snippet text
.replace(/\\/g, "\\\\")
// Escape dollar signs in the snippet text so that they don't get used as
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread data/fixtures/recorded/actions/snippets/snipIf.yml
Comment thread data/fixtures/recorded/actions/snippets/snipCode.yml
@phillco phillco changed the title Supports getting multiple snippet variants from community Migrate snippets support to community snippets, support multiple snippets Feb 4, 2025
Comment thread cursorless-talon/src/snippets.py Outdated
Comment thread cursorless-talon/src/snippets.py Outdated
Comment thread cursorless-talon/src/snippets.py Outdated
Comment thread data/fixtures/recorded/actions/snippets/snipFunkToThis.yml
Comment thread data/fixtures/recorded/actions/snippets/tryWrapThis.yml
@AndreasArvidsson AndreasArvidsson added this pull request to the merge queue Feb 4, 2025
Merged via the queue into main with commit e4fe5b8 Feb 4, 2025
@AndreasArvidsson AndreasArvidsson deleted the snippetVariants branch February 4, 2025 20:21
cursorless-bot pushed a commit that referenced this pull request Feb 4, 2025
…pets (#2804)

#2353

The Cursorless side of talonhub/community#1718

Will allow Cursorless to fetch multiple snippets from community and
decide which one to use.

## Release notes
Cursorless can now get multiple snippets from community. One for each
language. Cursorless can then pick the correct snippet for the document
language regardless of which document is focused at the moment.

---------

Co-authored-by: Phillip Cohen <phillip@phillip.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants