How to know which extension provides what snippets in VSCode - visual-studio-code

I've installed many code snippet extensions in my Visual Stuidio Code, but when I considered to use them, I got several snippets choices with a same input. I cannot tell which one should I use.
Now I have to disable some extensions. How can I find out what extensions that each snippet is provided by? or what snippets an extension is providing?

Select a code snippet, and the extension name is showed in the hint window near the auto completing window.

Related

Where do code snippets reside in Visual Studio Code?

The only C/C++ extension I have is the official one from Microsoft. I do not have any other snippet/intellisense/autocompletion extension.
See below all the extensions loaded:
In trying to create shortcut keys/prefixes for my snippets, I would like to make sure that it does not clash with any pre-existing shortcuts/prefixes for other snippets. Is there a way to know / look through all currently available code snippets in VSCode and their shortcut keys/prefixes?
I tried to Insert Snippet via the command pallette in the hope that it would reveal all available snippets. Unfortunately, it does not list all snippets. See, for instance, below image, where this command pallette does not show the existence of a for snippet and yet inside the editor, when I type for, there is an option to add such a snippet.
I obtained confirmation officially from vscode-cpptools folks that C/C++ snippets are only available via Ctrl-Space autocomplete and not via Ctrl-Shift-P Command Pallette.
See link to their answer here.

Visual Studio Code Autocomplete Add Parentheses After Method in .js File

When I type console.lo in a .js file in Visual Studio Code, I can hit Enter, and autocomplete will change my line to console.log. However, I would also like autocomplete to add parentheses. This question was already asked using the Go programming language. I tried adding js.useCodeSnippetsOnFunctionSuggest as well as javascript.useCodeSnippetsOnFunctionSuggest. Neither of these work. I also tried useCodeSnippetsOnMethodSuggest as suggested here, but that didn't work either. What am I doing wrong?
I fixed this by searching for "Complete Function Calls" in VS Code's settings, and checking JavaScript > Suggest: Complete Function Calls. Thanks Mark for the suggestion.

Remove duplicated Intellisense suggestions

I'm writing extension that provides CompletionItems to VSCode CSS Intellisense. The issue is that some completions are already being provided to Intellisense by internal VSCode completion providers resulting in showing same complitions twice.
What I need is to remove those duplications. How can I achieve this without messing with css language-server?
VS Code shows suggestions from all extensions that provide suggestions. It is not possible for your extension to disable the suggestions from another extension: https://github.com/Microsoft/vscode/issues/63004
You could try:
Tell users to disable the built-in css extension.
Have your extension register a new language and a new completion provider for that language.

VS Code - Text formatting in a new language extension

I'm building an extension providing a syntax highlighting for the 'Jack' language used in an online course I am taking (Nand2Tetris at Coursera - it is not a part of the course assignment). I have the syntax highlighting rules ready, but I would like to add custom formatting for some language elements. In particular, I would like type definitions to appear in italic.
I know how to change the user settings to get the desired result on my VS Code installation, but I would like that formatting to be the default behavior for anyone using the extension.
I've tried to create a new theme extension and then copy paste the 'themes' folder from it to the 'syntax' extension and reference the file from that folder in package.json, but it didn't work. I also tried adding the 'configuration' setting in the 'contributes' section of package.json, without success. I browsed numerous VC Code extensions on GitHub and couldn't find one providing similar functionality.
Is it even possible to provide syntax definition and 'theming' in one extension? If so how?
Based on VS Code Semantic Highlight Guide, besides syntax highlighting rules, you'll also need
Implement and register a Semantic token provider in your extension.
Declare Enablement of semantic highlighting in settings.json.
Customize tokens in Theming.
VS Code team kindly provides a Semantic tokens sample. Note that this example skips step 3 and customizes tokens directly in settings.json.

How to edit existing VS Code Snippets

Is there a way to remove or edit some of the default code snippets in Visual Studio CODE ?
For example when i type req+TAB i need require not requestAnimationFrame
The extensions snippets can be found inside each snippet directory below:
(if there are snippets in the extension)
Mac/Linux: $HOME/.vscode/extensions/
Windows: %USERPROFILE%\.vscode\extensions/
Select the extension you want to modify and then dive into the javascript.json file in snippets/ directory in there, and change whatever you like.
Just remember that if/when you choose to download and update the extension someday, all your personal modifications will get overwritten/replaced out with the updated version of the file.
(unless of course you squirrel away your changes outside of the extension's directory...)
Edit/Aside:
Looking closely at all the copied editions already present in this directory, it appears that at least some of the extension updates keep the former version around. If this is the case, when you update an extension when a new version is released, you wouldn't need to worry about storing a copy of your modified file somewhere else; returning a file to active duty might just be as easy as a copy-paste from the old into the appropriate, newer, higher numbered directory.
Resources/citations/acknowledgements:
Thanks to here for helping initially pointing me towards the relevant directory.
The suggestion item requestAnimationFrame is coming from the JavaScript language service. It's not coming from the snippets.
However, you can define your own snippets and tell Visual Studio Code to show the snippets first. How to do it:
Go to File -> Preferences -> User Snippets and select JavaScript in order to edit snippets for that language
Add this entry to the opened file javascript.json and save it
"require": {
"prefix": "req",
"body": [
"require"
],
"description": "Add 'require'"
}
Add the following line to your preferred settings.json (user or workspace settings) and save it
"editor.snippetSuggestions": "top"
Now you get your self defined require suggestion in first place as soon as you type req in a .js file.
On my Windows10 machine the log and other default javascript snippets can be found in :
C:\Users\$USER\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\javascript\snippets\javascript.json
On my Windows installation the default/built-in JavaScript snippets are located in
C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\javascript\snippets\javascript.json
I renamed that snippet to "logx" (requires admin privileges to modify the file) and restarted vsCode and now have just my user "log" snippet.
There are some threads about this on the issue tracker -
https://github.com/Microsoft/vscode/issues/10565
https://github.com/Microsoft/vscode/issues/48315
Attention everyone!
This is now possible in the latest vscode. Solution here: https://github.com/microsoft/vscode/issues/10565#issuecomment-721832613
That solution tells you how to disable any snippet (including built-in or extension snippets). While this is technically not editing the snippet, disabling the snippet and then creating your own user snippet accomplishes the same exact goal. Yay!
I found mine at ~/.config/Code/User/snippets
If you want to create a global snippet, create a file named snippet_name.code-snippets
If you want a language specific snippet, create it like php.json
Hiding default VSCode snippets is easy:
you can hide specific snippets from showing in IntelliSense (completion list) by selecting the Hide from IntelliSense button to the right of snippet items in the Insert Snippet command dropdown.
https://code.visualstudio.com/docs/editor/userdefinedsnippets#_can-i-remove-snippets-from-intellisense