Skip to content

Commit 8ac2c23

Browse files
committed
Don't force convert fixable diagnostics to numbers
Fixes #64848 for the VS Code side
1 parent 45c34a2 commit 8ac2c23

File tree

1 file changed

+10
-13
lines changed
  • extensions/typescript-language-features/src/features

1 file changed

+10
-13
lines changed

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import * as nls from 'vscode-nls';
88
import * as Proto from '../protocol';
99
import { ITypeScriptServiceClient } from '../typescriptService';
1010
import API from '../utils/api';
11+
import { nulToken } from '../utils/cancellation';
1112
import { applyCodeActionCommands, getEditForCodeAction } from '../utils/codeAction';
1213
import { Command, CommandManager } from '../utils/commandManager';
1314
import { VersionDependentRegistration } from '../utils/dependentRegistration';
15+
import { memoize } from '../utils/memoize';
1416
import TelemetryReporter from '../utils/telemetry';
1517
import * as typeConverters from '../utils/typeConverters';
1618
import { DiagnosticsManager } from './diagnostics';
1719
import FileConfigurationManager from './fileConfigurationManager';
18-
import { nulToken } from '../utils/cancellation';
1920

2021
const localize = nls.loadMessageBundle();
2122

@@ -154,25 +155,21 @@ class CodeActionSet {
154155
}
155156

156157
class SupportedCodeActionProvider {
157-
private _supportedCodeActions?: Thenable<Set<number>>;
158-
159158
public constructor(
160159
private readonly client: ITypeScriptServiceClient
161160
) { }
162161

163162
public async getFixableDiagnosticsForContext(context: vscode.CodeActionContext): Promise<DiagnosticsSet> {
164-
const supportedActions = await this.supportedCodeActions;
165-
return DiagnosticsSet.from(context.diagnostics.filter(diagnostic => supportedActions.has(+(diagnostic.code!))));
163+
const fixableCodes = await this.fixableDiagnosticCodes;
164+
return DiagnosticsSet.from(
165+
context.diagnostics.filter(diagnostic => typeof diagnostic.code !== 'undefined' && fixableCodes.has(diagnostic.code + '')));
166166
}
167167

168-
private get supportedCodeActions(): Thenable<Set<number>> {
169-
if (!this._supportedCodeActions) {
170-
this._supportedCodeActions = this.client.execute('getSupportedCodeFixes', null, nulToken)
171-
.then(response => response.type === 'response' ? response.body || [] : [])
172-
.then(codes => codes.map(code => +code).filter(code => !isNaN(code)))
173-
.then(codes => new Set(codes));
174-
}
175-
return this._supportedCodeActions;
168+
@memoize
169+
private get fixableDiagnosticCodes(): Thenable<Set<string>> {
170+
return this.client.execute('getSupportedCodeFixes', null, nulToken)
171+
.then(response => response.type === 'response' ? response.body || [] : [])
172+
.then(codes => new Set(codes));
176173
}
177174
}
178175

0 commit comments

Comments
 (0)