I am creating a vscode extension which has some custom settings. I have defined the settings in package.json like so:
{
"contributes": {
"configuration":[
{
"title": "Extension",
"properties": {
"Codegenx."A Float": {
"type": "number",
"default": 1.0,
"description": "A sample decimal number"
}
}
}
]
}
}
How can I access these setings in my main extension? And also make sure that I get the updated value if the user changes the settings through the settings.json file or through the VsCode UI?
Related
You can configure a vs-code multi-root workspace to include several folders. Eg,
{
"folders": [
{
// Source code
"name": "Product",
"path": "vscode"
},
{
// Docs and release notes
"name": "Documentation",
"path": "vscode-docs"
},
{
// Yeoman extension generator
"name": "Extension generator",
"path": "vscode-generator-code"
}
]
}
I would also like to include a README file from a root directory that pertains to all those folders. Is there a way to do this?
I am trying to add a simple configuration to my VSCode extension, but I can't find the correct information.
I just want that the user have a string input field, that has a default value, and read it from my typescript code through the vscode library
Can someone provide me and example about which file should I add, where, and how to consume? also if more configurations are needed.
Thanks!
Ok, found
I need to add into my package.json
...
"contributes": {
"commands": [
...
],
"configuration": {
"title": "My Extension",
"properties": {
"myExtension.myProperty": {
"type": "string",
"default": "default",
"description": "description"
}
}
}
},
and consume
vscode.workspace.getConfiguration('myExtension').myProperty;
I have a vs code extension with two configuration values.
"configuration": [
{
"title": "Test",
"properties": {
"conf.test.string2": {
"type": "string",
"description": "Installation Directory",
"scope": "window"
},
"conf.test.string1": {
"type": "string",
"description": "Directory",
"scope": "resource"
}
}
}
I am installing the extension using a custom installer which will run code <extension-name.vsix> for installing. How can I set the default values for these configurations during the installation? The values are derived during the installation by the custom installer.
Is there a way to pass the values in the commandline or any other way during the installation?
Add the configuration value to Settings.json in %APPDATA%/Code/User/settings.json
I work on a new grammar for a language and I introduce new scopes.
I want to define sane default colors for these new scopes like it could be done with the color-contribution
The following example shows how it's done for colors:
{
"contributes": {
"colors": [
{
"id": "superstatus.error",
"description": "Color for error message in the status bar.",
"defaults": {
"dark": "errorForeground",
"light": "errorForeground",
"highContrast": "#010203"
}
}
]
}
}
I want to set defaults for tokenColors within my extension like:
{
"contributes": {
"tokenColors": [
{
"scopes": ["my.warning.new.scope.waring", "my.warining.other.new.scope"],
"description": "Color for warning message in unknown .",
"defaults": {
"dark": "wariningForeground",
"light": "wariningForeground",
"highContrast": "#010203"
}
}
]
}
}
I don't want to create a new theme that inherits from another theme, bc the user have to select that explicitly.
I want do define sane defaults for a scope, bc most themes won't define a color for my new scope.
Is there a way to define default token colors for token scopes without creating a new theme?
I am building a VS Code extension starting from this page. Now I want to hide in the palette menu the command extension.timerStart after I run it. I have read this page, didn't helped. I have the code bellow for package.json. How do I make the varFromMyExtension===false part work?
"contributes": {
"commands": [
{
"command": "extension.timerStart",
"title": "Timer Start"
}
],
"menus": {
"commandPalette": [
{
"command": "extension.timerStart",
"when": "varFromMyExtension===false"
}
]
}
I think it is not possible to access variables from your extension directly in a when clause. However you can access any configuration of the settings.json.
From the docs (at the bottom of the chapter):
Note: You can use any user or workspace setting that evaluates to a boolean here with the prefix "config.".
So when your extension contributes a boolean configuration called varFromMyExtension you should be able to use it in the when clause. This configuration then can be manipulated programmatically, too.
So your package.json would probably contain something like this (not tested):
"contributes": {
"commands": [
{
"command": "extension.timerStart",
"title": "Timer Start"
}
],
"menus": {
"commandPalette": [
{
"command": "extension.timerStart",
"when": "!config.myextension.varFromMyExtension"
}
]
},
"configuration": {
"type": "object",
"title": "Indicates whether ...",
"properties": {
"myextension.varFromMyExtension": {
"title": "My title.",
"description": "My description",
"type": "boolean",
"default": false,
"pattern": "(true|false)"
}
}
}
}
But bare in mind that the user can see and edit this setting, too.