Skip to content

Commit 0402ed6

Browse files
authored
Wrapping code action title with string (#1117)
* Wrapping code action title with string * adding textedit value field wrapped as string
1 parent e0cd098 commit 0402ed6

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/languageservice/services/yamlCodeActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ export class YamlCodeActions {
351351
for (const value of values) {
352352
results.push(
353353
CodeAction.create(
354-
value,
355-
createWorkspaceEdit(document.uri, [TextEdit.replace(diagnostic.range, value)]),
354+
String(value),
355+
createWorkspaceEdit(document.uri, [TextEdit.replace(diagnostic.range, String(value))]),
356356
CodeActionKind.QuickFix
357357
)
358358
);

test/yamlCodeActions.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,5 +431,30 @@ animals: [dog , cat , mouse] `;
431431
expect(result.map((r) => r.title)).deep.equal(['fooX', 'fooY']);
432432
expect(result[0].edit.changes[TEST_URI]).deep.equal([TextEdit.replace(Range.create(0, 0, 0, 3), 'fooX')]);
433433
});
434+
435+
it('should generate proper action for enum mismatch, title converted to string value', () => {
436+
const doc = setupTextDocument('foo: value1');
437+
const diagnostic = createDiagnosticWithData(
438+
'message',
439+
0,
440+
5,
441+
0,
442+
11,
443+
DiagnosticSeverity.Hint,
444+
'YAML',
445+
'schemaUri',
446+
ErrorCode.EnumValueMismatch,
447+
{ values: [5, 10] }
448+
);
449+
const params: CodeActionParams = {
450+
context: CodeActionContext.create([diagnostic]),
451+
range: undefined,
452+
textDocument: TextDocumentIdentifier.create(TEST_URI),
453+
};
454+
const actions = new YamlCodeActions(clientCapabilities);
455+
const result = actions.getCodeAction(doc, params);
456+
expect(result.map((r) => r.title)).deep.equal(['5', '10']);
457+
expect(result[0].edit.changes[TEST_URI]).deep.equal([TextEdit.replace(Range.create(0, 5, 0, 11), '5')]);
458+
});
434459
});
435460
});

0 commit comments

Comments
 (0)