@@ -13,7 +13,7 @@ import * as lsp from 'vscode-languageclient/node';
13
13
14
14
import { ProjectLoadingFinish , ProjectLoadingStart , SuggestStrictMode , SuggestStrictModeParams } from '../common/notifications' ;
15
15
import { NgccProgress , NgccProgressToken , NgccProgressType } from '../common/progress' ;
16
- import { GetComponentsWithTemplateFile , GetTcbRequest , IsInAngularProject } from '../common/requests' ;
16
+ import { GetComponentsWithTemplateFile , GetEditsForFileRenameParams , GetEditsForFileRenameRequest , GetTcbRequest , IsInAngularProject } from '../common/requests' ;
17
17
import { resolve , Version } from '../common/resolver' ;
18
18
19
19
import { isInsideComponentDecorator , isInsideInlineTemplateRegion , isInsideStringLiteral } from './embedded_support' ;
@@ -147,6 +147,42 @@ export class AngularLanguageClient implements vscode.Disposable {
147
147
}
148
148
}
149
149
} ;
150
+ vscode . workspace . onWillRenameFiles ( ( e : vscode . FileWillRenameEvent ) => {
151
+ if ( ! this . client ) {
152
+ return ;
153
+ }
154
+
155
+ const c2pConverter = this . client . code2ProtocolConverter ;
156
+ const requests : Array < Promise < lsp . WorkspaceEdit | null > > = [ ] ;
157
+ for ( let f of e . files ) {
158
+ requests . push ( this . client . sendRequest ( GetEditsForFileRenameRequest , {
159
+ oldUri : c2pConverter . asUri ( f . oldUri ) ,
160
+ newUri : c2pConverter . asUri ( f . newUri ) ,
161
+ } ) ) ;
162
+ }
163
+ const response = Promise . all ( requests ) . then ( allEdits => {
164
+ const final : lsp . WorkspaceEdit = { } ;
165
+ for ( const edit of allEdits ) {
166
+ if ( ! edit ) {
167
+ continue ;
168
+ }
169
+ final . changes = { ...final . changes , ...edit . changes } ;
170
+ if ( edit . documentChanges && edit . documentChanges . length > 0 ) {
171
+ if ( ! final . documentChanges ) {
172
+ final . documentChanges = [ ] ;
173
+ }
174
+ final . documentChanges . push ( ...edit . documentChanges ) ;
175
+ }
176
+ final . changeAnnotations = { ...final . changeAnnotations , ...edit . changeAnnotations } ;
177
+ }
178
+ if ( ! final . changeAnnotations && ! final . changes && ! final . documentChanges ) {
179
+ return undefined ;
180
+ }
181
+ const p2cConverter = this . client ! . protocol2CodeConverter ;
182
+ return p2cConverter . asWorkspaceEdit ( final ) ;
183
+ } )
184
+ e . waitUntil ( response ) ;
185
+ } ) ;
150
186
}
151
187
152
188
private async isInAngularProject ( doc : vscode . TextDocument ) : Promise < boolean > {
0 commit comments