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

[snippets] Cannot override/disable snippets defined in extensions #10565

Closed
ramya-rao-a opened this issue Aug 16, 2016 · 91 comments · Fixed by #109916
Closed

[snippets] Cannot override/disable snippets defined in extensions #10565

ramya-rao-a opened this issue Aug 16, 2016 · 91 comments · Fixed by #109916
Assignees
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes snippets verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@ramya-rao-a
Copy link
Contributor

One of the Go Extension users talks about the ability to override/disable the snippets defined in the Go extension.
vscode-go/#385

This applies to all extensions that define snippets and so adding this issue as a feature request

@alexdima alexdima added feature-request Request for new features or functionality api labels Aug 16, 2016
@alexdima alexdima added this to the Backlog milestone Aug 16, 2016
@zertosh
Copy link

zertosh commented Aug 24, 2016

I was just wondering this too. Seems like you can't turn off languages at all. I want to disable javascript snippets, and the language features (like suggestions, hover, etc.) from typescript, so I can run my own language service for javascript. I'd still want to keep the syntax though.

@aeschli
Copy link
Contributor

aeschli commented Aug 29, 2016

IMO the best is if snippets are contributed by separate external extensions, so it's possible to uninstall them.
Note that if you don't like snippets at all you can disable them in code assist with
"editor.snippetSuggestions": "none"

@aeschli aeschli changed the title Cannot override/disable snippets defined in extensions [snippets] Cannot override/disable snippets defined in extensions Aug 29, 2016
@Davilink
Copy link

Sometimes you don't want to shutdown all snippet suggestion, but just override some of them, like the "cw" for C#. the default will write « System.Console.WriteLine(""); », i would like « Console.WriteLine("") », i perfectly know the the first one will work with a charm, but i just LIKE the second syntax, but when i add a snippet it's show 2 suggestion with the same prefix and that is confusing. We know, we are picky, but we like to have to possibilities to custom our editor at our taste.

@gluons
Copy link

gluons commented Feb 16, 2017

I'm using JavaScript snippets extension and I always see 2 if snippet, 2 for, and more....
I can't type prefix and press enter immediately. I have to move arrow key to find snippets.
That really annoy me. 😔

@JohnWeisz
Copy link

JohnWeisz commented Mar 20, 2017

Also, some snippets just make no sense at all. For example, the for snippet in TypeScript creates this:

for (var index = 0; index < array.length; index++) {
    var element = array[index];
    
}

