Writing a vscode plugin for adding snippets but only for file composer.json - visual-studio-code

Did you know if it's possible to write a vscode plugin to match only a given file?
My plugin already works but add snippets for all .json files. I wish to be able to add these snippets only if the current file is composer.json.
My current package.json (partial) is:
{
"contributes": {
"snippets": [
{
"language": "json",
"path": "./snippets/snippets.code-snippets"
}
]
}
}
The idea is to be able to having something like:
{
"contributes": {
"snippets": [
{
"filename": "composer.json", <-- JUST FOR ILLUSTRATION PURPOSE
"path": "./snippets/snippets.code-snippets"
}
]
}
}
Thanks.

Related

VS Code: Add single file (README) to multi-root workspace

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?

How to inject a TextMate grammar to a Markdown heading in VS Code?

I want to select [ ] for syntax highlighting within a markdown file in VS Code.
I can target [ ] using the following regex: (?<=\s)\]|\[(?=\s).
However [ ] doesn't get matched when it is part of a heading.
As a minimal example, in the package.json I have the following:
"contributes": {
"grammars": [
{
"scopeName": "markdown.todo",
"path": "./syntaxes/todo.markdown.json",
"injectTo": ["text.html.markdown"]
}
]
}
Then, in the todo.markdown.json I have:
{
"scopeName": "markdown.todo",
"injectionSelector": "L:text.html.markdown",
"patterns": [
{ "include": "#item-todo" }
],
"repository": {
"item-todo": {
"name": "item.todo",
"match": "(?<=\\s)\\]|\\[(?=\\s)"
}
}
}
Finally, in the VS Code settings.json I apply a color using:
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "item.todo",
"settings": {
"foreground": "#FF0000"
}
}
]
}
I can see below that [ ] gets selected, but not when it is within a heading.
When I inspect the tokens and scopes I see several textmate scopes.
I am not sure if this is related, but it seems that VS Code is highlighting the markdown headings based on the markup.heading scope. However, markup.heading is not present in the textmate scopes array.
I tried changing to "injectionSelector": "L:heading.1.markdown" and/ or "injectTo": ["heading.1.markdown"], but no matter what selectors I specify I cannot seem to be able to match [ ] within a heading.

How to add configurations to user to a VSCode extension

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;

VSCode Running a Script Using Macros

tl;dr:
I wanna run a script through a macro using "macros" extension for VSCode, see the extension here
Is it possible? if yes, then how?
long story:
There is this extension called "powertools" (see it here), and I used it to add a custom button that runs a script when I click it.
I wanna add a functionality to this button, such that each time I click the button, it saves all of my files using this command ID "workbench.action.files.saveAll", and then shall it run the script.
defining the button goes like this:
"ego.power-tools": {
"buttons":
[
{
"text": "Compile Folder",
"tooltip": "Compile all the .Jack files in the current folder.",
"action":
{
"type": "command",
"command": "macros.compile_button_click",
}
}
],
}
And I want the macro to look something like this:
"macros": {
"compile_button_click": [
"workbench.action.files.saveAll",
{
"action":
{
"type": "script",
"script": "compile_folder.js"
}
},
]
}
Thanks in advance!
P.S - It is important that the macro will first save the files, and only then shall it execute the script
THE SOLUTION:
as #rioV8 said, using powertools you can define a command to execute a script, and then you can add the newly defined command to the macros.
THIS IS HOW I DID IT:
"ego.power-tools": {
"buttons":
[
{
"text": "Save & Compile",
"tooltip": "Compile all the .Jack files in the current folder.",
// Running the macro on button click
"action":
{
"type": "command",
"command": "macros.compile_button_click"
}
}
],
"commands": {
// Define a command that runs a script
"compile_folder": {
"script": "compile_folder.js"
}
}
},
"macros": {
// Define a macro command
"compile_button_click": [
"workbench.action.files.saveAll",
"compile_folder"
]
}

How to use a library on SAPWebIDE

i am trying to use the openui5-googlemaps library, but the WebIDE looks at a different path than my SAP-System then the app is deployed.
libs: ["sap.m", "sap.ui.layout", "sap.ushell", "openui5.googlemaps"],
my SAP-System looks at path resources/openui5/googlemaps.
However this does not work in the WebIDE.
Any ideas why and how i can fix it?
Thanks
Either change the path, or load via your index.
API With Example
In Index
~ update may 2017 ~
You can now use the manifest to add libraries:
"resources": {
"css": [
{
"uri": "css/style.css"
},
{
"uri": "css/croppie.css"
}
],
"js": [
{
"uri": "library/croppie.min.js"
}
]