Skip to content

Commit 935df52

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Ignore changes that don't have a diff
Updates the lineDiff to return empty array of changes when both the original and the changed text are equal. Then check in the CombinedDiffView whether there were actual diff before rendering. Bug: 406699819 Change-Id: I3f637f22b42a0eb4853b9897c2ea08fc632f79ea Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6404313 Reviewed-by: Ergün Erdoğmuş <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent 6c5d77f commit 935df52

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

front_end/panels/changes/CombinedDiffView.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ function createWorkspaceDiff({workspace}: {workspace: Workspace.Workspace.Worksp
4646

4747
async function createCombinedDiffView({workspaceDiff}: {workspaceDiff: WorkspaceDiff.WorkspaceDiff.WorkspaceDiffImpl}) {
4848
const view = createViewFunctionStub(CombinedDiffView.CombinedDiffView);
49-
const combinedDiffView = new CombinedDiffView.CombinedDiffView(undefined, view);
50-
combinedDiffView.workspaceDiff = workspaceDiff;
49+
const widget = new CombinedDiffView.CombinedDiffView(undefined, view);
50+
widget.workspaceDiff = workspaceDiff;
5151

5252
const container = document.createElement('div');
5353
renderElementIntoDOM(container);
54-
combinedDiffView.markAsRoot();
55-
combinedDiffView.show(container);
54+
widget.markAsRoot();
55+
widget.show(container);
5656
await view.nextInput;
5757

58-
return {combinedDiffView, view};
58+
return {widget, view};
5959
}
6060

6161
describeWithEnvironment('CombinedDiffView', () => {

front_end/panels/changes/CombinedDiffView.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,22 @@ export class CombinedDiffView extends UI.Widget.Widget {
178178
}
179179

180180
override async performUpdate(): Promise<void> {
181-
const uiSourceCodeAndDiffs = await Promise.all(this.#modifiedUISourceCodes.map(async modifiedUISourceCode => {
182-
// `requestDiff` caches the response from the previous `requestDiff` calls if the file did not change
183-
// so we can safely call it here without concerns for performance.
184-
const diffResponse = await this.#workspaceDiff?.requestDiff(modifiedUISourceCode);
185-
return {
186-
diff: diffResponse?.diff,
187-
uiSourceCode: modifiedUISourceCode,
188-
};
189-
}));
181+
const uiSourceCodeAndDiffs = (await Promise.all(this.#modifiedUISourceCodes.map(async modifiedUISourceCode => {
182+
// `requestDiff` caches the response from the previous `requestDiff` calls if the file did not change
183+
// so we can safely call it here without concerns for performance.
184+
const diffResponse = await this.#workspaceDiff?.requestDiff(modifiedUISourceCode);
185+
if (!diffResponse || diffResponse.diff.length === 0) {
186+
return;
187+
}
188+
189+
return {
190+
diff: diffResponse.diff,
191+
uiSourceCode: modifiedUISourceCode,
192+
};
193+
}))).filter(uiSourceCodeAndDiff => !!uiSourceCodeAndDiff);
190194

191195
const singleDiffViewInputs =
192-
uiSourceCodeAndDiffs.filter(uiSourceCodeAndDiff => Boolean(uiSourceCodeAndDiff.diff))
196+
uiSourceCodeAndDiffs
193197
.map(({uiSourceCode, diff}) => {
194198
let displayText = uiSourceCode.fullDisplayName();
195199
// If the UISourceCode is backed by a workspace, we show the path as "{workspace-name}/path/relative/to/workspace"
@@ -203,7 +207,7 @@ export class CombinedDiffView extends UI.Widget.Widget {
203207
].join('/');
204208
}
205209
return {
206-
diff: diff as Diff.Diff.DiffArray, // We already filter above the ones that does not have `diff`.
210+
diff,
207211
fileName: `${uiSourceCode.isDirty() ? '*' : ''}${displayText}`,
208212
fileUrl: uiSourceCode.url(),
209213
mimeType: uiSourceCode.mimeType(),

front_end/third_party/diff/DiffWrapper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export const DiffWrapper = {
2828
const text1 = lines1.map(line => idMap.toChar(line)).join('');
2929
const text2 = lines2.map(line => idMap.toChar(line)).join('');
3030

31+
// If both text are the same don't emit a diff
32+
if(text1 === text2){
33+
return [];
34+
}
35+
3136
const diff = DiffWrapper.charDiff(text1, text2);
3237
const lineDiff = [];
3338
for (let i = 0; i < diff.length; i++) {

front_end/ui/components/diff_view/DiffView.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,17 @@ describeWithLocale('DiffView', () => {
7171
assert.isNotNull(view.querySelector('.diff-line-spacer'));
7272
});
7373
});
74+
75+
describe('DiffWrapper', () => {
76+
describe('lineDiff', () => {
77+
it('should work with no changes', () => {
78+
let diff = Diff.Diff.DiffWrapper.lineDiff([''], ['']);
79+
80+
assert.deepEqual(diff, []);
81+
82+
diff = Diff.Diff.DiffWrapper.lineDiff(['initial'], ['initial']);
83+
84+
assert.deepEqual(diff, []);
85+
});
86+
});
87+
});

0 commit comments

Comments
 (0)