I... I don't even...

  1. Why would I use a for loop to iterate an array in the first place? (unless I'm iterating MB-sized arrays in a worker)
  2. Why does the snippet assume I would ever user var for block-scoped variables?
  3. (And who uses index as a loop counter variable name for a simple iteration?)

I support the above request. Please, either make built-in snippets overridable, or nuke them, and let users create their own, without having to put up with the additional noise.

@nakamorichi
Copy link

Although currently it seems disabling particular snippets is not possible, it is possible to put your custom snippets first in the list in order to avoid skimming through the snippet menu. Just name your snippet so that the sorting algorithm puts it before the unwanted snippets (such a 1-<name of your snippet>).

@ramya-rao-a
Copy link
Contributor Author

Like @Kitanotori mentioned most of the scenarios listed here will be solved with the user defined snippets being sorted above the built-in snippets and the ones from extensions.

So if you don't like the for snippet, create your own, and that would be sorted before the other for snippet.
The label for the snippets will include both the name of the snippet and the prefix, making it easy to know which one is yours and which is from built-in or from the extension.

screen shot 2017-05-03 at 6 35 48 pm

There is another scenario where this does not help. Say you have 5 javascript related extensions and all of them have the for snippet. Now your suggestion list just bloats up.

So it is still valuable to have a way to disable snippets not only built-in but also from extensions. We need to be able to provide the extension id and the snippet prefix and ask to disable it.

@ramya-rao-a
Copy link
Contributor Author

My proposal would be to add a new field while snippet creation

    "For Loop":{
         "prefix": "for",
         "body": "",
         "disableFromExtension": "typescript"
     }

When snippets are registered in https://github.com/Microsoft/vscode/blob/1.11.2/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts#L58 we can maintain a separate map of languageId -> snippets-to-disable

And they can be filtered out in https://github.com/Microsoft/vscode/blob/1.11.2/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts#L65

@jrieken Thoughts?

@nakamorichi
Copy link

Just noticed that identifiers (e.g. import { log } from '...') have preference over snippets, so in such case it seems to be impossible to have custom snippets come first.

@MilyMilo
Copy link

MilyMilo commented Jul 3, 2017

Also, it would be great to be able to disable keywords suggestions. It basically blocks snippets because we have to use arrow down instead of just hitting enter.
img

@amackintosh
Copy link

amackintosh commented Jul 23, 2017

This is incredibly annoying especially coming from Atom Editor.

I think we should be able to disable them from the snippet menu, such as a 'hide' option so you can just clean the snippet menu as it gets bad items in it. In the post above mine, imagine the 'hide' option appearing along the right side of the menu for each item.

I think this would be the most efficient and noob-user friendly solution, that would make it very intuitive to discover and clean up.

I also find it comical how you cannot set user defined snippets as the default (but, I wouldn't care about if I could simply disable them from the snippet menu).

While I am mentioning, I also find it annoying how I have to press tab twice to access the snippet. There comes a point where typing at 100WPM, its literally faster to just type it out rather than performing what is essentially some "cryptic video game cheat code input" to use a time saving device.

@ramya-rao-a
Copy link
Contributor Author

@amackintosh What's the "tab twice" scenario you mentioned?

@amackintosh
Copy link

amackintosh commented Jul 23, 2017

I added a user snippet for "log", and then after in the code: when I type "log", it displays the snippet menu, then I press tab and nothing happens, then I press tab again and it puts in <log> </log>.

I am used to Atom, using which I type "log" and then press tab and it puts console.log().

To confirm my gripe, I cannot find a way to achieve this in VSCode without doing:
type "log", press down-arrow key, press tab

I was able however, to change the name of my snippet to "1Console Log" and now it sometimes displays as the first and/or only snippet entry for "log". I haven't been able to figure out the logic yet. Sometimes it displays two logs (at which time I need to press tab twice), and other times it works as intended without having to press tab twice.

@ramya-rao-a
Copy link
Contributor Author

@amackintosh

it displays the snippet menu

Do you mean the suggestion/auto completion list?

screen shot 2017-07-23 at 9 41 48 pm

When no suggestion list is present, log followed by tab expanding to <log></log> is due to emmet which gets triggered on tab. You can avoid that by setting emmet.triggerExpansionOnTab to false.
We are moving away from this model of tab being tied to emmet, that will be out in the next update.

When you end up pressing tab twice do you get the snippet you configured or you get ?

@gluons
Copy link

gluons commented Jul 24, 2017

@amackintosh "editor.snippetSuggestions": "top" may help you to get rid of arrowing down. 🙂

I'm using it now while waiting for this issue to be resolved.

@amackintosh
Copy link

amackintosh commented Jul 29, 2017

I get that snippet when I press tab twice. (also, yes I mean't suggestion/auto completion list)

Thanks @gluons, that solved my issue 100%.

Keep up the good work everyone.

@jiayihu
Copy link

jiayihu commented Aug 2, 2017

Related: for some reason, in .tsx (Typescript React) files the built-in import snippet expands to import $2 = require('$1') instead of import { $2 } from '$1'. The possibility to change default snippets would allow me to override the former behaviour.

@aristotele
Copy link

aristotele commented Aug 18, 2017

I've tried to edit built-in snippets code, use notepad++ in admin mode and it will work.

@ioquatix
Copy link
Contributor

ioquatix commented May 2, 2020

I found the snippet and added:

'.ruby.source':
  'Add ‘# =>’ Marker':
    'prefix': '#'

to my ~/.atom/snippets.cson and it stopped the snippet from firing.

@ghost
Copy link

ghost commented Jul 16, 2020

All I want is,

  • Snippet has an option to hide
  • There will be three dots in suggestion window to control to hide or not.

So I can choose good one left, bad one hidden.

@VijayaKatikireddy
Copy link

This will be a great feature, and helps avoid overloading.

@antonmyrberg
Copy link

The plugin wasn't was I was looking for, I didn't want to disable all snippets for a lang, just overwrite the existing one.

What I ended up with was just prefixing all my snippets like >ue and >us (useEffect and useState).
Never collides with the built-ins, but I would really prefer to be able to declare snippets like @ramya-rao-a suggested using "disableFromExtension": "typescript" or similar.

@siimsepp
Copy link

siimsepp commented Oct 3, 2020

I had the same problem of annoying default snippets. I found a file named javascript.code-snippets there:
C:\Users<USERNAME>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\javascript\snippets
After removing it and restarting VS Code I see only my own snippets. If you only want to remove some default snippets then you can edit that file. Simply cut out annoying for-loop snippet and only that one is gone. This may be a temporary fix until the next update but it is easy to repeat if you keep your own version of the file and replace the default one with it after the update.

@connesy
Copy link

connesy commented Oct 3, 2020

On linux, the default code snippets can be found in /usr/share/code/resources/app/extensions/[language]/snippets/[language].code-snippets, so for JavaScript that would be /usr/share/code/resources/app/extensions/javascript/snippets/javascript.code-snippets.
As with siimsepp's answer, these changes take effect after restarting VSCode.

@PabloLION
Copy link

these are nice workarounds but not the ultimate solution.

@ghost
Copy link

ghost commented Oct 10, 2020

This issue has been open since 2016, seriously, my favovurite editor? All of the options are just work arounds, I really do hope that someone does something about this. 😞

@bakape
Copy link

bakape commented Oct 10, 2020 via email

@ghost
Copy link

ghost commented Oct 11, 2020

I know it's pretty easy but hey, it wouldn't be too hard to directly implement it.

@AllanDaemon
Copy link

There is a major extension that provides a snippet with the prefix ., so every time I use a . it changes to self..

This is so bad that many times I wast more time undoing this than doing the task I supposed to. The fact that I can't type . is pretty annoying and this has 4 years is frustrating.

@jrieken
Copy link
Member

jrieken commented Nov 4, 2020

This will happen for 1.52 and works like so:

  • Select F1 > Insert Snippet
  • find an extension snippet that you want to hide
  • select the eye-icon to hide/show it in IntelliSense

Note that hidden snippets are synced across devices when using setting-sync, so this needs to be done only once per extension snippet.

Nov-04-2020 17-21-42

@danielo515
Copy link

@jrieken does that also apply to built in extensions? Those are the ones that I find more annoying (all those old-style snippets like for loops, selfs, this, etc)

@jrieken
Copy link
Member

jrieken commented Nov 5, 2020

@danielo515 Yes - it will apply to all snippets from extensions - builtin or user-extensions.

This will be in next 1.52 insiders: https://code.visualstudio.com/insiders/

@jrieken
Copy link
Member

jrieken commented Nov 30, 2020

To verify

  • make sure that you can hide/show extension snippets, not user nor workspace snippets, via "F1 > Insert Snippet"
  • make sure that hidden snippets do not show in IntelliSense
  • make sure that hidden snippets still show in "F1 > Insert Snippet"

@sandy081 sandy081 added the verified Verification succeeded label Dec 3, 2020
@jrieken jrieken added the on-release-notes Issue/pull request mentioned in release notes label Dec 4, 2020
@ghost
Copy link

ghost commented Dec 18, 2020 via email

@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes snippets verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.