Skip to content

Commit 2f4fdec

Browse files
authored
debt - rename markDirty to markModified (fix microsoft#182977) (microsoft#183146)
debt - rename `markDirty` to `markModified`
1 parent 70cb2a2 commit 2f4fdec

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ export interface IStoredFileWorkingCopy<M extends IStoredFileWorkingCopyModel> e
117117
resolve(options?: IStoredFileWorkingCopyResolveOptions): Promise<void>;
118118

119119
/**
120-
* Explicitly sets the working copy to be dirty.
120+
* Explicitly sets the working copy to be modified.
121121
*/
122-
markDirty(): void;
122+
markModified(): void;
123123

124124
/**
125125
* Whether the stored file working copy is in the provided `state`
@@ -349,8 +349,8 @@ export class StoredFileWorkingCopy<M extends IStoredFileWorkingCopyModel> extend
349349
return this.dirty;
350350
}
351351

352-
markDirty(): void {
353-
this.setDirty(true);
352+
markModified(): void {
353+
this.setDirty(true); // stored file working copy tracks modified via dirty
354354
}
355355

356356
private setDirty(dirty: boolean): void {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,16 @@ export class StoredFileWorkingCopyManager<M extends IStoredFileWorkingCopyModel>
371371
if (workingCopiesToRestore) {
372372
this.mapCorrelationIdToWorkingCopiesToRestore.delete(e.correlationId);
373373

374-
workingCopiesToRestore.forEach(workingCopy => {
374+
for (const workingCopy of workingCopiesToRestore) {
375375

376-
// Snapshot presence means this working copy used to be dirty and so we restore that
376+
// Snapshot presence means this working copy used to be modified and so we restore that
377377
// flag. we do NOT have to restore the content because the working copy was only soft
378-
// reverted and did not loose its original dirty contents.
378+
// reverted and did not loose its original modified contents.
379+
379380
if (workingCopy.snapshot) {
380-
this.get(workingCopy.source)?.markDirty();
381+
this.get(workingCopy.source)?.markModified();
381382
}
382-
});
383+
}
383384
}
384385
}
385386
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ export interface IUntitledFileWorkingCopyInitialContents {
8282

8383
/**
8484
* If not provided, the untitled file working copy will be marked
85-
* dirty by default given initial contents are provided.
85+
* modified by default given initial contents are provided.
8686
*
8787
* Note: if the untitled file working copy has an associated path
88-
* the dirty state will always be set.
88+
* the modified state will always be set.
8989
*/
90-
readonly markDirty?: boolean;
90+
readonly markModified?: boolean;
9191
}
9292

9393
export class UntitledFileWorkingCopy<M extends IUntitledFileWorkingCopyModel> extends Disposable implements IUntitledFileWorkingCopy<M> {
@@ -137,7 +137,7 @@ export class UntitledFileWorkingCopy<M extends IUntitledFileWorkingCopyModel> ex
137137

138138
//#region Dirty
139139

140-
private modified = this.hasAssociatedFilePath || Boolean(this.initialContents && this.initialContents.markDirty !== false);
140+
private modified = this.hasAssociatedFilePath || Boolean(this.initialContents && this.initialContents.markModified !== false);
141141

142142
isDirty(): boolean {
143143
return this.modified && !this.isScratchpad; // Scratchpad working copies are never dirty
@@ -197,7 +197,7 @@ export class UntitledFileWorkingCopy<M extends IUntitledFileWorkingCopyModel> ex
197197
await this.doCreateModel(untitledContents);
198198

199199
// Untitled associated to file path are modified right away as well as untitled with content
200-
this.setModified(this.hasAssociatedFilePath || !!backup || Boolean(this.initialContents && this.initialContents.markDirty !== false));
200+
this.setModified(this.hasAssociatedFilePath || !!backup || Boolean(this.initialContents && this.initialContents.markModified !== false));
201201

202202
// If we have initial contents, make sure to emit this
203203
// as the appropriate events to the outside.

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ suite('StoredFileWorkingCopy', function () {
146146
});
147147
});
148148

