Use built-in Octicons in editor/title menu for vscode extension command contribution point - visual-studio-code

Is it possible to use Octitons that ship with vscode without embedding it into my extension?
"contributes": {
"commands": [
{
"command": "my.extraordinary.command",
"title": "My command",
"icon":{
"dark": "<what should go here?>",
"light": "<what should go here?>"
}
},
],
"menus": {
"editor/title": [
{
"command": "my.extraordinary.command",
"group": "navigation"
}
]
},

Related

Prevent asynchronous order of command sequence execution in VS Codium

How can I control the execution order of multiCommand extension? It behaves like it executes them in parallel, while I want them to be executed one after another.
I have a project with the following structure:
/home/user/myproject/dir1/problem1.py
/home/user/myproject/dir1/problem1.txt
/home/user/myproject/dir1/problem2.py
/home/user/myproject/dir1/problem2.txt
...
/home/user/myproject/pointer.txt
The pointer.txt contains the text: dir1/problem2.
I want to press a shortcut, and do a sequence of actions:
Create next problem files pair
Modify a pointer.txt to point to new files
Open them in the editor
I setuped the following things.
In settings.json I defined the command sequence named "openPointedProblemLayout" (for being able to easily reuse it):
"multiCommand.commands": [
{
"command": "multiCommand.openPointedProblemLayout",
"sequence": [
{ "command": "htmlRelatedLinks.openFile",
"args": {
"file": "${command:mypointer}.py",
"method": "vscode.open",
"viewColumn": 1,
"command": {
"mypointer": {
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/pointer.txt"
}
}
}
}
},
{ "command": "htmlRelatedLinks.openFile",
"args": {
"file": "${command:mypointer}.txt",
"method": "vscode.open",
"viewColumn": 2,
"command": {
"mypointer": {
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/pointer.txt"
}
}
}
}
},
]
},
]
In tasks.json I created a shell command definition, that creates a new .py and .txt pair and also changes the pointer:
{
"version": "2.0.0",
"tasks": [
{
"label": "create_new_problem_files_pair",
"type": "shell",
"command": "python /home/user/scripts/create_new_problem_files_pair.py \"${file}\""
},
],
}
In keybindings.json I defined shortcut numpad2 that executes both actions (creates files and opens them) and a numpad5 (just opens them):
{
"key": "numpad2",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
{
"command": "workbench.action.tasks.runTask",
"args": "create_new_problem_files_pair"
},
{
"command": "multiCommand.openPointedProblemLayout"
},
]
}
},
{
"key": "numpad5",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.openPointedProblemLayout" },
},
Now, when I press numpad2, the two new files are created:
/home/user/myproject/dir1/problem3.py
/home/user/myproject/dir1/problem3.txt
And then two files are opened in layout (means the command actually runs), but wrong files. They are problem2.py and problem2.txt, i.e. the previous pointer is used.
I checked the content of the pointer.txt now, and it actually contains dir1/problem3. And when I press numpad5, they are opened correctly.
Why does the VS Codium uses previous content of pointer, while at the moment of command run, it should already take the new content? It looks like VS Code executes the command sequence in parallel, instead of sequence them.
Am I doing something wrong? Is that an issue with configuration or vs code itself or maybe in multiCommand extension?
I have solved the problem by avoiding usage of any extensions. A command sequence can be defined via Tasks. See https://stackoverflow.com/a/72201981/7869636
In keybindings.json I define:
{
"key": "numpad2",
"command": "workbench.action.tasks.runTask",
"args": "create_new_problem_files_pair_and_open_file_pair_in_layout"
},
And in tasks.json I defined the whole things:
{
"version": "2.0.0",
"tasks": [
{
"label": "create_new_problem_files_pair",
"type": "shell",
"command": "python /home/user/scripts/create_new_problem_files_pair.py \"${file}\""
},
{
"label": "open_file_pair_in_layout",
"dependsOrder": "sequence",
"dependsOn": [
"open_in_layout_left",
"open_in_layout_right",
],
},
{
"label": "create_new_problem_files_pair_and_open_file_pair_in_layout",
"dependsOrder": "sequence",
"dependsOn": [
"create_new_problem_files_pair",
"open_file_pair_in_layout",
],
},
{
"label": "open_in_layout_left",
"command": "${input:open_in_layout_left}",
},
{
"label": "open_in_layout_right",
"command": "${input:open_in_layout_right}",
},
],
"inputs": [
{
"id": "open_in_layout_left",
"type": "command",
"command": "htmlRelatedLinks.openFile",
"args": {
"file": "${command:mypointer}.py",
"method": "vscode.open",
"viewColumn": 1,
"command": {
"mypointer": {
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/pointer.txt"
}
}
}
}
},
{
"id": "open_in_layout_right",
"type": "command",
"command": "htmlRelatedLinks.openFile",
"args": {
"file": "${command:mypointer}.txt",
"method": "vscode.open",
"viewColumn": 2,
"command": {
"mypointer": {
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/pointer.txt"
}
}
}
}
}
]
}
This approach has a benefit that it defines these tasks in a scope of that project's workspace, and not globally in setting.json.

