How to get the current context in VSCode? - plugins

I am developing the VSCode plugin. Some VSCode command requires specific context to be executed. In the keyboard shortcuts, each command has a when clause context. (see official doc [here] https://code.visualstudio.com/api/references/when-clause-contexts)) I'd like to get the user current context, so that I can list all commands which satisfies the when clause context. Is there any VSCode API to do so? BTW, I am using typescript for plugin development. Thanks!
I have tried the following.
vscode.commands.executeCommand("getContextKeyInfo");
But I did not get any useful return info.

Related

How to LIST all occurrences of a string in VSCode?

Some text editors and IDEs have this feature that LISTS all the occurrences of a string and displays them as a list.
I have Googled this feature for VSCode, but what I got was mostly 'how to SELECT all occurrences'.
What I want is something like this (Notepad++):
One way to get this is to use the bundled ripgrep that comes with VS Code. You can find it under this path inside the folder your VS Code is installed to:
/resources/app/node_modules.asar.unpacked/#vscode/ripgrep/bin/rg
Just open a terminal pane in VS Code with a console of your choice and invoke that ripgrep executable with whatever query is appropriate for the search you want to perform.
You can read more about ripgrep and how to use it on its GitHub page: https://github.com/BurntSushi/ripgrep.

Adding the run-code option to a new language in VSCode

I'm currently writing my own language and I'm at a point where I would like to publish it to the VSCode-Marketplace so people can test it.
I have written a language extension and a syntax highlighter with the Yeoman-Generator and now want to merge it with my executable file that launches the interpreter, so that a file can get interpreted after clicking the run-code button.
I now have checked multiple articles, like:
How to add a run button in visual studio code? - StackOverflow
How to define or support a code language on Visual Studio? - StackOverflow
Debugger Extension Guide - VSCode API
However, I haven't found anything useful.
Currently, the code-runner displays the following error, when clicking on run, or pressing the shortcut:
(Code language not supported or defined.)
But even after a lot of browsing Google for adding new language support to the code-runner, I found absolutely nothing helpful.
(See this page, idk what Settings/Preferences they are referring to!?)
I also was not successful with tasks, as they don't seem to connect to the run-buttom or debug-button in any way.
My question is: How can I make the run-button execute a custom bash-command, when a file in my language is opened?
Okay, I finally did it.
For anyone wondering:
You have to go to the settings and type "code-runner" into the search bar.
Scroll down a little, and you should find the code runner-executor map.
Click on the "edit in settings.json" button.
Now a .json-file should've opened. There are two possible scenarios: Either, there is a json-object called code-runner.executorMapBy... or not.
If there is none, type code-runner.executorMapByFileExtension and let autocomplete do the job.
If the json-object exists, add the file-extension and a bash command that executes your compiler/interpreter. It gets automatically executed in the directory the program-file lies in.
Now still dont know, how to include the settings in my extension, but that was already a big step. Further help is still appreciated!
There is an open source extension called code runner, you can check source code there.

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.

List of all available commands in VSCode

Where can I find the list of all commands available in VSCode and their description?
I'm only aware of these sources:
In the official docs:
This list which only seems to include a subset of Visual Studio Code commands that you might use with vscode.commands.executeCommand API (why is this only a subset of the full list?)
This other list in the keybindings doc, which also only seems to include a subset of all commands available (I suppose those tied to a default keybinding?)
In the editor itself:
I can see a list of commands when I open the "default keybindings". Many actions are commented out with //, but interestingly I don't think this includes all the commands either (e.g. maximizeOtherEditor isn't listed)
Does VSCode have an official list of commands (commandID's) either in its documentation or in its code base? If not:
What's the closest to it?
What's a good way to navigate the code base to try to find all commands and what they do?
I believe that content of "Preferences: Default Keyboard Shortcuts (JSON)" (command ID workbench.action.openDefaultKeybindingsFile) really shows comprehensive list of all native and extensions-contributed commands VSC knows about at moment when invoked.
This file shows keys from VSC's defaults and extension manifests.
Commands with no suggested defaults are those commented out at the end of file.
Their descriptions (as seen in the Command Palette, Keyboard Shortcuts settings, extension Contributions tab and elsewhere) are supposedly in localization properties and I believe there is currently no way to see them along their respective command IDs in single convenient "localized" list. So for now the only way to read the description of command found in aforementioned JSON is pasting its ID into Keyboard Shortcuts search field. (Would be delighted to be proven wrong.)
In case someone ever fell on this and just wanted a quick-list of VSCode commands to browse through: https://gist.github.com/skfarhat/4e88ef386c93b9dceb98121d9457edbf
If you do, please note the VSCode version and commit. These may well be out of date by the time you read them.

Fuzzy file opening in vscode

I am exploring vscode after using atom for a long while. One of the things I'm missing is an equivalent of the lovely package advanced-open-file. Is there something similar to this in vscode?
I found the advanced-new-file extension, but it is only helpful when it comes to new files. I would like to be able to quickly open files from all over my local files (not only the workspace).
Edit: I found the option of workbench.action.quickOpen; but it doesn't allow opening files from the whole file system.
Sorry, but currently the answer is no. The problem is that input box doesn't provide a way to listen to key events:
GitHub issue,
so even the extensions can't do that currently. Here's the comment from advanced-new-file extension creator:
Because VSCode extensions don't yet have the ability to do type-ahead autocomplete within the text input box (See https://github.com/Microsoft/vscode/issues/426), we work around this limitation and provide autocomplete using a two-step workflow of selecting existing path, then providing new filename/path relative to the selection.
The good news is that there is a new API addressing this issue, but it's currently in 'proposed' state and can't be used for published extensions.
One workaround could be typing code -r some/path in integrated terminal and using 'tab' for autocomplete.
The Fuzzy search extension seems to work for me.
It adds a new action to the command palette which allows you to search for files in the current project and open them.