Skip to content

Commit cecc0e4

Browse files
remcohaszingevidolob
authored andcommitted
Remove data from unused anchor diagnostics
The anchor name was added as custom data. It’s unnecessary, because the name of the anchor can be determined from other values in the place where it’s used. Because Monaco Editor marker data doesn’t support custom data, this blocks support code actions in monaco-yaml.
1 parent 77e2f6c commit cecc0e4

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

src/languageservice/services/validation/unused-anchors.ts

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class UnusedAnchorsValidator implements AdditionalValidator {
4141
);
4242
const warningDiagnostic = Diagnostic.create(range, `Unused anchor "${aToken.source}"`, DiagnosticSeverity.Hint, 0);
4343
warningDiagnostic.tags = [DiagnosticTag.Unnecessary];
44-
warningDiagnostic.data = { name: aToken.source };
4544
result.push(warningDiagnostic);
4645
}
4746
}

src/languageservice/services/yamlCodeActions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ export class YamlCodeActions {
172172
const buffer = new TextBuffer(document);
173173
for (const diag of diagnostics) {
174174
if (diag.message.startsWith('Unused anchor') && diag.source === YAML_SOURCE) {
175-
const { name } = diag.data as { name: string };
176175
const range = Range.create(diag.range.start, diag.range.end);
176+
const actual = buffer.getText(range);
177177
const lineContent = buffer.getLineContent(range.end.line);
178178
const lastWhitespaceChar = getFirstNonWhitespaceCharacterAfterOffset(lineContent, range.end.character);
179179
range.end.character = lastWhitespaceChar;
180180
const action = CodeAction.create(
181-
`Delete unused anchor: ${name}`,
181+
`Delete unused anchor: ${actual}`,
182182
createWorkspaceEdit(document.uri, [TextEdit.del(range)]),
183183
CodeActionKind.QuickFix
184184
);

test/utils/verifyError.ts

-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export function createDiagnosticWithData(
3737

3838
export function createUnusedAnchorDiagnostic(
3939
message: string,
40-
name: string,
4140
startLine: number,
4241
startCharacter: number,
4342
endLine: number,
@@ -53,7 +52,6 @@ export function createUnusedAnchorDiagnostic(
5352
'YAML'
5453
);
5554
diagnostic.tags = [DiagnosticTag.Unnecessary];
56-
diagnostic.data = { name };
5755
return diagnostic;
5856
}
5957

test/yamlCodeActions.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('CodeActions Tests', () => {
158158
describe('Remove Unused Anchor', () => {
159159
it('should generate proper action', () => {
160160
const doc = setupTextDocument('foo: &bar bar\n');
161-
const diagnostics = [createUnusedAnchorDiagnostic('Unused anchor "&bar"', '&bar', 0, 5, 0, 9)];
161+
const diagnostics = [createUnusedAnchorDiagnostic('Unused anchor "&bar"', 0, 5, 0, 9)];
162162
const params: CodeActionParams = {
163163
context: CodeActionContext.create(diagnostics),
164164
range: undefined,
@@ -172,7 +172,7 @@ describe('CodeActions Tests', () => {
172172

173173
it('should delete all whitespace after unused anchor', () => {
174174
const doc = setupTextDocument('foo: &bar \tbar\n');
175-
const diagnostics = [createUnusedAnchorDiagnostic('Unused anchor "&bar"', '&bar', 0, 5, 0, 9)];
175+
const diagnostics = [createUnusedAnchorDiagnostic('Unused anchor "&bar"', 0, 5, 0, 9)];
176176
const params: CodeActionParams = {
177177
context: CodeActionContext.create(diagnostics),
178178
range: undefined,

test/yamlValidation.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('YAML Validation Tests', () => {
6161
const result = await parseSetup(yaml);
6262
expect(result).is.not.empty;
6363
expect(result.length).to.be.equal(1);
64-
expect(result[0]).deep.equal(createUnusedAnchorDiagnostic('Unused anchor "&bar"', '&bar', 0, 5, 0, 9));
64+
expect(result[0]).deep.equal(createUnusedAnchorDiagnostic('Unused anchor "&bar"', 0, 5, 0, 9));
6565
});
6666

6767
it('should not report used anchor', async () => {
@@ -85,10 +85,10 @@ some:
8585
expect(result).is.not.empty;
8686
expect(result.length).to.be.equal(4);
8787
expect(result).to.include.deep.members([
88-
createUnusedAnchorDiagnostic('Unused anchor "&bar"', '&bar', 0, 5, 0, 9),
89-
createUnusedAnchorDiagnostic('Unused anchor "&a"', '&a', 4, 2, 4, 4),
90-
createUnusedAnchorDiagnostic('Unused anchor "&aa"', '&aa', 5, 0, 5, 3),
91-
createUnusedAnchorDiagnostic('Unused anchor "&e"', '&e', 8, 4, 8, 6),
88+
createUnusedAnchorDiagnostic('Unused anchor "&bar"', 0, 5, 0, 9),
89+
createUnusedAnchorDiagnostic('Unused anchor "&a"', 4, 2, 4, 4),
90+
createUnusedAnchorDiagnostic('Unused anchor "&aa"', 5, 0, 5, 3),
91+
createUnusedAnchorDiagnostic('Unused anchor "&e"', 8, 4, 8, 6),
9292
]);
9393
});
9494
});

0 commit comments

Comments
 (0)