How to find out which extension provided the command in vscode? - visual-studio-code

I'm clueless what feature came out of which extension, is there a way to have its source displayed?
Also would be interesteed to know if its possible to trace the source code of the features.

The only thing I can think of is checking the package.json files, as even vscode.commands.getCommands() only returns plain strings. This can be done with the vscode.extensions API:
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
setTimeout(() => {
for (const extension of vscode.extensions.all) {
let commands = extension.packageJSON.contributes?.commands;
if (!Array.isArray(commands)) {
continue;
}
for (const command of commands) {
console.log(command.title + " is from " + extension.id);
}
}
}, 2000);
}
Note that all only includes activated extensions, hence the timeout to make sure all extensions that activate on startup are done with their activation.

what feature came out of which extension
Yes, you can do this, taking advantage of VSC's intellisense:
I'm Assuming (1) by feature, you mean a command executable from the command pallette and
Open keybindings.json in vscode
You should see JSON like below; if not, add one like below (you're not going to keep it).
{
"key": ".",
"command": "REPLACE THIS WITH YOUR COMMAND NAME",
"when": "suggestWidgetVisible"
}
Where it says "REPLACE THIS WITH YOUR COMMAND NAME", begin typing the name of the command you're interested in
The VSC suggestion widget will open, showing roughly EXTENSION_NAME.YOUR_COMMAND. If the suggest widget doesn't open, press ctrl+space to open it.
Note the name of the extension; that's what contributed that feature/command. If the name doesn't match an extension, it's probably a core VSC feature
trace the source code of the features
Most extensions are on GitHub, as is the core code for VSC, so you can simply navigate to the relevant repository and seacrch the code for that command.

Check this link out from VS Code documentation.
Here you can see where the extensions are installed by default.
And further, you can access their source code.
Where are extensions installed?
Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder:
Windows %USERPROFILE%\.vscode\extensions
macOS ~/.vscode/extensions
Linux ~/.vscode/extensions
You can change the location by launching VS Code with the --extensions-dir command-line option
About which feature cames from which extension, I'm not sure if it's possible to achive that.

Click on an extension and in the editor that opens showing its readme, click on the Feature Contributions link and you'll see the settings and commands that extension contributes. For example:

Related

How to run a Visual Studio Code extension?

I just installed the Visual Studio Code (v1.52.1) extension "Spelling Checker."
Now how do I use the thing?
I searched all the menus for a command to run this extension, or any extension. I asked Google "how to run a VSC extension" and only got matches that tell me how to install an extension. Apparently extensions are just supposed to run themselves.
There's a whole class of extensions for which that makes sense, such as extensions that add enhancements to editor windows. But there's another whole class of extensions, like this one, for which it makes no sense at all.
How do you run an extension?
This is confusing as the answer is spelled out in five-minute videos or is skirted around.
On your keyboard: Cmd+Shift+P (macOS) Ctrl+Shift+P (Windows, Linux, etc.) or under "View" and "Command Palette" opens the Command Palette so you can execute an extension's command such as "Browse Lite" for say https://github.com/antfu/vscode-browse-lite - hopefully, the developers say what the command is.
Note: Cmd+P (macOS) or Ctrl+P will search files by name. The shift is what's needed to launch the extension magic.
Open Visual studio code.
Go to extension option.
Then click on any extension.
After that disconnect your internet.
Then it will prompt for install extension manually.
Then it will ask to locate that .vsc file.
Select that and file and install it.

Add a custom command in Visual Studio Code Command Palette

Is it possible out of the box or using extensions to add a custom command in the Command Palette in Visual Studio Code like "External Tools" as in the IDE from JetBrains or in Visual Studio?
I would like to be able to run custom bash/cmd command directly from the Command Palette.
You can either use VS Code built-in functionality using shortcuts. Just add to keybindings.json:
{
"key": "cmd+shift+R",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "clear; rails server\u000D"
}
},
Or you can take a look at this extension: Command Runner
https://marketplace.visualstudio.com/items?itemName=usernamehw.commands
This extension can run it from custom Quick Pick (like command palette, but shows only your items). Command id is commands.openAsQuickPick
There's no api to seamlessly add commands to Command Palette #1422, but it's possible to modify package.json what that extension does when this setting is enabled:
"commands.populateCommandPalette": true,
With this setting it will not update Command Palette until the editor is reloaded. It might be an ok experience if you don't do that very often.
You can use multiCommand Extention to build your custom commands, which you can access through the Command Palette. Ctrl+Shift+P > Multi command > custom command.
I know it's not ideal, but I guess you can open multi command with a key binding and then it's almost what you want. Plus the feature that you can execute multiple commands with this extension.
This guy wrote something where you can customize the toolbar. https://github.com/AdamAnandUS/AdamsTool
Maybe add to it with a new StatusBarItem that registers a command you want to run.
https://code.visualstudio.com/docs/extensionAPI/vscode-api#commands.registerCommand
There are also many VS Code Extensions that might do what you want already. https://stackify.com/top-visual-studio-code-extensions/
Go to tools, External tools in visual Studio. Click Add, name the new command then you can point to a batch file command using the browse ellipses. When you save it, you will then see the new menu item under tools.

