@@ -8,14 +8,15 @@ import * as nls from 'vscode-nls';
8
8
import * as Proto from '../protocol' ;
9
9
import { ITypeScriptServiceClient } from '../typescriptService' ;
10
10
import API from '../utils/api' ;
11
+ import { nulToken } from '../utils/cancellation' ;
11
12
import { applyCodeActionCommands , getEditForCodeAction } from '../utils/codeAction' ;
12
13
import { Command , CommandManager } from '../utils/commandManager' ;
13
14
import { VersionDependentRegistration } from '../utils/dependentRegistration' ;
15
+ import { memoize } from '../utils/memoize' ;
14
16
import TelemetryReporter from '../utils/telemetry' ;
15
17
import * as typeConverters from '../utils/typeConverters' ;
16
18
import { DiagnosticsManager } from './diagnostics' ;
17
19
import FileConfigurationManager from './fileConfigurationManager' ;
18
- import { nulToken } from '../utils/cancellation' ;
19
20
20
21
const localize = nls . loadMessageBundle ( ) ;
21
22
@@ -154,25 +155,21 @@ class CodeActionSet {
154
155
}
155
156
156
157
class SupportedCodeActionProvider {
157
- private _supportedCodeActions ?: Thenable < Set < number > > ;
158
-
159
158
public constructor (
160
159
private readonly client : ITypeScriptServiceClient
161
160
) { }
162
161
163
162
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 + '' ) ) ) ;
166
166
}
167
167
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 ) ) ;
176
173
}
177
174
}
178
175
0 commit comments