149-
test('dirty', async () => {
149+
test('dirty / modified', async () => {
150+
assert.strictEqual(workingCopy.isModified(), false);
150151
assert.strictEqual(workingCopy.isDirty(), false);
151152
assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.DIRTY), false);
152153

@@ -172,12 +173,14 @@ suite('StoredFileWorkingCopy', function () {
172173
workingCopy.model?.updateContents('hello dirty');
173174
assert.strictEqual(contentChangeCounter, 1);
174175

176+
assert.strictEqual(workingCopy.isModified(), true);
175177
assert.strictEqual(workingCopy.isDirty(), true);
176178
assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.DIRTY), true);
177179
assert.strictEqual(changeDirtyCounter, 1);
178180

179181
await workingCopy.save();
180182

183+
assert.strictEqual(workingCopy.isModified(), false);
181184
assert.strictEqual(workingCopy.isDirty(), false);
182185
assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.DIRTY), false);
183186
assert.strictEqual(changeDirtyCounter, 2);
@@ -187,25 +190,29 @@ suite('StoredFileWorkingCopy', function () {
187190
await workingCopy.resolve({ contents: bufferToStream(VSBuffer.fromString('hello dirty stream')) });
188191

189192
assert.strictEqual(contentChangeCounter, 2); // content of model did not change
193+
assert.strictEqual(workingCopy.isModified(), true);
190194
assert.strictEqual(workingCopy.isDirty(), true);
191195
assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.DIRTY), true);
192196
assert.strictEqual(changeDirtyCounter, 3);
193197

194198
await workingCopy.revert({ soft: true });
195199

200+
assert.strictEqual(workingCopy.isModified(), false);
196201
assert.strictEqual(workingCopy.isDirty(), false);
197202
assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.DIRTY), false);
198203
assert.strictEqual(changeDirtyCounter, 4);
199204

200-
// Dirty from: API
201-
workingCopy.markDirty();
205+
// Modified from: API
206+
workingCopy.markModified();
202207

208+
assert.strictEqual(workingCopy.isModified(), true);
203209
assert.strictEqual(workingCopy.isDirty(), true);
204210
assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.DIRTY), true);
205211
assert.strictEqual(changeDirtyCounter, 5);
206212

207213
await workingCopy.revert();
208214

215+
assert.strictEqual(workingCopy.isModified(), false);
209216
assert.strictEqual(workingCopy.isDirty(), false);
210217
assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.DIRTY), false);
211218
assert.strictEqual(changeDirtyCounter, 6);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,16 @@ suite('UntitledFileWorkingCopyManager', () => {
157157

158158
const workingCopy1 = await manager.untitled.resolve({ contents: { value: bufferToStream(VSBuffer.fromString('Hello World')) } });
159159

160+
assert.strictEqual(workingCopy1.isModified(), true);
160161
assert.strictEqual(workingCopy1.isDirty(), true);
161162
assert.strictEqual(dirtyCounter, 1);
162163
assert.strictEqual(workingCopy1.model?.contents, 'Hello World');
163164

164165
workingCopy1.dispose();
165166

166-
const workingCopy2 = await manager.untitled.resolve({ contents: { value: bufferToStream(VSBuffer.fromString('Hello World')), markDirty: true } });
167+
const workingCopy2 = await manager.untitled.resolve({ contents: { value: bufferToStream(VSBuffer.fromString('Hello World')), markModified: true } });
167168

169+
assert.strictEqual(workingCopy2.isModified(), true);
168170
assert.strictEqual(workingCopy2.isDirty(), true);
169171
assert.strictEqual(dirtyCounter, 2);
170172
assert.strictEqual(workingCopy2.model?.contents, 'Hello World');
@@ -178,8 +180,9 @@ suite('UntitledFileWorkingCopyManager', () => {
178180
dirtyCounter++;
179181
});
180182

181-
const workingCopy = await manager.untitled.resolve({ contents: { value: bufferToStream(VSBuffer.fromString('Hello World')), markDirty: false } });
183+
const workingCopy = await manager.untitled.resolve({ contents: { value: bufferToStream(VSBuffer.fromString('Hello World')), markModified: false } });
182184

185+
assert.strictEqual(workingCopy.isModified(), false);
183186
assert.strictEqual(workingCopy.isDirty(), false);
184187
assert.strictEqual(dirtyCounter, 0);
185188
assert.strictEqual(workingCopy.model?.contents, 'Hello World');

0 commit comments

Comments
 (0)