Contributing vscode configurations which are activated conditionally - visual-studio-code

I am contributing some configurations to VSCode through my extension. I want some of the configurations of my extension to be enabled/disabled conditionally.
For example, I have a boolean config called "Enable Plugin Developer Mode". I want some other configs to be provided when I am in plugin developer mode and I just want to see them only if I have already enabled the plugin developer mode.
I have tried to achieve this through json schema if-then-else, but it seems not working.
"configuration":{
"type":"object",
"title":"MyExtension",
"properties":{
"myext.mode.developer.enable":{
"type":"boolean",
"default":false,
"description":"If set to true, Developer mode will be enabled"
}
},
"if":{
"properties":{
"myext.mode.developer.enable":{
"boolean":true
}
}
},
"then":{
"properties":{
"myext.runtime.path":{
"type":"string",
"default":"",
"description":"Path to runtime"
}
}
}
}

Related

Customising the application name in a vscode workspace

As directed by the VSCode github repo - I have an simple ask. Is it possible to set a human readable application name for a VSCode Workspace?
At the moment, my .code-workspace file looks like.
{
"folders": [
{
"name": "Some project",
"path": "../some-project"
}
]
}
Having a look through the Settings (File->Preferences->Settings) for the Workspace there is a plethora of settings. Curiously there is an appName environment variable - but surely there should be a way of customising this.
The title bar looks like the following with acme.app (Workspace):
Curiously the workspace filename is called acme.app.code-workspace.
I spotted window.title in settings when having a look earlier. You can customise it in the code-workspace. I am not sure whether this would be the best way. Would be nice if we could set an environment variable workspaceName or something and use that - if we needed to use elsewhere.
If you add the settings section - then add the window.title it will default the value to ${dirty}${activeEditorShort}${separator}${rootName}${separator}${appName}.
{
"folders": [
{
"name": "Some project",
"path": "../some-project"
}
]
"settings": {
"window.title": "${dirty}${activeEditorShort}${separator}${rootName}${separator}${appName}"
}
}
Here you can see the following:
dirty - displays an indicator of whether the current file has changed
activeEditorShort - the current file
separator - configured separator i.e. '-'
rootName - defaults to acme.app (Workspace)
appName - defaults to Visual Studio Code
So you could change the rootName to be the human-readable text:
"window.title": "${dirty}${activeEditorShort}${separator}MY SUPER PROJECT${separator}${appName}"
Which gives us:

Yaml Support for Kubernetes in VSCode

I am trying to use VS code editor for creating kubernetes yaml files, by some reason, vscode is not showing auto-complete commands or space in my yaml files even though I have installed Yaml Support by Redhat extension and configured yaml.schema file as per below:
{
"yaml.schemas": {
"Kubernetes": "*.yaml"
}
}
Any help would be appreciated.
Thanks
I don't know why your config does not work. Here's mine:
{
"workbench.colorTheme": "Default Light+",
"workbench.startupEditor": "none",
"editor.cursorSurroundingLines": 5,
"window.zoomLevel": 3,
"redhat.telemetry.enabled": false,
"yaml.schemas": {
"Kubernetes": [
"deploy*.yaml"
],
},
}
This snippet works for me which currently selects deploy*.yaml files.
I added rest of settings just to show overall structure. Only yaml.schemas part matters, of course.
To access this file one should press command+shift+P (macOS), and type >user settings json in the search. To reload vscode one should press command+shift+P and then type >reload window there.
I tried to match *.yaml and it works as well.
Hopefully this answer will help some vscode newbie like me. It's not very obvious how to proceed with yaml configuration after initial install.
Fix This Problem On The Vscode Step by Step
Step 1 : install yaml plugin on the vscode
Step 2 : Edit this path vscode file>prefrences>settings>Extention>YAML
Step 3 : After Click Yaml on the right side find and edit YAML: Custom Tag Edit in setings.json
Step 4 : Append This lines in File Settings.json
"https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.22.4-standalone-strict/all.json": ["/*.yaml","/*.yml"]
Step 5 : Final Reload vscode You can use Ctrl+Shift+p and search Reload Window On The Vscode
try this.
{
"yaml.schemas": {
"Kubernetes": "*.yaml"
},
"redhat.telemetry.enabled": true
}
you can try it.
"yaml.schemas": {
"http://www.schemastore.org/json/composer": ["/*"],
"kubernetes": ["/*.yaml"]
},

VSCode: settings.json file is not recognizing a terminal.integrated setting

