Skip to content

Commit 85a336c

Browse files
committed
Only return single ts-ignore action if there are multiple errors on one line
Fixes microsoft#97867
1 parent 990eb06 commit 85a336c

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

extensions/typescript-language-features/src/features/quickFix.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { TelemetryReporter } from '../utils/telemetry';
1717
import * as typeConverters from '../utils/typeConverters';
1818
import { DiagnosticsManager } from './diagnostics';
1919
import FileConfigurationManager from './fileConfigurationManager';
20+
import { equals } from '../utils/objects';
2021

2122
const localize = nls.loadMessageBundle();
2223

@@ -147,6 +148,11 @@ class CodeActionSet {
147148
}
148149

149150
public addAction(action: VsCodeCodeAction) {
151+
for (const existing of this._actions) {
152+
if (action.tsAction.fixName === existing.tsAction.fixName && equals(action.edit, existing.edit)) {
153+
this._actions.delete(existing);
154+
}
155+
}
150156
this._actions.add(action);
151157
}
152158

extensions/typescript-language-features/src/test/quickFix.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ suite('TypeScript Quick Fix', () => {
8787
`foo;`
8888
));
8989
});
90+
91+
test('Only a single ts-ignore should be returned if there are multiple errors on one line #98274', async () => {
92+
const testDocumentUri = workspaceFile('foojs.js');
93+
const editor = await createTestEditor(testDocumentUri,
94+
`//@ts-check`,
95+
`const a = require('./bla');`);
96+
97+
await wait(3000);
98+
99+
const fixes = await vscode.commands.executeCommand<vscode.CodeAction[]>('vscode.executeCodeActionProvider',
100+
testDocumentUri,
101+
editor.document.lineAt(1).range
102+
);
103+
104+
const ignoreFixes = fixes?.filter(x => x.title === 'Ignore this error message');
105+
assert.strictEqual(ignoreFixes?.length, 1);
106+
});
90107
});
91108

92109

extensions/typescript-language-features/test-workspace/foojs.js

Whitespace-only changes.

0 commit comments

Comments
 (0)