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

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.

Related

Azure DevOps Server 2019 extension: How do I limit the work item data entry forms my custom page appears on?

I'm using Azure Devops Server 2019, update 1.1. My goal is to write an extension that presents a new page, but only on the user story work item data entry form and not the data entry form for a Task, Bug, Issues, etc. See screen shot
Here is the contributions section of my vss-extension.json (It's what produced the custom page in the screen shot above). I've read Extension manifest reference, but I can't find a setting related to limiting which form a new page appears on.
Does anyone know which area of the extensions architecture I need to work in to limit which forms on which a new page appears?
"contributions": [
{
"id": "sample-work-item-form-page",
"type": "ms.vss-work-web.work-item-form-page",
"description": "Custom work item form page",
"targets": [
"ms.vss-work-web.work-item-form"
],
"properties": {
"name": "Create Standard Tasks",
"uri": "workItemPage.html"
}
}
]
By reference to this doc: Extend the work item form, this web extension belongs to Azure Boards service, so it will appear in all work item pages as your mentioned doc: Extension manifest reference. Currently it is not documented to specify which work item type it appears in.
In addition, you could directly follow this doc: Customize the web layout for a work item type (Inheritance process) to add a custom page to the user story work item.

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

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')

Unable to extend schema within a verified sub domain directory

I live in an enterprise environment where most of our production domains are currently non-routable (e.g. .local).
I tried extending the schema but since the non-routable cannot be verified and the default .onmicrosoft I don't think could either. My enterprise allows me to easily create subdomains so I attached it and verified for testing purposes and ran into the same verified domain error.
Per the documentation, I should be able to either us the ID of my domain name or just the scheme name and get 8 random-alpha-chars added. Neither approach works in this case.
POST: https://graph.microsoft.com/v1.0/schemaExtensions
{
"id": "idmdomain.sub.domain.net_Owners",
"description": "Owners of the group",
"targetTypes": [
"Group"
],
"properties": [{
"name": "PrimaryOwners",
"type": "String"
},
{
"name": "SecondaryOwners",
"type": "String"
}
]
}
Message Received:
{
"code": "BadRequest",
"message": "Your organization must own the namespace idmdomain.sub.domain.net as a part of one of the verified domains.",
"request-id": "1c7363f9-d54b-408a-8b29-2c0d2a94280a",
"date": "2018-03-22T21:47:22"
}
From the documentation:
If you already have a vanity .com,.net, .gov, .edu or a .org domain that you have verified with your tenant, you can use the domain name along with the schema name to define a unique name, in this format {domainName}_{schemaName}.
For example, if your vanity domain is contoso.com, you can define an id of, contoso_mySchema. This is the preferred option.
So in your example, idmdomain.sub.domain.net_Owners should simply be domain_Owners. It shouldn't include idmdomain, sub, net or any ..
Thank you Marc for pointing me in the correct direction. Even though my app had the correct delegated permissions (Directory.AccessAsUser.All) I now understand that I needed to execute this change in the user context instead of application as application is not supported.
For those that come behind me {domainName}_{schemaName} works if you validate your domain, if dont and you just leave schemename then the generated guid works as documented. I recommended reviewing the two links below as they were what finally unlocked the puzzle for me.
Helped me understand how this is working (authentication vs authorization)
https://developer.microsoft.com/en-us/graph/docs/concepts/rest
Helped me setup postman to quickly validate
https://blogs.msdn.microsoft.com/softwaresimian/2017/10/05/using-postman-to-call-the-graph-api-using-azure-active-directory-aad/
I should add for the postman route, a few changes...
Auth URL
https://login.microsoftonline.com/yourtennantid/oauth2/authorize?resource=https%3A%2F%2Fgraph.microsoft.com
Access Token URL
https://login.microsoftonline.com/yourtennantid/oauth2/token
Scope = Directory.AccessAsUser.All

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.

Having trouble PUTting profile variables in Watson Dialog service

I think this is actually two (related) problems. If I try to set profile variables in the Watson Dialog API via Postman, I don't get any errors (200 return code) but the variables don't get set. This is the data I'm sending:
{
"client_id": 152008,
"name_values":[
{
"name": "second",
"value": "2"
}]
}
and this is the answer I get:
{
"client_id": 152008,
"name_values": []
}
Doing a GET confirms that the variables were not set.
If I try to do it via dialog.updateProfile() in the watson-developer-cloud package using the same JSON, I get
Error: Missing required parameters: name_values
instead.
Has anyone successfully set Watson Dialog profile variables? How did you do it?
The Dialog profile variable you wish to manipulate via the API needs to already exist in the Dialog XML file. You can not create a new Dialog profile variable via the API.