Why does VSCode not highlight anything when I use this textMate?

I am writing a logic gate simulator and have decided to make a VSCode extension for the language it uses. So far, I have a folder named lgc that contains the extension. Inside that folder there are the following:
package.json:
{
"name": "Lgc",
"version": "0.1.0",
"engines": {
"vscode": ">=0.9.0-pre.1"
},
"publisher": "AwesomeCronk",
"contributes": {
"languages": [{
"id": "lgc",
"aliases": ["lgc", "Lgc", "LGC"],
"extensions": [".lgc",".ttb"]
}],
"grammars": [{
"language": "lgc",
"scopeName": "source.lgc",
"path": "./syntaxes/lgc.tmLanguage.json"
}]
}
}
syntaxes/lgc.tmLanguage.json:
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Lgc",
"patterns": [
{
"include": "#keywords"
}
],
"repository":
{
"keywords":
{
"paterns":
[
{
"name:": "keyword.gate.lgc",
"match": "a"
}
]
}
},
"scopeName": "source.lgc"
}
This is a test that should highlight any instance of the letter a as keywords. When I copy this folder to $Home/.vscode/extensions/, and restart VSCode with a .lgc file open, it is not highlighted at all. All the text is white. The status bar shows lgc as the language, so I know VSCode is detecting the language properly. Why doesn't it highlight?
I think you have a typo in your syntaxes/lgc.tmLanguage.json file:
"paterns":
Should be:
"patterns":

VS Code ESLint Checking for quick fixes... not working

I'm not sure if it was a recent update, but for some reason I'm not getting the quick fixes for ESLint any longer. It will say "Checking for quick fixes...", but I will not display any. In the ESLint server I can see the fix available, but the command is missing in VS Code.
[Trace - 5:30:49 PM] Received response 'textDocument/codeAction - (13)' in 0ms.
Result: [
{
"title": "Disable no-unused-vars for this line",
"command": {
"title": "Disable no-unused-vars for this line",
"command": "eslint.applyDisableLine",
"arguments": [
{
"uri": "file:///d%3A/Development/sfdx/insider/force-app/main/default/lwc/apexImperativeMethod/apexImperativeMethod.js",
"version": 14,
"ruleId": "no-unused-vars"
}
]
},
"kind": "quickfix"
},
{
"title": "Disable no-unused-vars for the entire file",
"command": {
"title": "Disable no-unused-vars for the entire file",
"command": "eslint.applyDisableFile",
"arguments": [
{
"uri": "file:///",
"version": 14,
"ruleId": "no-unused-vars"
}
]
},
"kind": "quickfix"
},
{
"title": "Show documentation for no-unused-vars",
"command": {
"title": "Show documentation for no-unused-vars",
"command": "eslint.openRuleDoc",
"arguments": [
{
"uri": "file:///",
"version": 14,
"ruleId": "no-unused-vars"
}
]
},
"kind": "quickfix"
}
]
Same was happening to me as well and after trying multiple things what worked for me was a clean reinstall of Code which meant uninstalling Code, deleting the extension folder and and installing the code followed by extensions. And quick fix is back.

Unable to create menu with contributes.menu

I am unable to create a menu using the documentation at the link below for contributes.menu. Actually, I was able to create one menu item, but could not create a second one. The code excerpt is from my package.json on Windows 10 using VS Code 1.37.0.
So my question is, can someone show me an example of adding two menu items?
-TIA
"contributes": {
"menus": {
"editor/title": [{
"title": "Underline Text",
"when": "editorHasSelection",
"command": "macros.underline",
"alt": "markdown.showPreviewToSide",
"group": "MyGroup#1"
}]
},
"languages": [
https://code.visualstudio.com/api/references/contribution-points#contributes.menus
Already tried the above code.
Here is an example package.json, based on the one in the tutorial, that creates two menu items:
{
...
"activationEvents": [
"onCommand:extension.helloWorld",
"onCommand:extension.helloAnotherWorld"
],
"contributes": {
"commands": [
{
"command": "extension.helloWorld",
"title": "Hello World"
},
{
"command": "extension.helloAnotherWorld",
"title": "Hello Another World"
}
],
"menus": {
"editor/title/context": [
{
"command": "extension.helloWorld"
},
{
"command": "extension.helloAnotherWorld"
}
]
}
},
...
}

How do I hide a command in the palette menu from my extension in VS Code

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.