Skip to content

Commit 896dc31

Browse files
committed
[json-language-features] Fix json/schemaAssociations parameters documentation
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 microsoft#106060
1 parent 616afa9 commit 896dc31

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

extensions/json-language-features/server/README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,34 @@ In addition to the settings, schemas associations can also be provided through a
143143

144144
Notification:
145145
- method: 'json/schemaAssociations'
146-
- params: `ISchemaAssociations` defined as follows
146+
- params: `ISchemaAssociations | SchemaConfiguration[]` defined as follows
147147

148148
```ts
149-
interface ISchemaAssociations {
150-
[pattern: string]: string[];
149+
/**
150+
* An object where:
151+
* - keys are file names or file paths (separated by `/`). `*` can be used as a wildcard.
152+
* - values ar an arrays of schema URLs
153+
*/
154+
type ISchemaAssociations = Record<string, string[]>
155+
156+
interface SchemaConfiguration {
157+
/**
158+
* The URI of the schema, which is also the identifier of the schema.
159+
*/
160+
uri: string;
161+
/**
162+
* A list of file path patterns that are associated to the schema. The '*' wildcard can be used. Exclusion patterns starting with '!'.
163+
* For example '*.schema.json', 'package.json', '!foo*.schema.json'.
164+
* A match succeeds when there is at least one pattern matching and last matching pattern does not start with '!'.
165+
*/
166+
fileMatch?: string[];
167+
/**
168+
* The schema for the given URI.
169+
* If no schema is provided, the schema will be fetched with the schema request service (if available).
170+
*/
171+
schema?: JSONSchema;
151172
}
152173
```
153-
- keys: a file names or file path (separated by `/`). `*` can be used as a wildcard.
154-
- values: An array of schema URLs
155174

156175
Notification:
157176
- method: 'json/schemaContent'

extensions/json-language-features/server/src/jsonServer.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,10 @@ import { TextDocument, JSONDocument, JSONSchema, getLanguageService, DocumentLan
1414
import { getLanguageModelCache } from './languageModelCache';
1515
import { RequestService, basename, resolvePath } from './requests';
1616

17-
interface ISchemaAssociations {
18-
[pattern: string]: string[];
19-
}
20-
21-
interface ISchemaAssociation {
22-
fileMatch: string[];
23-
uri: string;
24-
}
17+
type ISchemaAssociations = Record<string, string[]>;
2518

2619
namespace SchemaAssociationNotification {
27-
export const type: NotificationType<ISchemaAssociations | ISchemaAssociation[], any> = new NotificationType('json/schemaAssociations');
20+
export const type: NotificationType<ISchemaAssociations | SchemaConfiguration[], any> = new NotificationType('json/schemaAssociations');
2821
}
2922

3023
namespace VSCodeContentRequest {
@@ -212,7 +205,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
212205
}();
213206

214207
let jsonConfigurationSettings: JSONSchemaSettings[] | undefined = undefined;
215-
let schemaAssociations: ISchemaAssociations | ISchemaAssociation[] | undefined = undefined;
208+
let schemaAssociations: ISchemaAssociations | SchemaConfiguration[] | undefined = undefined;
216209
let formatterRegistration: Thenable<Disposable> | null = null;
217210

218211
// The settings have changed. Is send on server activation as well.

0 commit comments

Comments
 (0)