Skip to content

Commit 46c94f9

Browse files
authored
Intellisense recommends invalid schema uris for JSON Schema drafts (#201)
1 parent 2cb7fe3 commit 46c94f9

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/services/configuration.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import * as l10n from '@vscode/l10n';
1010
export const schemaContributions: ISchemaContributions = {
1111
schemaAssociations: [],
1212
schemas: {
13-
// refer to the latest schema
14-
'http://json-schema.org/schema#': {
15-
$ref: 'http://json-schema.org/draft-07/schema#'
16-
},
1713
// bundle the schema-schema to include (localized) descriptions
1814
'http://json-schema.org/draft-04/schema#': {
1915
'$schema': 'http://json-schema.org/draft-04/schema#',

src/services/jsonCompletion.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -733,13 +733,18 @@ export class JSONCompletion {
733733

734734
private addDollarSchemaCompletions(separatorAfter: string, collector: CompletionsCollector): void {
735735
const schemaIds = this.schemaService.getRegisteredSchemaIds(schema => schema === 'http' || schema === 'https');
736-
schemaIds.forEach(schemaId => collector.add({
737-
kind: CompletionItemKind.Module,
738-
label: this.getLabelForValue(schemaId),
739-
filterText: this.getFilterTextForValue(schemaId),
740-
insertText: this.getInsertTextForValue(schemaId, separatorAfter),
741-
insertTextFormat: InsertTextFormat.Snippet, documentation: ''
742-
}));
736+
schemaIds.forEach(schemaId => {
737+
if (schemaId.startsWith('http://json-schema.org/draft-')) {
738+
schemaId = schemaId + '#';
739+
}
740+
collector.add({
741+
kind: CompletionItemKind.Module,
742+
label: this.getLabelForValue(schemaId),
743+
filterText: this.getFilterTextForValue(schemaId),
744+
insertText: this.getInsertTextForValue(schemaId, separatorAfter),
745+
insertTextFormat: InsertTextFormat.Snippet, documentation: ''
746+
});
747+
});
743748
}
744749

745750
private getLabelForValue(value: any): string {

src/test/completion.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,9 @@ suite('JSON Completion', () => {
10781078
});
10791079
await testCompletionsFor('{ "$schema": | }', schema, {
10801080
items: [
1081-
{ label: '"http://myschemastore/test1"', resultText: '{ "$schema": "http://myschemastore/test1" }' }
1081+
{ label: '"http://myschemastore/test1"', resultText: '{ "$schema": "http://myschemastore/test1" }' },
1082+
{ label: '"http://json-schema.org/draft-04/schema#"', resultText: '{ "$schema": "http://json-schema.org/draft-04/schema#" }' },
1083+
{ label: '"http://json-schema.org/draft-07/schema#"', resultText: '{ "$schema": "http://json-schema.org/draft-07/schema#" }' }
10821084
]
10831085
});
10841086
await testCompletionsFor('{ "$schema": "|', schema, {

0 commit comments

Comments
 (0)