Skip to content

Commit ba42ae9

Browse files
author
Benjamin Pasero
committed
updateImportsOnFileMove is case-insensitive (fix microsoft#99690)
1 parent e3033fa commit ba42ae9

3 files changed

Lines changed: 29 additions & 49 deletions

File tree

src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE
136136

137137
// Move / Copy: remember models to restore after the operation
138138
if (e.operation === FileOperation.COPY || e.operation === FileOperation.MOVE) {
139-
140139
const modelsToRestore: { source: URI, target: URI, snapshot?: ITextSnapshot; mode?: string; encoding?: string; }[] = [];
141140

142141
for (const { source, target } of e.files) {
143142
if (source) {
143+
if (this.uriIdentityService.extUri.isEqual(source, target)) {
144+
continue; // ignore if resources are considered equal
145+
}
144146

145147
// find all models that related to either source or target (can be many if resource is a folder)
146148
const sourceModels: TextFileEditorModel[] = [];
@@ -200,7 +202,6 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE
200202
this.mapCorrelationIdToModelsToRestore.delete(e.correlationId);
201203

202204
modelsToRestore.forEach(model => {
203-
204205
// snapshot presence means this model used to be dirty and so we restore that
205206
// flag. we do NOT have to restore the content because the model was only soft
206207
// reverted and did not loose its original dirty contents.

src/vs/workbench/services/workingCopy/common/workingCopyFileService.ts

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -243,60 +243,40 @@ export class WorkingCopyFileService extends Disposable implements IWorkingCopyFi
243243
// file operation participant
244244
await this.runFileOperationParticipants(files, move ? FileOperation.MOVE : FileOperation.COPY);
245245

246-
// Before doing the heavy operations, check first if source and target
247-
// are either identical or are considered to be identical for the file
248-
// system. In that case we want the model to stay as is and only do the
249-
// raw file operation.
250-
const remainingFiles: SourceTargetPair[] = [];
251-
for (const { source, target } of files) {
252-
if (this.uriIdentityService.extUri.isEqual(source, target)) {
246+
// before event
247+
const event = { correlationId: this.correlationIds++, operation: move ? FileOperation.MOVE : FileOperation.COPY, files };
248+
await this._onWillRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None);
249+
250+
try {
251+
for (const { source, target } of files) {
252+
253+
// If source and target are not equal, handle dirty working copies
254+
// depending on the operation:
255+
// - move: revert both source and target (if any)
256+
// - copy: revert target (if any)
257+
if (!this.uriIdentityService.extUri.isEqual(source, target)) {
258+
const dirtyWorkingCopies = (move ? [...this.getDirty(source!), ...this.getDirty(target)] : this.getDirty(target));
259+
await Promise.all(dirtyWorkingCopies.map(dirtyWorkingCopy => dirtyWorkingCopy.revert({ soft: true })));
260+
}
261+
262+
// now we can rename the source to target via file operation
253263
if (move) {
254264
stats.push(await this.fileService.move(source!, target, overwrite));
255265
} else {
256266
stats.push(await this.fileService.copy(source!, target, overwrite));
257267
}
258-
} else {
259-
remainingFiles.push({ source, target });
260-
}
261-
}
262-
263-
// Now handle all the file operations that are not identical files
264-
if (remainingFiles.length > 0) {
265-
266-
// before event
267-
const event = { correlationId: this.correlationIds++, operation: move ? FileOperation.MOVE : FileOperation.COPY, files: remainingFiles };
268-
await this._onWillRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None);
269-
270-
271-
// handle dirty working copies depending on the operation:
272-
// - move: revert both source and target (if any)
273-
// - copy: revert target (if any)
274-
for (const { source, target } of remainingFiles) {
275-
const dirtyWorkingCopies = (move ? [...this.getDirty(source!), ...this.getDirty(target)] : this.getDirty(target));
276-
await Promise.all(dirtyWorkingCopies.map(dirtyWorkingCopy => dirtyWorkingCopy.revert({ soft: true })));
277268
}
269+
} catch (error) {
278270

279-
// now we can rename the source to target via file operation
280-
try {
281-
for (const { source, target } of remainingFiles) {
282-
if (move) {
283-
stats.push(await this.fileService.move(source!, target, overwrite));
284-
} else {
285-
stats.push(await this.fileService.copy(source!, target, overwrite));
286-
}
287-
}
288-
} catch (error) {
289-
290-
// error event
291-
await this._onDidFailWorkingCopyFileOperation.fireAsync(event, CancellationToken.None);
292-
293-
throw error;
294-
}
271+
// error event
272+
await this._onDidFailWorkingCopyFileOperation.fireAsync(event, CancellationToken.None);
295273

296-
// after event
297-
await this._onDidRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None);
274+
throw error;
298275
}
299276

277+
// after event
278+
await this._onDidRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None);
279+
300280
return stats;
301281
}
302282

src/vs/workbench/services/workingCopy/test/browser/workingCopyFileService.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ suite('WorkingCopyFileService', () => {
5050
const eventCounter = await testEventsMoveOrCopy([{ source: sourceModel.resource, target: sourceModel.resource }], true);
5151

5252
sourceModel.dispose();
53-
assert.equal(eventCounter, 1);
53+
assert.equal(eventCounter, 3);
5454
});
5555

5656
test('move - one source == target and another source != target', async function () {
@@ -94,7 +94,7 @@ suite('WorkingCopyFileService', () => {
9494
const eventCounter = await testEventsMoveOrCopy([{ source: sourceModel.resource, target: sourceModel.resource }]);
9595

9696
sourceModel.dispose();
97-
assert.equal(eventCounter, 1);
97+
assert.equal(eventCounter, 3);
9898
});
9999

100100
test('copy - one source == target and another source != target', async function () {
@@ -370,5 +370,4 @@ suite('WorkingCopyFileService', () => {
370370
listener1.dispose();
371371
listener2.dispose();
372372
}
373-
374373
});

0 commit comments

Comments
 (0)