@@ -315,19 +315,21 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
315315 if ( token . isCancellationRequested ) {
316316 return item ;
317317 }
318- const docChanges = result . edit . documentChanges ;
319- for ( const editType of docChanges ) {
320- if ( "textDocument" in editType ) {
321- for ( const edit of editType . edits ) {
322- if ( "snippet" in edit ) {
323- documentUris . push ( editType . textDocument . uri ) ;
324- snippetEdits . push ( new SnippetTextEdit ( asRange ( ( edit as any ) . range ) , new SnippetString ( ( edit as any ) . snippet . value ) ) ) ;
318+ const docChanges = result . edit !== undefined ? result . edit . documentChanges : undefined ;
319+ if ( docChanges !== undefined ) {
320+ for ( const editType of docChanges ) {
321+ if ( "textDocument" in editType ) {
322+ for ( const edit of editType . edits ) {
323+ if ( "snippet" in edit ) {
324+ documentUris . push ( editType . textDocument . uri ) ;
325+ snippetEdits . push ( new SnippetTextEdit ( asRange ( ( edit as any ) . range ) , new SnippetString ( ( edit as any ) . snippet . value ) ) ) ;
326+ }
325327 }
326328 }
327329 }
328330 }
329331 const codeAction = await client . protocol2CodeConverter . asCodeAction ( result , token ) ;
330- const docEdits = codeAction . edit . entries ( ) ;
332+ const docEdits = codeAction . edit !== undefined ? codeAction . edit . entries ( ) : [ ] ;
331333 const newWorkspaceEdit = new WorkspaceEdit ( ) ;
332334 for ( const doc of docEdits ) {
333335 const uri = doc [ 0 ] ;
@@ -350,7 +352,9 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
350352 newWorkspaceEdit . set ( uri , doc [ 1 ] ) ;
351353 }
352354 }
353- codeAction . edit = newWorkspaceEdit ;
355+ if ( newWorkspaceEdit . size > 0 ) {
356+ codeAction . edit = newWorkspaceEdit ;
357+ }
354358 return codeAction ;
355359 } , ( error ) => {
356360 return client . handleFailedRequest ( CodeActionResolveRequest . type , token , error , item ) ;
0 commit comments