@@ -7,13 +7,11 @@ import * as vscode from 'vscode';
77import { OmniSharpServer } from '../omnisharp/server' ;
88import AbstractProvider from './abstractProvider' ;
99import * as protocol from '../omnisharp/protocol' ;
10- import { toRange2 } from '../omnisharp/typeConversion' ;
1110import * as serverUtils from '../omnisharp/utils' ;
12- import { FileModificationType } from '../omnisharp/protocol' ;
13- import { Uri } from 'vscode' ;
1411import CompositeDisposable from '../CompositeDisposable' ;
1512import OptionProvider from '../observers/OptionProvider' ;
1613import { LanguageMiddlewareFeature } from '../omnisharp/LanguageMiddlewareFeature' ;
14+ import { buildEditForResponse } from '../omnisharp/fileOperationsResponseEditBuilder' ;
1715
1816export default class CodeActionProvider extends AbstractProvider implements vscode . CodeActionProvider {
1917
@@ -84,7 +82,8 @@ export default class CodeActionProvider extends AbstractProvider implements vsco
8482 Selection : selection ,
8583 Identifier : codeAction . Identifier ,
8684 WantsTextChanges : true ,
87- WantsAllCodeActionOperations : true
85+ WantsAllCodeActionOperations : true ,
86+ ApplyTextChanges : false
8887 } ;
8988
9089 return {
@@ -101,80 +100,12 @@ export default class CodeActionProvider extends AbstractProvider implements vsco
101100
102101 private async _runCodeAction ( req : protocol . V2 . RunCodeActionRequest , token : vscode . CancellationToken ) : Promise < boolean | string | { } > {
103102
104- return serverUtils . runCodeAction ( this . _server , req ) . then ( async response => {
105- if ( response && Array . isArray ( response . Changes ) ) {
106-
107- let edit = new vscode . WorkspaceEdit ( ) ;
108-
109- let fileToOpen : Uri = null ;
110- let renamedFiles : Uri [ ] = [ ] ;
111-
112- for ( let change of response . Changes ) {
113- if ( change . ModificationType == FileModificationType . Renamed )
114- {
115- // The file was renamed. Omnisharp has already persisted
116- // the right changes to disk. We don't need to try to
117- // apply text changes (and will skip this file if we see an edit)
118- renamedFiles . push ( Uri . file ( change . FileName ) ) ;
119- }
120- }
121-
122- for ( let change of response . Changes ) {
123- if ( change . ModificationType == FileModificationType . Opened )
124- {
125- // The CodeAction requested that we open a file.
126- // Record that file name and keep processing CodeActions.
127- // If a CodeAction requests that we open multiple files
128- // we only open the last one (what would it mean to open multiple files?)
129- fileToOpen = vscode . Uri . file ( change . FileName ) ;
130- }
131-
132- if ( change . ModificationType == FileModificationType . Modified )
133- {
134- let uri = vscode . Uri . file ( change . FileName ) ;
135- if ( renamedFiles . some ( r => r == uri ) )
136- {
137- // This file got renamed. OmniSharp has already
138- // persisted the new file with any applicable changes.
139- continue ;
140- }
141-
142- let edits : vscode . TextEdit [ ] = [ ] ;
143- for ( let textChange of change . Changes ) {
144- edits . push ( vscode . TextEdit . replace ( toRange2 ( textChange ) , textChange . NewText ) ) ;
145- }
146-
147- edit . set ( uri , edits ) ;
148- }
149- }
150-
151- // Allow language middlewares to re-map its edits if necessary.
152- edit = await this . _languageMiddlewareFeature . remap ( "remapWorkspaceEdit" , edit , token ) ;
153-
154- let applyEditPromise = vscode . workspace . applyEdit ( edit ) ;
155-
156- // Unfortunately, the textEditor.Close() API has been deprecated
157- // and replaced with a command that can only close the active editor.
158- // If files were renamed that weren't the active editor, their tabs will
159- // be left open and marked as "deleted" by VS Code
160- let next = applyEditPromise ;
161- if ( renamedFiles . some ( r => r . fsPath == vscode . window . activeTextEditor . document . uri . fsPath ) )
162- {
163- next = applyEditPromise . then ( _ =>
164- {
165- return vscode . commands . executeCommand ( "workbench.action.closeActiveEditor" ) ;
166- } ) ;
167- }
168-
169- return fileToOpen != null
170- ? next . then ( _ =>
171- {
172- return vscode . commands . executeCommand ( "vscode.open" , fileToOpen ) ;
173- } )
174- : next ;
175- }
176- } , async ( error ) => {
103+ return serverUtils . runCodeAction ( this . _server , req ) . then ( response => {
104+ if ( response ) {
105+ return buildEditForResponse ( response . Changes , this . _languageMiddlewareFeature , token ) ;
106+ }
107+ } , async ( error ) => {
177108 return Promise . reject ( `Problem invoking 'RunCodeAction' on OmniSharp server: ${ error } ` ) ;
178109 } ) ;
179110 }
180- }
111+ }
0 commit comments