microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.45k stars 28.62k forks source link

Creating Code Snippet is unfriendly #224900

Open maxime4000 opened 1 month ago

maxime4000 commented 1 month ago

So I've been trying to build snippet for my workflow and it's been a nightmare to write working snippets! This is integral part of VSCode and little to no help is the Editor helping it's user to build reliable and working snippet...

All I want to do is to transform this RELATIVE_FILEPATH from "src\Properties\gameState\Something.cs" to "Game.Properties.GameState" and I just don't understand how the EBNF syntax work or how to build a ".code-snippets" file accordingly.

Suggestion :

Creating code snippets is painful because there is a lack of strong examples through the documentation. Syntax highlighting is not great at all and invalid snippet are not easy to debug and find what is wrong in it.

I fully think this feature would benefits from a mix of thoses solutions :

  1. More example using fancy transform and regex in this documentation page : https://code.visualstudio.com/docs/editor/userdefinedsnippets#_grammar
  2. Having visual cue, good syntax highlight or just good intellisense in ".code-snippets" files? I mean how can I build my snippets if the only way to test it is to open a file and run it and see that the whole snippets is pasted directly in the file because the snippets is wrong?
    1. Having something like "Debuggex" (and the many other "Regex helper site" do), but for snippets would be awesome!
  3. Creation of a "Settings" page but for snippets. Each Snippet has it's own entry where you see the whole snippet text on the left and the "Generated output" on the right with the option to define a file path for testing ?

Opinion

To be honest, this feature is powerful yet so unfriendly to use... Could this part be improve so user can create snippets that answer to their workflow in a friendlier way?

Fun fact

In the past, I've written some snippet using fancier transform than the one I'm asking for and it did work like I wanted! And yet, I'm not able to rewrite it back now... I guess it was luck that I've succeed to write those snippets... Seriously, it's not normal that I can't rewrite simple snippet but can write complex Find and Replace Regex that work through the whole codebase...

sebastianvitterso commented 3 weeks ago

Ever since I started using vscode, I wondered why JSON was chosen as the file format for snippets. It's not flexible at all for this use-case.

I have a snippet called "Vue scaffold", which gives me a basic vue file. The snippet file for it looks like this:

{
  "Vue scaffold": {
    "description": "Vue scaffold",
    "prefix": "vue scaffold",
    "body": [
      "<template>",
      "  <div></div>",
      "</template>",
      "",
      "<script setup lang=\"ts\">",
      "</script>",
      "",
      "<style></style>"
    ],
  }
}

Notice how the snippet itself is located within "'s, inside an array?

Markdown with frontmatter would be better, in my opinion. This would even allow us to get syntax highlighting in our editors.

–––
description: Vue Scaffold
prefix: vue scaffold
–––
```vue
<template>
  <div></div>
</template>

<script setup lang="ts">
</script>

<style></style>
vs-code-engineering[bot] commented 3 weeks ago

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

maxime4000 commented 2 weeks ago

I'm curious about this, but how does the upvote process work? I mean, as a user of this IDE, I come here to report issues or to ask for features that are not currently in the IDE. When the upvote process happen, I try to publicized my feature request to colleagues and friends. But as a general user of VSCode, I don't look for issues that are candidate to the backlog.

Tbh, I don't follow those upvote process of my own, but that's because I don't know where they appear? Where do you look to see which issues should be prioritized? I would love to upvote some feature request that I see a potential in adding it, but Visibility is the main issue to me.

What if user could opt-in to see all Backlog Candidate through the Welcome page of the IDE? When the 60 days has pass, it stop being displayed in the list. Clicking an item would open to the Github issue url. Which each user could upvote using their Github account.

How could backlog candidate being more publicized to the users of VSCode?