mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
Improve user-facing error messages for IDE mode (#5522)
This commit is contained in:
@@ -11,9 +11,12 @@ export enum DetectedIde {
|
||||
export function getIdeDisplayName(ide: DetectedIde): string {
|
||||
switch (ide) {
|
||||
case DetectedIde.VSCode:
|
||||
return 'VSCode';
|
||||
default:
|
||||
throw new Error(`Unsupported IDE: ${ide}`);
|
||||
return 'VS Code';
|
||||
default: {
|
||||
// This ensures that if a new IDE is added to the enum, we get a compile-time error.
|
||||
const exhaustiveCheck: never = ide;
|
||||
return exhaustiveCheck;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,32 +45,6 @@ describe('ide-installer', () => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('isInstalled', () => {
|
||||
it('should return true if command is in PATH', async () => {
|
||||
expect(await installer.isInstalled()).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if command is in a known location', async () => {
|
||||
vi.spyOn(child_process, 'execSync').mockImplementation(() => {
|
||||
throw new Error('Command not found');
|
||||
});
|
||||
vi.spyOn(fs, 'existsSync').mockReturnValue(true);
|
||||
// Re-create the installer so it re-runs findVsCodeCommand
|
||||
installer = getIdeInstaller(DetectedIde.VSCode)!;
|
||||
expect(await installer.isInstalled()).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if command is not found', async () => {
|
||||
vi.spyOn(child_process, 'execSync').mockImplementation(() => {
|
||||
throw new Error('Command not found');
|
||||
});
|
||||
vi.spyOn(fs, 'existsSync').mockReturnValue(false);
|
||||
// Re-create the installer so it re-runs findVsCodeCommand
|
||||
installer = getIdeInstaller(DetectedIde.VSCode)!;
|
||||
expect(await installer.isInstalled()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('install', () => {
|
||||
it('should return a failure message if VS Code is not installed', async () => {
|
||||
vi.spyOn(child_process, 'execSync').mockImplementation(() => {
|
||||
@@ -81,9 +55,7 @@ describe('ide-installer', () => {
|
||||
installer = getIdeInstaller(DetectedIde.VSCode)!;
|
||||
const result = await installer.install();
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.message).toContain(
|
||||
'not found in your PATH or common installation locations',
|
||||
);
|
||||
expect(result.message).toContain('VS Code CLI not found');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,7 +18,6 @@ const VSCODE_COMPANION_EXTENSION_FOLDER = 'vscode-ide-companion';
|
||||
|
||||
export interface IdeInstaller {
|
||||
install(): Promise<InstallResult>;
|
||||
isInstalled(): Promise<boolean>;
|
||||
}
|
||||
|
||||
export interface InstallResult {
|
||||
@@ -95,16 +94,12 @@ class VsCodeInstaller implements IdeInstaller {
|
||||
this.vsCodeCommand = findVsCodeCommand();
|
||||
}
|
||||
|
||||
async isInstalled(): Promise<boolean> {
|
||||
return (await this.vsCodeCommand) !== null;
|
||||
}
|
||||
|
||||
async install(): Promise<InstallResult> {
|
||||
const commandPath = await this.vsCodeCommand;
|
||||
if (!commandPath) {
|
||||
return {
|
||||
success: false,
|
||||
message: `VS Code command-line tool not found in your PATH or common installation locations.`,
|
||||
message: `VS Code CLI not found. Please ensure 'code' is in your system's PATH. For help, see https://code.visualstudio.com/docs/configure/command-line#_code-is-not-recognized-as-an-internal-or-external-command. You can also install the companion extension manually from the VS Code marketplace.`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -141,12 +136,12 @@ class VsCodeInstaller implements IdeInstaller {
|
||||
return {
|
||||
success: true,
|
||||
message:
|
||||
'VS Code companion extension installed successfully. Restart gemini-cli in a fresh terminal window.',
|
||||
'VS Code companion extension was installed successfully. Please restart your terminal to complete the setup.',
|
||||
};
|
||||
} catch (_error) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'Failed to install VS Code companion extension.',
|
||||
message: `Failed to install VS Code companion extension. Please try installing it manually from the VS Code marketplace.`,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -154,7 +149,7 @@ class VsCodeInstaller implements IdeInstaller {
|
||||
|
||||
export function getIdeInstaller(ide: DetectedIde): IdeInstaller | null {
|
||||
switch (ide) {
|
||||
case 'vscode':
|
||||
case DetectedIde.VSCode:
|
||||
return new VsCodeInstaller();
|
||||
default:
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user