Only return single ts-ignore action if there are multiple errors on one line

Fixes #97867
pull/98340/head
Matt Bierner 2020-05-20 15:15:32 -07:00
parent 990eb06cfe
commit 85a336c885
3 changed files with 23 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import { TelemetryReporter } from '../utils/telemetry';
import * as typeConverters from '../utils/typeConverters';
import { DiagnosticsManager } from './diagnostics';
import FileConfigurationManager from './fileConfigurationManager';
import { equals } from '../utils/objects';
const localize = nls.loadMessageBundle();
@ -147,6 +148,11 @@ class CodeActionSet {
}
public addAction(action: VsCodeCodeAction) {
for (const existing of this._actions) {
if (action.tsAction.fixName === existing.tsAction.fixName && equals(action.edit, existing.edit)) {
this._actions.delete(existing);
}
}
this._actions.add(action);
}

View File

@ -87,6 +87,23 @@ suite('TypeScript Quick Fix', () => {
`foo;`
));
});
test('Only a single ts-ignore should be returned if there are multiple errors on one line #98274', async () => {
const testDocumentUri = workspaceFile('foojs.js');
const editor = await createTestEditor(testDocumentUri,
`//@ts-check`,
`const a = require('./bla');`);
await wait(3000);
const fixes = await vscode.commands.executeCommand<vscode.CodeAction[]>('vscode.executeCodeActionProvider',
testDocumentUri,
editor.document.lineAt(1).range
);
const ignoreFixes = fixes?.filter(x => x.title === 'Ignore this error message');
assert.strictEqual(ignoreFixes?.length, 1);
});
});