@@ -20,19 +20,23 @@ import * as typeConverters from '../utils/typeConverters';
2020import { DiagnosticsManager } from './diagnostics' ;
2121import FileConfigurationManager from './fileConfigurationManager' ;
2222
23+ type ApplyCodeActionCommand_args = {
24+ readonly resource : vscode . Uri ;
25+ readonly diagnostic : vscode . Diagnostic ;
26+ readonly action : Proto . CodeFixAction ;
27+ } ;
2328
2429class ApplyCodeActionCommand implements Command {
2530 public static readonly ID = '_typescript.applyCodeActionCommand' ;
2631 public readonly id = ApplyCodeActionCommand . ID ;
2732
2833 constructor (
2934 private readonly client : ITypeScriptServiceClient ,
35+ private readonly diagnosticManager : DiagnosticsManager ,
3036 private readonly telemetryReporter : TelemetryReporter ,
3137 ) { }
3238
33- public async execute (
34- action : Proto . CodeFixAction
35- ) : Promise < boolean > {
39+ public async execute ( { resource, action, diagnostic } : ApplyCodeActionCommand_args ) : Promise < boolean > {
3640 /* __GDPR__
3741 "quickFix.execute" : {
3842 "owner": "mjbvz",
@@ -46,6 +50,7 @@ class ApplyCodeActionCommand implements Command {
4650 fixName : action . fixName
4751 } ) ;
4852
53+ this . diagnosticManager . deleteDiagnostic ( resource , diagnostic ) ;
4954 return applyCodeActionCommands ( this . client , action . commands , nulToken ) ;
5055 }
5156}
@@ -212,7 +217,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
212217 private readonly diagnosticsManager : DiagnosticsManager ,
213218 telemetryReporter : TelemetryReporter
214219 ) {
215- commandManager . register ( new ApplyCodeActionCommand ( client , telemetryReporter ) ) ;
220+ commandManager . register ( new ApplyCodeActionCommand ( client , diagnosticsManager , telemetryReporter ) ) ;
216221 commandManager . register ( new ApplyFixAllCodeAction ( client , telemetryReporter ) ) ;
217222
218223 this . supportedCodeActionProvider = new SupportedCodeActionProvider ( client ) ;
@@ -223,26 +228,32 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
223228 _range : vscode . Range ,
224229 context : vscode . CodeActionContext ,
225230 token : vscode . CancellationToken
226- ) : Promise < VsCodeCodeAction [ ] > {
231+ ) : Promise < VsCodeCodeAction [ ] | undefined > {
227232 const file = this . client . toOpenedFilePath ( document ) ;
228233 if ( ! file ) {
229- return [ ] ;
234+ return ;
230235 }
231236
232237 const fixableDiagnostics = await this . supportedCodeActionProvider . getFixableDiagnosticsForContext ( context ) ;
233- if ( ! fixableDiagnostics . size ) {
234- return [ ] ;
238+ if ( ! fixableDiagnostics . size || token . isCancellationRequested ) {
239+ return ;
235240 }
236241
237242 if ( this . client . bufferSyncSupport . hasPendingDiagnostics ( document . uri ) ) {
238- return [ ] ;
243+ return ;
239244 }
240245
241246 await this . formattingConfigurationManager . ensureConfigurationForDocument ( document , token ) ;
247+ if ( token . isCancellationRequested ) {
248+ return ;
249+ }
242250
243251 const results = new CodeActionSet ( ) ;
244252 for ( const diagnostic of fixableDiagnostics . values ) {
245253 await this . getFixesForDiagnostic ( document , file , diagnostic , results , token ) ;
254+ if ( token . isCancellationRequested ) {
255+ return ;
256+ }
246257 }
247258
248259 const allActions = Array . from ( results . values ) ;
@@ -303,12 +314,13 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
303314 diagnostic : vscode . Diagnostic ,
304315 tsAction : Proto . CodeFixAction
305316 ) : CodeActionSet {
306- results . addAction ( this . getSingleFixForTsCodeAction ( diagnostic , tsAction ) ) ;
307- this . addFixAllForTsCodeAction ( results , document , file , diagnostic , tsAction as Proto . CodeFixAction ) ;
317+ results . addAction ( this . getSingleFixForTsCodeAction ( document . uri , diagnostic , tsAction ) ) ;
318+ this . addFixAllForTsCodeAction ( results , document . uri , file , diagnostic , tsAction as Proto . CodeFixAction ) ;
308319 return results ;
309320 }
310321
311322 private getSingleFixForTsCodeAction (
323+ resource : vscode . Uri ,
312324 diagnostic : vscode . Diagnostic ,
313325 tsAction : Proto . CodeFixAction
314326 ) : VsCodeCodeAction {
@@ -317,15 +329,15 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
317329 codeAction . diagnostics = [ diagnostic ] ;
318330 codeAction . command = {
319331 command : ApplyCodeActionCommand . ID ,
320- arguments : [ tsAction ] ,
332+ arguments : [ < ApplyCodeActionCommand_args > { action : tsAction , diagnostic , resource } ] ,
321333 title : ''
322334 } ;
323335 return codeAction ;
324336 }
325337
326338 private addFixAllForTsCodeAction (
327339 results : CodeActionSet ,
328- document : vscode . TextDocument ,
340+ resource : vscode . Uri ,
329341 file : string ,
330342 diagnostic : vscode . Diagnostic ,
331343 tsAction : Proto . CodeFixAction ,
@@ -335,7 +347,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
335347 }
336348
337349 // Make sure there are multiple diagnostics of the same type in the file
338- if ( ! this . diagnosticsManager . getDiagnostics ( document . uri ) . some ( x => {
350+ if ( ! this . diagnosticsManager . getDiagnostics ( resource ) . some ( x => {
339351 if ( x === diagnostic ) {
340352 return false ;
341353 }
0 commit comments