VS Code highlight modified lines

I am unable to find a setting to enable modified/changed/new lines highlight in editor. Like on this screenshot from the video about angular2 by google.
How to enable modified line hilight?
This is connected with your file being under revision control. If you have your files in git and open the folder in VS Code. You will see the colors depending on the change you've made.
Check section about Gutter indicators.
I had the same problem try launching vscode in terminal like: code your-project-dictionary.
If code command cannot be found, enable code in shell:
Open VSCode press CMD+Shift+P. A dialog will be shown: Type in "shell" and click on Shell Command: Install 'code' command in PATH. Now you can launch VSCode in terminal. This solved my issue with highlighting changed files on VSC Project Structure!
I had the same issue and turns out that for me it was a bug in git client. Reinstalling git resolved the problem with changes highlighting. Ensure that you are using latest git client. Then reopen VSCode, reopen project/folder.
It seems you should open with folder, rather than open just files.
open just files:
img example
open with folder:
img example
anyway, in terminal, use code xxxx(folder name) to open project, or right click the floder and choose open with vscode in context
Tip: must open the real directory, but not a link dir
if you add fold to a workspace, also must add a real direcotory
{
"folders": [
{
"path": "."
},
{
"path": "../src/xxx/"
},
{ # ../golang/src/test must be a real dir
"path": "../golang/src/test"
}
],

VSCode Keyboard command ids

When creating or editing the keybindings.json file v1.2.1 of Visual Studio Code requires not only the key to bind but also the 'CommandID' and 'When' condition.
I am looking for a complete list of 'CommandIDs' available to use and have been unable to find one. Where is that complete list of commands ?
Thanks
Preferences > Open Keyboard Shortcuts.
Click to edit keybindings.json for advanced customization. At the bottom of keybindings.json is a list of available commands:
// Here are other available commands:
This is mentioned (but hard to find) on the page shared by seairth.
Open command palette with Ctrl/Cmd + p and type in Open Default Keyboard Shortcuts(JSON)
then Enter or click on it
Look at Key Bindings for Visual Studio Code for the default list.
This isn't trivial, but does answer the question.
You can retrieve all commands from within a VS Code Extension. So if you create your own like this:
npm install -g yo generator-code
yo code
Then you can use the commands object like this:
let commands = await vscode.commands.getCommands()
Which does the following according to the docs:
Retrieve the list of all available commands. Commands starting with an underscore are treated as internal commands.
See Also: List of all available commands in VSCode

How to add semicolon to the end of the line in visual studio code

I press Shift+Enter, but not working, Ctrl+Enter start a new line, but not add semicolon at the end of previous line. Is there a shortcut?
Now there is an extension called Colonize:
Shift+Enter Insert semicolon at the end of line and continue on the same line
Alt+Enter Insert semicolon at the end of line and continue on the new line
Ctrl+Alt+Enter Insert semicolon and stay at the same position
Visual Studio Code doesn't appear to directly support adding a semi-colon to the end of a line via a keyboard shortcut, meaning it'll need a custom extension to support it. Fortunately, Sergii Naumov has created one for us, named (appropriately) 'Trailing Semicolon'.
To install this extension:
Launch Visual Studio Code
Press "Ctrl+P" (or "Command+P" on the Mac)
type "ext install Trailing Semicolon" to search for the extension
With the extension visible below the search box, click the Install Extension icon in the bottom right of the extension. (It's a cloud with an arrow pointing down...)
You will need to restart Visual Studio Code to enable the extension (Visual Studio Code should prompt you to restart once the extension has been successfully downloaded.)
According to Sergii, the default keybinding for the extension is "cmd+;". On my Mac, this meant pressing "Command+;", which worked great.
On my Windows 10 PC, I tried several key combinations ("Window+;" "Ctrl+;" "Alt+;" etc.), and nothing worked. I opened the Keyboard Shortcut preferences (File > Preferences > Keyboard Shortcuts) and searched for the new extension. I found it listed at the end of the keybindings:
{ "key": "win+;", "command": "extension.trailing-semicolon",
"when": "editorTextFocus" }
The "win" key binding apparently doesn't work. I copied this binding to the keybindings.json file, changed "win+;" to "ctrl+;" and it worked like a charm!
Hope that helps.
I wrote an extension to mimic IntelliJ's complete statement.
Pressing ctrl+; (cmd+; on mac) appends ; to the line end,
and moves cursor to line end.
If the line already ends with ;, pressing ctrl+; just moves cursor to line end.
There is also experimental support for complete structures like class, interface, function, if, switch, for, and while. (Not understanding semantic of languages, so it may not work as you expected.)
You can install it as VSIX at GitHub.
The version vscode marketplace is outdated. (Unfortunately my M$ account has been suspended, thus I cannot update it.)
There is no way to do it by default that I could find. I just had to make do as best I could.
I ended up adding a binding via File>Preferences>Keyboard Shortcuts, and then pressing ; after the shortcut. Having the semicolon is part of the binding is as close as I could get... at least my finger is already over that key
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+;",
"command": "cursorEnd",
"when": "editorTextFocus"
}
]
This simply means that Ctrl+; brings you to the end of the line, and then tap ; again.
Update (May 2021)
Started using VSCode Vim keybindings extension a few months ago. Highly recommend it. Out of interest, semi-colon end of the line is A; with vim keys⌨️
at 2021
settings >search for colon
You will find a javascript option to insert the semi-colon.
Try install the following ext then use shortcut: Ctr+; (Cmd+;)
There is a way to have semicolon appended automatically by VSCode.
By default this property is disabled:
For Windows ctrl + ,
For Mac cmd + ,
Settings -> in Search bar type: 'semicolon' -> change values to 'insert' for both JS and TS, save and close.
Now every time on save, VSCode will look for missing semicolons inside the file you're in and append them.
I just started using Visual Studio Code and felt this requirement myself yesterday. After a quick google search I found this nice extension called "Prettier". Being a little new to VSCode it took me a few hours to get it all setup but it works like a charm now. Here are the steps and my setup. I hope it helps others.
My coding environment: VSCode running on a Windows 10 desktop environment connecting to my codebase SMB share hosted on my development machine which is running Ubuntu server 18.04.
Solution Steps
Install node on the Windows desktop
Run, npm install -g prettier
Install the Prettier extension in VSCode
Edit the settings.json file for VSCode and add the following
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
// Set the default
"editor.formatOnSave": true
Add the .prettierrc file at the root of my codebase on the ubuntu host (e.g.: /var/www/html/tutorials) with the following basic styling configuration
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80
}
Restart VSCode and open the code file
Use the existing VSCode keyboard shortcuts to apply formatting to the entire file (Ctrl+K Ctrl+F) or to a selection (Shift+Alt+F)
Or simply saving the file Ctrl+S adds the formatting while saving the file with no additional work required
Viola!
(March 2022) Missing semi colons can be added automatically without the needing of an extension (*with a little catch ;) They are added every time your code is formatted.
Go to settings: Look for this settings if you are writing javascript:
And/or go to settings: Look for this settings if you are writing typescript:
Go to settings: Look for this settings if you are writing javascript:
Format your code and semi colons will be added \o/ Yeah
*The catch: As the settings says: Your workspace needs to have typescript 3.7 or newer.
I know this is a really old post but Prettier - code formatter for vs code adds the semi colon (amongst other formatting).
ext install esbenp.prettier-vscode
If you need semicolons on Javascript/Typescript using vscode do:
Settings
type "semicolon"
you will have options for Javascript & Tyepscript
select the "insert" option as desired
You can also select semicolons for css, less, or scss
/*******/
You can select the "Show matching extensions" and get some extra help with extensions that address the same issue.
Go to settings: Look for this settings if you are writing javascript: enter image description here
And/or go to settings: Look for this settings if you are writing typescript: enter image description hereGo to settings: Look for this settings if you are writing javascript:
Format your code and semi colons will be added \o/ Yeah
*The catch: As the settings says: Your workspace needs to have typescript 3.7 or newer.
This solution works for me
Add the following configuration in settings.json:
"css.completion.completePropertyWithSemicolon": true
or you can cancel by:
"css.completion.completePropertyWithSemicolon": false
other
"scss.completion.completePropertyWithSemicolon": true,
"less.completion.completePropertyWithSemicolon": true
Add semicolon to the end of the line and go to the next line
Shortcode: ctrl+;
Install plugin: multicomando
ext install ryuta46.multi-command
Edit file: keybindings.json
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+;",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"cursorEnd",
{ "command": "type", "args": { "text": ";" } },
"lineBreakInsert",
"cursorDown"
]
},
"when": "editorTextFocus"
}
]
This plugin promotes a sequence of commands. Infinite possibilities!
I hope it helps someone!
You can try Semicolon Insertion Shortcut.
It's in Visual Studio's Preferences. Solution from sbi's answer here:
Go to Tools/Options/Environment/Keyboard.
Switch the "Use new shortcut in:" dropdown to "Text Editor".
Pick the Edit.BreakLine command.
In the Press shortcut keys edit pane press Shift+Enter.
Worked for me!
Ctrl+Shift+P and open Preferences:Open keyboard shortcuts (JSON) in VS Code
and insert
{
"key": "tab",
"command":"cursorEnd",
"when":"editorTextFocus"
}
tab is optional, ofc.
Put whatever you want from the keys on the keyboard.