Why is this entry not recognized by VSCode? I have a very slow terminal output that I am hoping this will help fix:
"terminal.integrated.rendererType": "experimentalWebgl"
The above command is known to exist, here: https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md
Here is my settings.json file:
{
"atomKeymap.promptV3Features": true,
"editor.formatOnPaste": true,
"editor.multiCursorModifier": "ctrlCmd",
"python.pythonPath": "C:\\Users\\Andrew\\Anaconda3",
"workbench.colorTheme": "Visual Studio Dark",
"terminal.integrated.rendererType": "experimentalWebgl", # grey'd out assuming its not a real command
"workbench.iconTheme": "Monokai Pro Icons",
"workbench.editorAssociations": {
"*.ipynb": "jupyter-notebook"
},
"python.defaultInterpreterPath": "C:\\Users\\Andrew\\Anaconda3",
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "left"
},
"debug.javascript.pickAndAttachOptions": {
},
"workbench.colorCustomizations": {
}
}
The referenced markdown documentation file is not up to date (note that it's on branch master, while current development happens on the main branch). The WebGL renderer has been made the default in v1.55 (March 2021):
As part of this work we also added some fallback logic. When "terminal.integrated.rendererType": "auto", the following happens:
The WebGL renderer will try to start up.
If it fails, for example due to lack of OS/browser support:
The canvas renderer will be enabled and the time it takes to render a frame will start to be measured.
If the first 20 frames are rendering slowly, for example if there are hardware issues or GPU rendering is disabled:
The DOM renderer will be enabled.
In the next release, we plan on removing the rendererType setting all together in favor of a much more understandable "terminal.integrated.gpuAcceleration": "auto" | "on" | "off".
See the current documentation on this for further reference.

How do I remove a custom terminal profile from Visual Studio Code?

How do I delete the custom profile "New 1" as shown in the picture?
I'm using Zsh, so I suggest configuration
"terminal.integrated.profiles.osx": {
"zsh": {
"path": "/bin/zsh",
"icon": "star",
"env": {
"TESTING_VAR": "abc"
}
}
},
"terminal.integrated.defaultProfile.osx": "zsh",
As described in the Configuring profiles section of the VS Code docs), when you create a custom terminal profile, it adds an entry to your settings.json file:
The recommended way to create a new profile is to run the Terminal: Select Default Profile command and activate the configure button on the right side of the shell to base it on. This will add a new entry to your settings that can be tweaked manually in your settings.json file.
...
"terminal.integrated.profiles.windows": {
"PowerShell -NoProfile": {
"source": "PowerShell",
"args": ["-NoProfile"]
}
},
"terminal.integrated.profiles.linux": {
"zsh (login)": {
"path": "zsh",
"args": ["-l"]
}
}
So open your User settings and you'll find the terminal.integrated.profiles.<OS> setting with an added entry for your custom profile under your corresponding OS. It is better to open the settings.json file directly, or open it from the UI "Edit settings.json":
settings UI
settings.json
"terminal.integrated.profiles.osx": {
"1": {
"path": "bash"
}
}
(I'm using a Mac OS so I have it in .osx. It gets added correspondingly to .linux or .windows)
To remove your custom profile:
Simply delete your custom profile ("1": {...}) from terminal.integrated.profiles
Reload/Restart VS Code
When VS Code reloads/restarts, the removed custom profiles should be gone. (It seems these custom profiles are read and loaded one-time during VS Code startup).
Note though that this only works for custom profiles. For built-in profiles, you'll have to set the profile to null instead:
To remove profile entries from the dropdown, set the name of the profile to null. For example, to remove the Git Bash profile on Windows, use this setting:
"terminal.integrated.profiles.windows": {
"Git Bash": null
}

Visual Studio Code Run On Save Extension not running

I installed the Run On Save extension for VS Code. I made a Workspace setting for it, and if I change a file then resave, it does not seem to run. "I run for all files" does not show up in the console or terminal.
When I chose to edit the command configuration in my Workspace settings, it automatically edited the file with the comment "Place your settings in this file to overwrite default and user settings." so it looks like this:
// Place your settings in this file to overwrite default and user settings.
{
"editor.mouseWheelZoom": false,
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
I'm new to configuring Workspace settings, so I'm not sure if this is okay or not. I ensured that Run On Save is enabled by selecting it on the command palette.
Here is the site for the extension: https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
In order to see the console output, you have to be in the Output tab and select the Run On Save option in the dropdown. The extension was created before the integrated terminal existed and hasn't seen a major update in a while.
Regarding the comment that was added to your config:
// Place your settings in this file to overwrite default and user
settings.
is unrelated to this particular extension. It is just vscode letting you know the purpose of the workspace level configuration. It allows you to override a subset of your more global user / default settings. This allows you to keep reasonable default preferences but to customize certain specific things in any given workspace.
Regarding the original RunOnSave extension, feel free to file an issue here https://github.com/emeraldwalk/vscode-runonsave/issues if you have any questions or problems. I would also welcome pull requests if anyone is interested.
I had the exact same issue. I removed that extension and am using this one instead:
https://marketplace.visualstudio.com/items?itemName=wk-j.save-and-run
It is a fork based on RunOnSave. This one works for me when I set its configuration in my user settings and then run the command "Save and Run: Enable".
This one uses the bulit-in powershell terminal.
HTH
In addition to our dear #bingles, I have accidentally discovered that the commands should be added to .vscode/settings.json file instead of .vscode/emeraldwalk.runonsave as said in the plugin documentation
Add it to settings.json and everything should work as expected.
For the extension to work on Workspace you must put the emeraldwalk.runonsave inside settings:
{
"settings": {
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
}
A related one:
Previously I used RunOnSave, this time around I used Code Runner.
Code Runner - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
Below are it's settings I used:
File: %AppData%\Code\User\keybindings.json
{
{
"key": "ctrl+s",
"command": "code-runner.run"
}
}
File: .vscode\settings.json
{
"code-runner.saveFileBeforeRun": true,
"editor.codeActionsOnSave": [
"code-runner.executorMap"
]
"code-runner.executorMap": {
"javascript": "node a.js"
},
}
If possible, you could use Code Runner with the above settings, or use a similar to the above settings for the RunOnSave.
Note that RunOnSave has its own tab which is time-consuming to switch to another tab.
With Code Runner I can see the output in the Output tab itself which is a very nice thing, saves time.