Merge pull request #2545 from QwenLM/fix/secondary-sidebar-warning

fix(vscode-ide-companion): silence secondary sidebar warning on older VS Code versions
This commit is contained in:
Mingholy 2026-03-26 10:22:31 +08:00 committed by GitHub
commit 23a17b6c1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 18 deletions

View file

@ -9,7 +9,7 @@
* These IDs must match the `views` contributions declared in package.json.
*
* Only one of sidebar / secondary is visible at runtime controlled by the
* `qwen-code:doesNotSupportSecondarySidebar` context key in package.json.
* `qwen-code:supportsSecondarySidebar` context key in package.json.
* The secondary sidebar is preferred; the primary sidebar is a fallback for
* VS Code versions that lack secondary sidebar support.
*/

View file

@ -71,11 +71,15 @@ describe('registerChatViewProviders', () => {
expect(calls[0]?.[2]).toEqual({
webviewOptions: { retainContextWhenHidden: true },
});
expect(executeCommand).not.toHaveBeenCalled();
expect(executeCommand).toHaveBeenCalledWith(
'setContext',
'qwen-code:supportsSecondarySidebar',
true,
);
expect(context.subscriptions).toHaveLength(2);
});
it('sets the fallback context key when secondary sidebar is unavailable', () => {
it('sets context key to false when secondary sidebar is unavailable', () => {
registerChatViewProviders({
context: context as never,
createViewProvider: vi.fn(),
@ -84,8 +88,8 @@ describe('registerChatViewProviders', () => {
expect(executeCommand).toHaveBeenCalledWith(
'setContext',
'qwen-code:doesNotSupportSecondarySidebar',
true,
'qwen-code:supportsSecondarySidebar',
false,
);
});
});

View file

@ -14,8 +14,7 @@ import {
type WebViewProviderFactory,
} from './ChatWebviewViewProvider.js';
const SECONDARY_SIDEBAR_CONTEXT_KEY =
'qwen-code:doesNotSupportSecondarySidebar';
const SECONDARY_SIDEBAR_CONTEXT_KEY = 'qwen-code:supportsSecondarySidebar';
export function detectSecondarySidebarSupport(vscodeVersion: string): boolean {
const [major, minor] = vscodeVersion.split('.').map(Number);
@ -35,13 +34,16 @@ export function registerChatViewProviders(params: {
const supportsSecondarySidebar = detectSecondarySidebarSupport(vscodeVersion);
if (!supportsSecondarySidebar) {
void vscode.commands.executeCommand(
'setContext',
SECONDARY_SIDEBAR_CONTEXT_KEY,
true,
);
}
// Set the context key so package.json `when` clauses can gate the
// secondarySidebar view container. The key defaults to undefined (falsy),
// which keeps the secondary container hidden until we explicitly enable it.
// This prevents the "view container not found" warning on older VS Code
// versions that don't recognise the `secondarySidebar` location.
void vscode.commands.executeCommand(
'setContext',
SECONDARY_SIDEBAR_CONTEXT_KEY,
supportsSecondarySidebar,
);
const sidebarViewProvider = new ChatWebviewViewProvider(createViewProvider);
const secondaryViewProvider = new ChatWebviewViewProvider(createViewProvider);