How do you create custom settings for a vs code extension? - json

I have been researching for hours but to no avail.
Pretty much all VsCode extensions will have custom made settings, and they show up in the default settings json file like this from the Red Hat Java extension:
"java.dependency.showOutline": true,
I'm trying to write my own extension and I have found a lot of useful stuff, I can create custom themes, snippets, commands, etc. and it's all well documented on the VsCode API site, but I need to create custom user-defined settings, and I cannot find ANYWHERE that explains how to do so. Does anyone know?

This is done using contribution points, JSON declarations in the contributes field of your extension's package.json file.
You want the configuration contribution point.
For example:
// package.json
{
"contributes": {
"configuration": {
"title": "",
"properties": {
"scope.name": {
"type": "",
"default": "",
"description": ""
}
}
}
}
}
Then you can read those values using
vscode.workspace.getConfiguration('your-extension-name')

Related

Automate inclusion of Git submodules based on JSON file

This question may be too open-ended for Stack Overflow, but I'm getting nowhere on my own. I am looking for a way to use automate the use of designated Git submodules based on values in a text file. My company generates a lot of projects, but we reuse a lot of code. We use submodules and tags for this, but the volume is starting to get unwieldy.
I was thinking it would make sense to use something similar to an NPM packages.json file. Maybe like this:
{
"name": "Custom Development Components",
"description": "Reusable objects to increase the efficiency and quality of custom development",
"components": [
{
"name": "stats",
"description": "Statistics",
"URL": "https://my.git.repo/Statistics",
"folder-name": "STATS",
"version": "^"
},
{
"name": "standard",
"description": "Standard",
"URL": "https://my.git.repo/Standard",
"folder-name": "STANDARD",
"version": "X"
},
{
"name": "helpers",
"description": "Helper Objects and Scripts",
"URL": "https://my.git.repo/Helpers",
"folder-name": "HELPERS",
"version": "^"
}
]
}
But I haven't been able to figure out how to parse the JSON and turn it into Git commands. I've fiddled around with using JQ in a Windows batch file (we're all working in Windows environments), but I haven't gotten very far with it. Basically, I'm looking to be able to step through the JSON, find components where the version is a string other than ^ (which may or may not be a specific tag), and import the URL for the submodule.
Any guidance here would be appreciated.
just use something like this this:
$ jq -r < /tmp/o '.components[] | select( .version != "^" ) | "git submodule init \(.URL):\(.version)"'
git submodule init https://my.git.repo/Standard:X
I'm not much versed in the bat language, but you may have some luck with:
https://superuser.com/questions/652492/windows-equivalent-to-xargs

“Cannot find debug adapter for type 'dart". ”

I'm trying to debug dart script in vs code.
Below is my launch.json -
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "todoapp",
"request": "launch",
"type": "dart"
}
]
} ```
Go to Extensions View (⇧⌘X) and search for Dart extension. Try to uninstall and reinstall the Dart extension, and then restart VS code to see if it works.
If it is still not working, install an older version of Dart and give it a try again.

VS code API documentation isn't clear on how to read json customizable values

I ahve read both the online docuemntation and the source code for the VS code API and it is still not clear to me how to read the JSON user settings and workpsace settings. I ahve tried to look for examples but I can't find something that just displays how to do this.
In essence I want a value in the settings called "maximum". I want then to read the value of maximum from the TS scrypt.
The documentation has led me to write the following two lines in the activate function:
const config = vscode.workspace.getConfiguration('extension', vscode.window.activeTextEditor.document.uri);
vscode.window.showInformationMessage(config.has('configuration').toString());
In the package.json file I have added, under contributes:
"configuration": {
"maximum":
{
"type": ["integer"],
"default": 40,
"description": "The level of alignment, how far the titles will extend horizontally"
}
}
However I get false as an output.
I have tried multiple different outputs and the only time I got true was when the parameter of the first function was 'launch' and the second parameters was 'configurations'.
I do nmot understand from the documentation alone what the parameters need to be. Nor where should the value be specified.
You get False as output because the configuration keyword in the package.json indicates only the configuration contribution point of your extension.
I would suggest you to adopt the vscode example to your needs:
"contributes": {
"configuration": {
"type": "object",
"title": "This is my config",
"properties": {
"myExtensionName.maximum": {
"type": "integer",
"default": 40,
"description": "The level of alignment, how far the titles will extend horizontally."
}
}
}
}
Now if you run the following you should get returned true:
const config = vscode.workspace.getConfiguration('myExtensionName');
vscode.window.showInformationMessage(config.has('maximum').toString());
I think you can not separately get the workspace and user settings, because vscode's pattern is that the workspace settings override the user settings.
From the docs:
VS Code provides two different scopes for settings:
User Settings - Settings that apply globally to any instance of VS Code you open.
Workspace Settings - Settings stored inside your workspace and only apply when the workspace is opened.
Workspace settings override user settings.

Azure Functions: How do I control development/production/staging app settings?

I've just started experimenting with Azure functions and I'm trying to understand how to control the app settings depending on environment.
In dotnet core you could have appsettings.json, appsettings.development.json etc. And as you moved between different environments the config would change.
However from looking at Azure function documentation all I can find is that you can set up config in the azure portal but I can't see anything about setting up config in the solution?
So what is the best way to manage build environment?
Thanks in advance :-)
The best way, in my opinion, is using a proper build and release system, like VSTS.
What I've done in one of my solutions is creating an ARM template of my Function App and deploy this using a release pipeline with VSTS RM.
This way you can just add a value to the template.json, like the one from below.
"appSettings": [
// other entries
{
"name": "MyValue",
"value": "[parameters('myValue')]"
}
You will need another file, called parameters.json which will hold the values. This file looks like so (at the moment).
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {},
"storageName": {},
"location": {},
"subscriptionId": {}
}
}
Back in VSTS you can just change/override the values of these parameters in the portal.
By using such a workflow you will get a professional CI/CD implementation where no one has to bother themselves with the actual secrets. They are only known to the system administrators.

Visualize JSON models as domain model

Is there a way to display a bunch of JSON objects, WITH relations, as a domain model?
Models could be something like this:
{
"name": "Order",
"status": {
"type": "number",
"null": false,
"default": 1
}
},
"relations": {
"customer": {
"type": "belongsTo",
"model": "Customer",
"foreignKey": "customerId"
}
}
}
Basically, as this image shows, Domain model -to-> code... but the other way around.?
Thanks
PS: If there are no tools that do this out of the box, I assume that there might be frameworks that I could use to create this.. any recommendations?
As I understand your question you are asking if a utility exists that can turn your JSON code into a domain model. If I understand correctly the answer is yes. There is one project on github that is doing something similar: json-discoverer
From the project page you will see the tool was inspired by some research which was published in ICWE (International Conference on Web Engineering) 2013 and 2014. Below is a link to the main article, as it is quite lengthy and detailed I will not attempt to summarize it here.
Discovering Implicit Schemas in JSON Data
Unfortunately, as you mention you can't then edit the domain afterward. But I have still found it to be a fairly useful tool.
I am unaware of any other existing utilities. The only other alternatives are fairly easy to find with a simple search, but only allow for conversion to trees and/or tables.