Skip to content

[json-language-features] Fix json/schemaAssociations parameters documentation#106061

Merged
aeschli merged 2 commits intomicrosoft:masterfrom
rchl:fix/json-language-features-docs
Sep 7, 2020
Merged

[json-language-features] Fix json/schemaAssociations parameters documentation#106061
aeschli merged 2 commits intomicrosoft:masterfrom
rchl:fix/json-language-features-docs

Conversation

@rchl
Copy link
Copy Markdown
Contributor

@rchl rchl commented Sep 3, 2020

The json/schemaAssociations documentation is not accurate in stating
that the only supported parameter is an object in { pattern: uri }
format. It also supports the structure defined by SchemaConfiguration
interface from "vscode-json-languageservice".

Also updated the server code to match that.

This PR fixes #106060

…entation

The `json/schemaAssociations` documentation is not accurate in stating
that the only supported parameter is an object in `{ pattern: uri }`
format. It also supports the structure defined by `SchemaConfiguration`
interface from "vscode-json-languageservice".

Also updated the server code to match that.

Resolves #106060
@ghost
Copy link
Copy Markdown

ghost commented Sep 3, 2020

CLA assistant check
All CLA requirements met.

@aeschli aeschli merged commit e56f766 into microsoft:master Sep 7, 2020
@aeschli aeschli added this to the September 2020 milestone Sep 7, 2020
Comment on lines +169 to +171
fileMatch: string[];

}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema property is also supported.
The type could be set to object if you didn't want to reference JSONSchema.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I see what you did there now.

It's no longer accurate again after your change...

Copy link
Copy Markdown
Contributor Author

@rchl rchl Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was meant to describe two possible inputs for that notification:

  1. An object form. Example:
{
  'foo.js': ['http://schemas.org/foo.json'],
  'bar.js': ['http://schemas.org/bar.json'],
}
  1. An array form. Example:
[
  {
    fileMatch: ['foo.js'],
    uri: ['http://schemas.org/foo.json'],
  },
  {
    fileMatch: ['bar.js'],
    uri: ['http://schemas.org/bar.json'],
  },
]

With your change, we're back to just explaining the first form.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry, was confused by ISchemaAssociations/ISchemaAssociation[] naming. Thought that ISchemaAssociations is just an array of ISchemaAssociation and thus equivalent.

I'm just wondering why schema property was removed from the interface documentation.

@rchl rchl deleted the fix/json-language-features-docs branch September 7, 2020 08:26
@aeschli
Copy link
Copy Markdown
Contributor

aeschli commented Sep 7, 2020

The json/schemaAssociations message is for the associations that come from the jsonValidation contribution point in vscode,
More associations can come the user settings. There you can have the schema.

See the Settings section in the readme.

@rchl
Copy link
Copy Markdown
Contributor Author

rchl commented Sep 7, 2020

The json/schemaAssociations message is for the associations that come from the jsonValidation contribution point in vscode,
More associations can come the user settings. There you can have the schema.

What is used in vscode is one thing but I'm talking about what this endpoint supports specifically.
Those are handled at https://github.com/microsoft/vscode-json-languageservice/blob/a5d6dfbfb6032fdfa5901c3e21409581e0d10f0a/src/jsonLanguageService.ts#L75-L75 and so also support schema object.

@aeschli
Copy link
Copy Markdown
Contributor

aeschli commented Sep 7, 2020

That's the API of the service (vscode-json-languageservice)

The readme is for the server.

The server listens to the (LSP) configuration and schema association messagse (see here) and then configures the service with the sum of all configurations. (see here)

@rchl
Copy link
Copy Markdown
Contributor Author

rchl commented Sep 7, 2020

That's the API of the service (vscode-json-languageservice)

Here is what the server does:

if (schemaAssociations) {
if (Array.isArray(schemaAssociations)) {
Array.prototype.push.apply(languageSettings.schemas, schemaAssociations);
} else {

It just passes json/schemaAssociations-provided schemas as is to the service. That means the service will handle the schema property if it was provided by the user.

I also know about schemas passed through initialize request but that doesn't change the handling of json/schemaAssociations itself.

@aeschli
Copy link
Copy Markdown
Contributor

aeschli commented Sep 7, 2020

Ok I see, that was not intentional.
First we had the map, then (since a few releases) the array. You can see from the map code that we haven't supported schema.
I want to leave it at that, and will make a code change to not simply copy the array.

@rchl
Copy link
Copy Markdown
Contributor Author

rchl commented Sep 7, 2020

I'm not against making that code more explicit but I don't see any reason to limit it to not pass schema property.
It's more consistent if it's supported both from that place and initialize request.

BTW. Also, semi-related, the schemas passed through initialize request require url property while those passed through json/schemaAssociations an uri property. That is inconsistent. It's always a URI really.

@aeschli
Copy link
Copy Markdown
Contributor

aeschli commented Sep 7, 2020

Yes, the uri/url inconsistency is unhappy, it has historical reasons. As the url is part of user settings, change it is not trivial and could result in more confusion that clarity.

@aeschli
Copy link
Copy Markdown
Contributor

aeschli commented Oct 1, 2020

I added the ISchemaAssociation.schema to the spec, after all. You are right, it's more consistent and makes it easier to configure the LS with schemas.

1b96024

@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[vscode-json-languageserver] API documentation is inaccurate

2 participants