-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(vscode-ide-companion): use existing editor group for diff instead of forcing a new one #4130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b4747c2
fix(vscode-ide-companion): use existing editor group for diff instead…
yiliang114 756e9cf
fix(vscode-ide-companion): address review feedback — explicit Beside …
yiliang114 a7abe85
fix(vscode-ide-companion): remove dead ensureLeftGroupOfChatWebview, …
yiliang114 cab669f
fix(vscode-ide-companion): align Beside fallback placement in FileMes…
yiliang114 e00505f
fix(vscode-ide-companion): fix TS2322 type error in FileMessageHandle…
yiliang114 680b016
fix(vscode-ide-companion): clarify Beside fallback comment — covers m…
yiliang114 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
packages/vscode-ide-companion/src/utils/editorGroupUtils.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| const chatViewType = 'mainThreadWebview-qwenCode.chat'; | ||
|
|
||
| const vscodeMock = vi.hoisted(() => ({ | ||
| ViewColumn: { One: 1, Two: 2, Three: 3, Four: 4 }, | ||
| window: { | ||
| tabGroups: { | ||
| all: [] as Array<{ tabs: Array<{ input: unknown }>; viewColumn: number }>, | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock('vscode', () => vscodeMock); | ||
|
|
||
| import { | ||
| findLeftGroupOfChatWebview, | ||
| findRightGroupOfChatWebview, | ||
| } from './editorGroupUtils.js'; | ||
|
|
||
| function chatTab() { | ||
| return { input: { viewType: chatViewType } }; | ||
| } | ||
|
|
||
| function regularTab() { | ||
| return { input: { viewType: 'default' } }; | ||
| } | ||
|
|
||
| describe('findLeftGroupOfChatWebview', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vscodeMock.window.tabGroups.all = []; | ||
| }); | ||
|
|
||
| it('returns the nearest left neighbor when chat webview has a group to its left', () => { | ||
| vscodeMock.window.tabGroups.all = [ | ||
| { tabs: [regularTab()], viewColumn: 1 }, | ||
| { tabs: [chatTab()], viewColumn: 2 }, | ||
| { tabs: [regularTab()], viewColumn: 3 }, | ||
| ]; | ||
|
|
||
| expect(findLeftGroupOfChatWebview()).toBe(1); | ||
| }); | ||
|
|
||
| it('returns the closest left neighbor when multiple left groups exist', () => { | ||
| vscodeMock.window.tabGroups.all = [ | ||
| { tabs: [regularTab()], viewColumn: 1 }, | ||
| { tabs: [regularTab()], viewColumn: 2 }, | ||
| { tabs: [chatTab()], viewColumn: 4 }, | ||
| { tabs: [regularTab()], viewColumn: 5 }, | ||
| ]; | ||
|
|
||
| // closest left is group 2, not group 1 | ||
| expect(findLeftGroupOfChatWebview()).toBe(2); | ||
| }); | ||
|
|
||
| it('returns undefined when chat webview is in the leftmost group', () => { | ||
| vscodeMock.window.tabGroups.all = [ | ||
| { tabs: [chatTab()], viewColumn: 1 }, | ||
| { tabs: [regularTab()], viewColumn: 2 }, | ||
| ]; | ||
|
|
||
| expect(findLeftGroupOfChatWebview()).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when no chat webview is found', () => { | ||
| vscodeMock.window.tabGroups.all = [ | ||
| { tabs: [regularTab()], viewColumn: 1 }, | ||
| { tabs: [regularTab()], viewColumn: 2 }, | ||
| ]; | ||
|
|
||
| expect(findLeftGroupOfChatWebview()).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when there are no tab groups', () => { | ||
| vscodeMock.window.tabGroups.all = []; | ||
|
|
||
| expect(findLeftGroupOfChatWebview()).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when tabGroups access throws', () => { | ||
| // make .all throw on access | ||
| Object.defineProperty(vscodeMock.window.tabGroups, 'all', { | ||
| get: () => { | ||
| throw new Error('unexpected error'); | ||
| }, | ||
| configurable: true, | ||
| }); | ||
|
|
||
| expect(findLeftGroupOfChatWebview()).toBeUndefined(); | ||
|
|
||
| // restore | ||
| Object.defineProperty(vscodeMock.window.tabGroups, 'all', { | ||
| value: [], | ||
| configurable: true, | ||
| writable: true, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('findRightGroupOfChatWebview', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vscodeMock.window.tabGroups.all = []; | ||
| }); | ||
|
|
||
| it('returns the nearest right neighbor when chat webview has a group to its right', () => { | ||
| vscodeMock.window.tabGroups.all = [ | ||
| { tabs: [regularTab()], viewColumn: 1 }, | ||
| { tabs: [chatTab()], viewColumn: 2 }, | ||
| { tabs: [regularTab()], viewColumn: 3 }, | ||
| ]; | ||
|
|
||
| expect(findRightGroupOfChatWebview()).toBe(3); | ||
| }); | ||
|
|
||
| it('returns the closest right neighbor when multiple right groups exist', () => { | ||
| vscodeMock.window.tabGroups.all = [ | ||
| { tabs: [regularTab()], viewColumn: 1 }, | ||
| { tabs: [chatTab()], viewColumn: 2 }, | ||
| { tabs: [regularTab()], viewColumn: 3 }, | ||
| { tabs: [regularTab()], viewColumn: 5 }, | ||
| ]; | ||
|
|
||
| // closest right is group 3, not group 5 | ||
| expect(findRightGroupOfChatWebview()).toBe(3); | ||
| }); | ||
|
|
||
| it('returns undefined when chat webview is in the rightmost group', () => { | ||
| vscodeMock.window.tabGroups.all = [ | ||
| { tabs: [regularTab()], viewColumn: 1 }, | ||
| { tabs: [chatTab()], viewColumn: 3 }, | ||
| ]; | ||
|
|
||
| expect(findRightGroupOfChatWebview()).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when no chat webview is found', () => { | ||
| vscodeMock.window.tabGroups.all = [ | ||
| { tabs: [regularTab()], viewColumn: 1 }, | ||
| { tabs: [regularTab()], viewColumn: 2 }, | ||
| ]; | ||
|
|
||
| expect(findRightGroupOfChatWebview()).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when there are no tab groups', () => { | ||
| vscodeMock.window.tabGroups.all = []; | ||
|
|
||
| expect(findRightGroupOfChatWebview()).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when tabGroups access throws', () => { | ||
| Object.defineProperty(vscodeMock.window.tabGroups, 'all', { | ||
| get: () => { | ||
| throw new Error('unexpected error'); | ||
| }, | ||
| configurable: true, | ||
| }); | ||
|
|
||
| expect(findRightGroupOfChatWebview()).toBeUndefined(); | ||
|
|
||
| Object.defineProperty(vscodeMock.window.tabGroups, 'all', { | ||
| value: [], | ||
| configurable: true, | ||
| writable: true, | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.