Skip to content

Commit d838f71

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
[workspace_diff] Include un-bound FileSystem resources.
When the `kDevToolsImprovedWorkspaces` feature is enabled, the Changes panel will also show differences between the working copy and the committed state for `UISourceCode`s that belong to a FileSystem project and don't have a binding (to a Network project resource). Fixed: 393267660 Bug: 393244410 Change-Id: I75276fb97316f05f8c8aebff17913cdedf1b6cbe Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6218361 Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Benedikt Meurer <[email protected]> Auto-Submit: Benedikt Meurer <[email protected]>
1 parent 17794ee commit d838f71

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

front_end/models/workspace_diff/WorkspaceDiff.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ interface DiffResponse {
1616
}
1717

1818
export class WorkspaceDiffImpl extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
19-
private readonly uiSourceCodeDiffs: WeakMap<Workspace.UISourceCode.UISourceCode, UISourceCodeDiff>;
20-
private readonly loadingUISourceCodes:
21-
Map<Workspace.UISourceCode.UISourceCode, Promise<[string | null, string|null]>>;
22-
private readonly modifiedUISourceCodesInternal: Set<Workspace.UISourceCode.UISourceCode>;
19+
readonly #persistence = Persistence.Persistence.PersistenceImpl.instance();
20+
readonly #diffs = new WeakMap<Workspace.UISourceCode.UISourceCode, UISourceCodeDiff>();
21+
private readonly loadingUISourceCodes =
22+
new Map<Workspace.UISourceCode.UISourceCode, Promise<[string | null, string|null]>>();
23+
readonly #modified = new Set<Workspace.UISourceCode.UISourceCode>();
2324

2425
constructor(workspace: Workspace.Workspace.WorkspaceImpl) {
2526
super();
26-
this.uiSourceCodeDiffs = new WeakMap();
27-
28-
this.loadingUISourceCodes = new Map();
29-
30-
this.modifiedUISourceCodesInternal = new Set();
3127
workspace.addEventListener(Workspace.Workspace.Events.WorkingCopyChanged, this.uiSourceCodeChanged, this);
3228
workspace.addEventListener(Workspace.Workspace.Events.WorkingCopyCommitted, this.uiSourceCodeChanged, this);
3329
workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, this.uiSourceCodeAdded, this);
@@ -51,18 +47,18 @@ export class WorkspaceDiffImpl extends Common.ObjectWrapper.ObjectWrapper<EventT
5147
}
5248

5349
modifiedUISourceCodes(): Workspace.UISourceCode.UISourceCode[] {
54-
return Array.from(this.modifiedUISourceCodesInternal);
50+
return Array.from(this.#modified);
5551
}
5652

5753
isUISourceCodeModified(uiSourceCode: Workspace.UISourceCode.UISourceCode): boolean {
58-
return this.modifiedUISourceCodesInternal.has(uiSourceCode) || this.loadingUISourceCodes.has(uiSourceCode);
54+
return this.#modified.has(uiSourceCode) || this.loadingUISourceCodes.has(uiSourceCode);
5955
}
6056

6157
private uiSourceCodeDiff(uiSourceCode: Workspace.UISourceCode.UISourceCode): UISourceCodeDiff {
62-
let diff = this.uiSourceCodeDiffs.get(uiSourceCode);
58+
let diff = this.#diffs.get(uiSourceCode);
6359
if (!diff) {
6460
diff = new UISourceCodeDiff(uiSourceCode);
65-
this.uiSourceCodeDiffs.set(uiSourceCode, diff);
61+
this.#diffs.set(uiSourceCode, diff);
6662
}
6763
return diff;
6864
}
@@ -92,7 +88,7 @@ export class WorkspaceDiffImpl extends Common.ObjectWrapper.ObjectWrapper<EventT
9288

9389
private removeUISourceCode(uiSourceCode: Workspace.UISourceCode.UISourceCode): void {
9490
this.loadingUISourceCodes.delete(uiSourceCode);
95-
const uiSourceCodeDiff = this.uiSourceCodeDiffs.get(uiSourceCode);
91+
const uiSourceCodeDiff = this.#diffs.get(uiSourceCode);
9692
if (uiSourceCodeDiff) {
9793
uiSourceCodeDiff.dispose = true;
9894
}
@@ -101,27 +97,44 @@ export class WorkspaceDiffImpl extends Common.ObjectWrapper.ObjectWrapper<EventT
10197

10298
private markAsUnmodified(uiSourceCode: Workspace.UISourceCode.UISourceCode): void {
10399
this.uiSourceCodeProcessedForTest();
104-
if (this.modifiedUISourceCodesInternal.delete(uiSourceCode)) {
100+
if (this.#modified.delete(uiSourceCode)) {
105101
this.dispatchEventToListeners(Events.MODIFIED_STATUS_CHANGED, {uiSourceCode, isModified: false});
106102
}
107103
}
108104

109105
private markAsModified(uiSourceCode: Workspace.UISourceCode.UISourceCode): void {
110106
this.uiSourceCodeProcessedForTest();
111-
if (this.modifiedUISourceCodesInternal.has(uiSourceCode)) {
107+
if (this.#modified.has(uiSourceCode)) {
112108
return;
113109
}
114-
this.modifiedUISourceCodesInternal.add(uiSourceCode);
110+
this.#modified.add(uiSourceCode);
115111
this.dispatchEventToListeners(Events.MODIFIED_STATUS_CHANGED, {uiSourceCode, isModified: true});
116112
}
117113

118114
private uiSourceCodeProcessedForTest(): void {
119115
}
120116

117+
#shouldTrack(uiSourceCode: Workspace.UISourceCode.UISourceCode): boolean {
118+
// We track differences for all Network resources.
119+
if (uiSourceCode.project().type() === Workspace.Workspace.projectTypes.Network) {
120+
return true;
121+
}
122+
123+
// Additionally we also track differences for FileSystem resources that don't have
124+
// a binding (as part of the kDevToolsImprovedWorkspaces feature).
125+
if (uiSourceCode.project().type() === Workspace.Workspace.projectTypes.FileSystem &&
126+
this.#persistence.binding(uiSourceCode) === null &&
127+
Common.Settings.Settings.instance().getHostConfig().devToolsImprovedWorkspaces?.enabled) {
128+
return true;
129+
}
130+
131+
return false;
132+
}
133+
121134
private async updateModifiedState(uiSourceCode: Workspace.UISourceCode.UISourceCode): Promise<void> {
122135
this.loadingUISourceCodes.delete(uiSourceCode);
123136

124-
if (uiSourceCode.project().type() !== Workspace.Workspace.projectTypes.Network) {
137+
if (!this.#shouldTrack(uiSourceCode)) {
125138
this.markAsUnmodified(uiSourceCode);
126139
return;
127140
}

0 commit comments

Comments
 (0)