From 004be4a4058262e2cd7c8116a05adbf0e8178886 Mon Sep 17 00:00:00 2001 From: Morgan Chang Date: Wed, 29 Apr 2026 18:01:50 -0400 Subject: [PATCH 1/3] support `showSchemaSource` configuration Signed-off-by: Morgan Chang --- .../handlers/settingsHandlers.ts | 4 ++ src/languageservice/services/yamlHover.ts | 4 +- src/languageservice/yamlLanguageService.ts | 5 ++ src/yamlSettings.ts | 2 + test/hover.test.ts | 72 +++++++++++++++++++ test/utils/serviceSetup.ts | 6 ++ 6 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/languageserver/handlers/settingsHandlers.ts b/src/languageserver/handlers/settingsHandlers.ts index 581b3f0de..9a68b02f1 100644 --- a/src/languageserver/handlers/settingsHandlers.ts +++ b/src/languageserver/handlers/settingsHandlers.ts @@ -77,6 +77,9 @@ export class SettingsHandler { if (Object.prototype.hasOwnProperty.call(settings.yaml, 'completion')) { this.yamlSettings.yamlShouldCompletion = settings.yaml.completion; } + if (Object.prototype.hasOwnProperty.call(settings.yaml, 'showSchemaSource')) { + this.yamlSettings.yamlShowSchemaSource = settings.yaml.showSchemaSource; + } this.yamlSettings.customTags = settings.yaml.customTags ? settings.yaml.customTags : []; this.yamlSettings.maxItemsComputed = Math.trunc(Math.max(0, Number(settings.yaml.maxItemsComputed))) || 5000; @@ -280,6 +283,7 @@ export class SettingsHandler { flowSequence: this.yamlSettings.style?.flowSequence, yamlVersion: this.yamlSettings.yamlVersion, keyOrdering: this.yamlSettings.keyOrdering, + showSchemaSource: this.yamlSettings.yamlShowSchemaSource, }; if (this.yamlSettings.schemaAssociations) { diff --git a/src/languageservice/services/yamlHover.ts b/src/languageservice/services/yamlHover.ts index da0cc9a30..bee8772c1 100644 --- a/src/languageservice/services/yamlHover.ts +++ b/src/languageservice/services/yamlHover.ts @@ -27,6 +27,7 @@ export class YAMLHover { private shouldHover: boolean; private shouldHoverAnchor: boolean; private indentation: string; + private showSchemaSource: boolean; private schemaService: YAMLSchemaService; constructor( @@ -42,6 +43,7 @@ export class YAMLHover { this.shouldHover = languageSettings.hover; this.shouldHoverAnchor = languageSettings.hoverAnchor; this.indentation = languageSettings.indentation; + this.showSchemaSource = languageSettings.showSchemaSource ?? true; } } @@ -208,7 +210,7 @@ export class YAMLHover { result += `\`\`\`yaml\n${example}\`\`\`\n`; }); } - if (result.length > 0 && schema.schema.url) { + if (result.length > 0 && schema.schema.url && this.showSchemaSource) { result = ensureLineBreak(result); result += l10n.t('Source: [{0}]({1})', getSchemaName(schema.schema), schema.schema.url); } diff --git a/src/languageservice/yamlLanguageService.ts b/src/languageservice/yamlLanguageService.ts index 7d5877161..487ffc0a5 100644 --- a/src/languageservice/yamlLanguageService.ts +++ b/src/languageservice/yamlLanguageService.ts @@ -125,6 +125,11 @@ export interface LanguageSettings { * If set enforce alphabetical ordering of keys in mappings. */ keyOrdering?: boolean; + + /** + * Show schema source URI in hover popups. Default is true. + */ + showSchemaSource?: boolean; } export interface WorkspaceContextService { diff --git a/src/yamlSettings.ts b/src/yamlSettings.ts index b46075958..0bea496c1 100644 --- a/src/yamlSettings.ts +++ b/src/yamlSettings.ts @@ -37,6 +37,7 @@ export interface Settings { keyOrdering: boolean; maxItemsComputed: number; yamlVersion: YamlVersion; + showSchemaSource: boolean; }; http: { proxy: string; @@ -80,6 +81,7 @@ export class SettingsState { yamlShouldHover = true; yamlShouldHoverAnchor = true; yamlShouldCompletion = true; + yamlShowSchemaSource = true; schemaStoreSettings = []; customTags = []; schemaStoreEnabled = true; diff --git a/test/hover.test.ts b/test/hover.test.ts index aca2f6b36..7c3842cd8 100644 --- a/test/hover.test.ts +++ b/test/hover.test.ts @@ -1287,4 +1287,76 @@ Source: [${SCHEMA_ID}](file:///${SCHEMA_ID})` expect((result.contents as MarkupContent).value).to.include('Disabled flag'); }); }); + + describe('showSchemaSource configuration', () => { + it('Hover should not show schema source when showSchemaSource is false', async () => { + const languageSettingsSetupWithoutSource = new ServiceSetup() + .withHover() + .withShowSchemaSource(false) + .withSchemaFileMatch({ + uri: SCHEMA_ID, + fileMatch: ['*.yaml'], + }); + const { + languageHandler: langHandler, + yamlSettings: settings, + schemaProvider: testSchemaProvider, + } = setupLanguageService(languageSettingsSetupWithoutSource.languageSettings); + + testSchemaProvider.addSchema(SCHEMA_ID, { + type: 'object', + properties: { + cwd: { + type: 'string', + description: 'The directory from which bower should run.', + }, + }, + }); + const content = 'c|w|d: test'; + const { content: parsedContent, position } = caretPosition(content); + const testTextDocument = setupSchemaIDTextDocument(parsedContent); + settings.documents = new TextDocumentTestManager(); + (settings.documents as TextDocumentTestManager).set(testTextDocument); + const hover = await langHandler.hoverHandler({ + position: testTextDocument.positionAt(position), + textDocument: testTextDocument, + }); + + assert.strictEqual(MarkupContent.is(hover.contents), true); + assert.strictEqual((hover.contents as MarkupContent).kind, 'markdown'); + assert.strictEqual((hover.contents as MarkupContent).value, 'The directory from which bower should run.'); + assert.strictEqual((hover.contents as MarkupContent).value.includes('Source:'), false); + + testSchemaProvider.deleteSchema(SCHEMA_ID); + }); + + it('Hover should show schema source by default', async () => { + schemaProvider.addSchema(SCHEMA_ID, { + type: 'object', + properties: { + cwd: { + type: 'string', + description: 'The directory from which bower should run.', + }, + }, + }); + const content = 'c|w|d: test'; + const { content: parsedContent, position } = caretPosition(content); + const testTextDocument = setupSchemaIDTextDocument(parsedContent); + yamlSettings.documents = new TextDocumentTestManager(); + (yamlSettings.documents as TextDocumentTestManager).set(testTextDocument); + const hover = await languageHandler.hoverHandler({ + position: testTextDocument.positionAt(position), + textDocument: testTextDocument, + }); + + assert.strictEqual(MarkupContent.is(hover.contents), true); + assert.strictEqual((hover.contents as MarkupContent).kind, 'markdown'); + assert.strictEqual((hover.contents as MarkupContent).value.includes('Source:'), true); + assert.strictEqual( + (hover.contents as MarkupContent).value, + `The directory from which bower should run.\n\nSource: [${SCHEMA_ID}](file:///${SCHEMA_ID})` + ); + }); + }); }); diff --git a/test/utils/serviceSetup.ts b/test/utils/serviceSetup.ts index 2bfd68e36..06596c370 100644 --- a/test/utils/serviceSetup.ts +++ b/test/utils/serviceSetup.ts @@ -22,6 +22,7 @@ export class ServiceSetup { yamlVersion: '1.2', flowMapping: 'allow', flowSequence: 'allow', + showSchemaSource: true, }; withValidate(): ServiceSetup { @@ -81,4 +82,9 @@ export class ServiceSetup { this.languageSettings.yamlVersion = version; return this; } + + withShowSchemaSource(show: boolean): ServiceSetup { + this.languageSettings.showSchemaSource = show; + return this; + } } From a2f0e7383f9ccf985ca0cf9c4cfeb7c6e7396f23 Mon Sep 17 00:00:00 2001 From: Morgan Chang Date: Wed, 29 Apr 2026 18:03:37 -0400 Subject: [PATCH 2/3] update README.md Signed-off-by: Morgan Chang --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fb4c632ef..07f07543e 100755 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ The following settings are supported: - `yaml.style.flowMapping` : Forbids flow style mappings if set to `forbid` - `yaml.style.flowSequence` : Forbids flow style sequences if set to `forbid` - `yaml.keyOrdering` : Enforces alphabetical ordering of keys in mappings when set to `true`. Default is `false` +- `yaml.showSchemaSource`: Enable/disable showing the schema source in hover tooltips. Default is `true` ## Suppressing diagnostics From 3bad6421c274d969b97eff2a6beab60cef7df70a Mon Sep 17 00:00:00 2001 From: Morgan Chang Date: Thu, 30 Apr 2026 10:57:19 -0400 Subject: [PATCH 3/3] rename showSchemaSource -> hoverSchemaSource Signed-off-by: Morgan Chang --- README.md | 2 +- src/languageserver/handlers/settingsHandlers.ts | 6 +++--- src/languageservice/services/yamlHover.ts | 6 +++--- src/languageservice/yamlLanguageService.ts | 2 +- src/yamlSettings.ts | 4 ++-- test/hover.test.ts | 6 +++--- test/utils/serviceSetup.ts | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 07f07543e..1a41299bb 100755 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ The following settings are supported: - `yaml.style.flowMapping` : Forbids flow style mappings if set to `forbid` - `yaml.style.flowSequence` : Forbids flow style sequences if set to `forbid` - `yaml.keyOrdering` : Enforces alphabetical ordering of keys in mappings when set to `true`. Default is `false` -- `yaml.showSchemaSource`: Enable/disable showing the schema source in hover tooltips. Default is `true` +- `yaml.hoverSchemaSource`: Enable/disable showing the schema source in hover tooltips. Default is `true` ## Suppressing diagnostics diff --git a/src/languageserver/handlers/settingsHandlers.ts b/src/languageserver/handlers/settingsHandlers.ts index 9a68b02f1..8372ac871 100644 --- a/src/languageserver/handlers/settingsHandlers.ts +++ b/src/languageserver/handlers/settingsHandlers.ts @@ -77,8 +77,8 @@ export class SettingsHandler { if (Object.prototype.hasOwnProperty.call(settings.yaml, 'completion')) { this.yamlSettings.yamlShouldCompletion = settings.yaml.completion; } - if (Object.prototype.hasOwnProperty.call(settings.yaml, 'showSchemaSource')) { - this.yamlSettings.yamlShowSchemaSource = settings.yaml.showSchemaSource; + if (Object.prototype.hasOwnProperty.call(settings.yaml, 'hoverSchemaSource')) { + this.yamlSettings.yamlhoverSchemaSource = settings.yaml.hoverSchemaSource; } this.yamlSettings.customTags = settings.yaml.customTags ? settings.yaml.customTags : []; @@ -283,7 +283,7 @@ export class SettingsHandler { flowSequence: this.yamlSettings.style?.flowSequence, yamlVersion: this.yamlSettings.yamlVersion, keyOrdering: this.yamlSettings.keyOrdering, - showSchemaSource: this.yamlSettings.yamlShowSchemaSource, + hoverSchemaSource: this.yamlSettings.yamlhoverSchemaSource, }; if (this.yamlSettings.schemaAssociations) { diff --git a/src/languageservice/services/yamlHover.ts b/src/languageservice/services/yamlHover.ts index bee8772c1..fdaa1eac7 100644 --- a/src/languageservice/services/yamlHover.ts +++ b/src/languageservice/services/yamlHover.ts @@ -27,7 +27,7 @@ export class YAMLHover { private shouldHover: boolean; private shouldHoverAnchor: boolean; private indentation: string; - private showSchemaSource: boolean; + private hoverSchemaSource: boolean; private schemaService: YAMLSchemaService; constructor( @@ -43,7 +43,7 @@ export class YAMLHover { this.shouldHover = languageSettings.hover; this.shouldHoverAnchor = languageSettings.hoverAnchor; this.indentation = languageSettings.indentation; - this.showSchemaSource = languageSettings.showSchemaSource ?? true; + this.hoverSchemaSource = languageSettings.hoverSchemaSource ?? true; } } @@ -210,7 +210,7 @@ export class YAMLHover { result += `\`\`\`yaml\n${example}\`\`\`\n`; }); } - if (result.length > 0 && schema.schema.url && this.showSchemaSource) { + if (result.length > 0 && schema.schema.url && this.hoverSchemaSource) { result = ensureLineBreak(result); result += l10n.t('Source: [{0}]({1})', getSchemaName(schema.schema), schema.schema.url); } diff --git a/src/languageservice/yamlLanguageService.ts b/src/languageservice/yamlLanguageService.ts index 487ffc0a5..b21cb0aaa 100644 --- a/src/languageservice/yamlLanguageService.ts +++ b/src/languageservice/yamlLanguageService.ts @@ -129,7 +129,7 @@ export interface LanguageSettings { /** * Show schema source URI in hover popups. Default is true. */ - showSchemaSource?: boolean; + hoverSchemaSource?: boolean; } export interface WorkspaceContextService { diff --git a/src/yamlSettings.ts b/src/yamlSettings.ts index 0bea496c1..5d8c1fbe0 100644 --- a/src/yamlSettings.ts +++ b/src/yamlSettings.ts @@ -37,7 +37,7 @@ export interface Settings { keyOrdering: boolean; maxItemsComputed: number; yamlVersion: YamlVersion; - showSchemaSource: boolean; + hoverSchemaSource: boolean; }; http: { proxy: string; @@ -81,7 +81,7 @@ export class SettingsState { yamlShouldHover = true; yamlShouldHoverAnchor = true; yamlShouldCompletion = true; - yamlShowSchemaSource = true; + yamlhoverSchemaSource = true; schemaStoreSettings = []; customTags = []; schemaStoreEnabled = true; diff --git a/test/hover.test.ts b/test/hover.test.ts index 7c3842cd8..bc4e013a8 100644 --- a/test/hover.test.ts +++ b/test/hover.test.ts @@ -1288,11 +1288,11 @@ Source: [${SCHEMA_ID}](file:///${SCHEMA_ID})` }); }); - describe('showSchemaSource configuration', () => { - it('Hover should not show schema source when showSchemaSource is false', async () => { + describe('hoverSchemaSource configuration', () => { + it('Hover should not show schema source when hoverSchemaSource is false', async () => { const languageSettingsSetupWithoutSource = new ServiceSetup() .withHover() - .withShowSchemaSource(false) + .withhoverSchemaSource(false) .withSchemaFileMatch({ uri: SCHEMA_ID, fileMatch: ['*.yaml'], diff --git a/test/utils/serviceSetup.ts b/test/utils/serviceSetup.ts index 06596c370..a7bc5d906 100644 --- a/test/utils/serviceSetup.ts +++ b/test/utils/serviceSetup.ts @@ -22,7 +22,7 @@ export class ServiceSetup { yamlVersion: '1.2', flowMapping: 'allow', flowSequence: 'allow', - showSchemaSource: true, + hoverSchemaSource: true, }; withValidate(): ServiceSetup { @@ -83,8 +83,8 @@ export class ServiceSetup { return this; } - withShowSchemaSource(show: boolean): ServiceSetup { - this.languageSettings.showSchemaSource = show; + withhoverSchemaSource(show: boolean): ServiceSetup { + this.languageSettings.hoverSchemaSource = show; return this; } }