Skip to content

Commit b76a221

Browse files
msivasubramaniaandatho7561
authored andcommitted
show the matching value on top
1 parent c94fa43 commit b76a221

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

src/languageservice/jsonSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface JSONSchema {
4949
not?: JSONSchemaRef;
5050
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5151
enum?: any[];
52+
enumMarkdown?: any[];
5253
format?: string;
5354

5455
// schema draft 06

src/languageservice/services/yamlHover.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { setKubernetesParserOption } from '../parser/isKubernetes';
1212
import { TextDocument } from 'vscode-languageserver-textdocument';
1313
import { yamlDocumentsCache } from '../parser/yaml-documents';
1414
import { SingleYAMLDocument } from '../parser/yamlParser07';
15-
import { IApplicableSchema } from '../parser/jsonParser07';
15+
import { getNodeValue, IApplicableSchema } from '../parser/jsonParser07';
1616
import { JSONSchema } from '../jsonSchema';
1717
import { URI } from 'vscode-uri';
1818
import * as path from 'path';
@@ -114,14 +114,17 @@ export class YAMLHover {
114114
let markdownEnumDescriptions: string[] = [];
115115
const markdownExamples: string[] = [];
116116
const markdownEnums: markdownEnum[] = [];
117-
117+
let enumIdx: number | undefined = undefined;
118118
matchingSchemas.every((s) => {
119119
if ((s.node === node || (node.type === 'property' && node.valueNode === s.node)) && !s.inverted && s.schema) {
120120
title = title || s.schema.title || s.schema.closestTitle;
121121
markdownDescription = markdownDescription || s.schema.markdownDescription || this.toMarkdown(s.schema.description);
122122
if (s.schema.enum) {
123+
enumIdx = s.schema.enum.indexOf(getNodeValue(node));
123124
if (s.schema.markdownEnumDescriptions) {
124125
markdownEnumDescriptions = s.schema.markdownEnumDescriptions;
126+
} else if (s.schema.enumMarkdown) {
127+
markdownEnumDescriptions = s.schema.enumMarkdown;
125128
} else if (s.schema.enumDescriptions) {
126129
markdownEnumDescriptions = s.schema.enumDescriptions.map(this.toMarkdown, this);
127130
} else {
@@ -174,6 +177,9 @@ export class YAMLHover {
174177
if (markdownEnums.length !== 0) {
175178
result = ensureLineBreak(result);
176179
result += 'Allowed Values:\n\n';
180+
if (enumIdx) {
181+
markdownEnums.unshift(markdownEnums.splice(enumIdx, 1)[0]);
182+
}
177183
markdownEnums.forEach((me) => {
178184
if (me.description) {
179185
result += `* \`${toMarkdownCodeBlock(me.value)}\`: ${me.description}\n`;

test/hover.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,9 @@ Source: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
617617
618618
Allowed Values:
619619
620+
* \`non\`
620621
* \`cat\`
621622
* \`dog\`: Canis familiaris
622-
* \`non\`
623623
* \`bird\`
624624
* \`fish\`: Special fish
625625

test/yamlValidation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('YAML Validation Tests', () => {
5555
});
5656

5757
it('Should allow proper space indentation followed by tab', async () => {
58-
const yaml = 'foo:\n \tbar';
58+
const yaml = 'foo:\n bar';
5959
const result = await parseSetup(yaml);
6060
expect(result).to.be.empty;
6161
});

0 commit comments

Comments
 (0)