Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.hoverSchemaSource`: Enable/disable showing the schema source in hover tooltips. Default is `true`

## Suppressing diagnostics

Expand Down
4 changes: 4 additions & 0 deletions src/languageserver/handlers/settingsHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, 'hoverSchemaSource')) {
this.yamlSettings.yamlhoverSchemaSource = settings.yaml.hoverSchemaSource;
}
this.yamlSettings.customTags = settings.yaml.customTags ? settings.yaml.customTags : [];

this.yamlSettings.maxItemsComputed = Math.trunc(Math.max(0, Number(settings.yaml.maxItemsComputed))) || 5000;
Expand Down Expand Up @@ -280,6 +283,7 @@ export class SettingsHandler {
flowSequence: this.yamlSettings.style?.flowSequence,
yamlVersion: this.yamlSettings.yamlVersion,
keyOrdering: this.yamlSettings.keyOrdering,
hoverSchemaSource: this.yamlSettings.yamlhoverSchemaSource,
};

if (this.yamlSettings.schemaAssociations) {
Expand Down
4 changes: 3 additions & 1 deletion src/languageservice/services/yamlHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class YAMLHover {
private shouldHover: boolean;
private shouldHoverAnchor: boolean;
private indentation: string;
private hoverSchemaSource: boolean;
private schemaService: YAMLSchemaService;

constructor(
Expand All @@ -42,6 +43,7 @@ export class YAMLHover {
this.shouldHover = languageSettings.hover;
this.shouldHoverAnchor = languageSettings.hoverAnchor;
this.indentation = languageSettings.indentation;
this.hoverSchemaSource = languageSettings.hoverSchemaSource ?? true;
}
}

Expand Down Expand Up @@ -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.hoverSchemaSource) {
result = ensureLineBreak(result);
result += l10n.t('Source: [{0}]({1})', getSchemaName(schema.schema), schema.schema.url);
}
Expand Down
5 changes: 5 additions & 0 deletions src/languageservice/yamlLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
hoverSchemaSource?: boolean;
}

export interface WorkspaceContextService {
Expand Down
2 changes: 2 additions & 0 deletions src/yamlSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface Settings {
keyOrdering: boolean;
maxItemsComputed: number;
yamlVersion: YamlVersion;
hoverSchemaSource: boolean;
};
http: {
proxy: string;
Expand Down Expand Up @@ -80,6 +81,7 @@ export class SettingsState {
yamlShouldHover = true;
yamlShouldHoverAnchor = true;
yamlShouldCompletion = true;
yamlhoverSchemaSource = true;
schemaStoreSettings = [];
customTags = [];
schemaStoreEnabled = true;
Expand Down
72 changes: 72 additions & 0 deletions test/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,4 +1287,76 @@ Source: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
expect((result.contents as MarkupContent).value).to.include('Disabled flag');
});
});

describe('hoverSchemaSource configuration', () => {
it('Hover should not show schema source when hoverSchemaSource is false', async () => {
const languageSettingsSetupWithoutSource = new ServiceSetup()
.withHover()
.withhoverSchemaSource(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})`
);
});
});
});
6 changes: 6 additions & 0 deletions test/utils/serviceSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ServiceSetup {
yamlVersion: '1.2',
flowMapping: 'allow',
flowSequence: 'allow',
hoverSchemaSource: true,
};

withValidate(): ServiceSetup {
Expand Down Expand Up @@ -81,4 +82,9 @@ export class ServiceSetup {
this.languageSettings.yamlVersion = version;
return this;
}

withhoverSchemaSource(show: boolean): ServiceSetup {
this.languageSettings.hoverSchemaSource = show;
return this;
}
}
Loading