diff --git a/src/languageserver/handlers/settingsHandlers.ts b/src/languageserver/handlers/settingsHandlers.ts index 36d943039..7ee11527d 100644 --- a/src/languageserver/handlers/settingsHandlers.ts +++ b/src/languageserver/handlers/settingsHandlers.ts @@ -257,10 +257,21 @@ export class SettingsHandler { for (const schemaIndex in schemas.schemas) { const schema = schemas.schemas[schemaIndex]; - - if (schema && schema.fileMatch) { - for (const fileMatch in schema.fileMatch) { - const currFileMatch: string = schema.fileMatch[fileMatch]; + if (!schema.url) { + continue; + } + const fileMatches = schema.fileMatch ?? []; + if (fileMatches.length === 0) { + languageSettings.schemas.push({ + uri: schema.url, + fileMatch: [], + priority: SchemaPriority.SchemaStore, + name: schema.name, + description: schema.description, + versions: schema.versions, + }); + } else { + for (const currFileMatch of fileMatches) { // If the schema is for files with a YAML extension, save the schema association if ( this.yamlSettings.fileExtensions.findIndex((value) => { diff --git a/test/settingsHandlers.test.ts b/test/settingsHandlers.test.ts index a90186e26..fb9842e37 100644 --- a/test/settingsHandlers.test.ts +++ b/test/settingsHandlers.test.ts @@ -277,6 +277,37 @@ describe('Settings Handlers Tests', () => { versions: undefined, }); }); + it('SettingsHandler should include schemas without file matches as selectable schemas', async () => { + const languageServerSetup = setupLanguageService({}); + const languageService = languageServerSetup.languageService; + xhrStub.resolves({ + responseText: `{"schemas": [ + { + "name": "Traefik v3", + "description": "Traefik v3 YAML configuration file", + "url": "https://www.schemastore.org/traefik-v3.json" + }]}`, + }); + const settingsHandler = new SettingsHandler( + connection, + languageService as unknown as LanguageService, + settingsState, + validationHandler as unknown as ValidationHandler, + {} as Telemetry + ); + workspaceStub.getConfiguration.resolves([{}, {}, {}, {}]); + const configureSpy = sinon.stub(languageService, 'configure'); + await settingsHandler.pullConfiguration(); + configureSpy.restore(); + expect(settingsState.schemaStoreSettings).deep.include({ + uri: 'https://www.schemastore.org/traefik-v3.json', + fileMatch: [], + priority: SchemaPriority.SchemaStore, + name: 'Traefik v3', + description: 'Traefik v3 YAML configuration file', + versions: undefined, + }); + }); }); it('SettingsHandler should not modify file match patterns', async () => {