mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 01:07:46 +00:00
[ide-mode] Support multi-folder workspaces (#6177)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import * as fs from 'node:fs';
|
||||
import { isSubpath } from '../utils/paths.js';
|
||||
import { detectIde, DetectedIde, getIdeInfo } from '../ide/detect-ide.js';
|
||||
import {
|
||||
ideContext,
|
||||
@@ -93,7 +94,14 @@ export class IdeClient {
|
||||
|
||||
this.setState(IDEConnectionStatus.Connecting);
|
||||
|
||||
if (!this.validateWorkspacePath()) {
|
||||
const { isValid, error } = IdeClient.validateWorkspacePath(
|
||||
process.env['GEMINI_CLI_IDE_WORKSPACE_PATH'],
|
||||
this.currentIdeDisplayName,
|
||||
process.cwd(),
|
||||
);
|
||||
|
||||
if (!isValid) {
|
||||
this.setState(IDEConnectionStatus.Disconnected, error, true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -245,37 +253,41 @@ export class IdeClient {
|
||||
}
|
||||
}
|
||||
|
||||
private validateWorkspacePath(): boolean {
|
||||
const ideWorkspacePath = process.env['GEMINI_CLI_IDE_WORKSPACE_PATH'];
|
||||
static validateWorkspacePath(
|
||||
ideWorkspacePath: string | undefined,
|
||||
currentIdeDisplayName: string | undefined,
|
||||
cwd: string,
|
||||
): { isValid: boolean; error?: string } {
|
||||
if (ideWorkspacePath === undefined) {
|
||||
this.setState(
|
||||
IDEConnectionStatus.Disconnected,
|
||||
`Failed to connect to IDE companion extension for ${this.currentIdeDisplayName}. Please ensure the extension is running and try refreshing your terminal. To install the extension, run /ide install.`,
|
||||
true,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (ideWorkspacePath === '') {
|
||||
this.setState(
|
||||
IDEConnectionStatus.Disconnected,
|
||||
`To use this feature, please open a single workspace folder in ${this.currentIdeDisplayName} and try again.`,
|
||||
true,
|
||||
);
|
||||
return false;
|
||||
return {
|
||||
isValid: false,
|
||||
error: `Failed to connect to IDE companion extension for ${currentIdeDisplayName}. Please ensure the extension is running and try refreshing your terminal. To install the extension, run /ide install.`,
|
||||
};
|
||||
}
|
||||
|
||||
const idePath = getRealPath(ideWorkspacePath).toLocaleLowerCase();
|
||||
const cwd = getRealPath(process.cwd()).toLocaleLowerCase();
|
||||
const rel = path.relative(idePath, cwd);
|
||||
if (rel.startsWith('..') || path.isAbsolute(rel)) {
|
||||
this.setState(
|
||||
IDEConnectionStatus.Disconnected,
|
||||
`Directory mismatch. Gemini CLI is running in a different location than the open workspace in ${this.currentIdeDisplayName}. Please run the CLI from the same directory as your project's root folder.`,
|
||||
true,
|
||||
);
|
||||
return false;
|
||||
if (ideWorkspacePath === '') {
|
||||
return {
|
||||
isValid: false,
|
||||
error: `To use this feature, please open a workspace folder in ${currentIdeDisplayName} and try again.`,
|
||||
};
|
||||
}
|
||||
return true;
|
||||
|
||||
const ideWorkspacePaths = ideWorkspacePath.split(':');
|
||||
const realCwd = getRealPath(cwd);
|
||||
const isWithinWorkspace = ideWorkspacePaths.some((workspacePath) => {
|
||||
const idePath = getRealPath(workspacePath);
|
||||
return isSubpath(idePath, realCwd);
|
||||
});
|
||||
|
||||
if (!isWithinWorkspace) {
|
||||
return {
|
||||
isValid: false,
|
||||
error: `Directory mismatch. Gemini CLI is running in a different location than the open workspace in ${currentIdeDisplayName}. Please run the CLI from one of the following directories: ${ideWorkspacePaths.join(
|
||||
', ',
|
||||
)}`,
|
||||
};
|
||||
}
|
||||
return { isValid: true };
|
||||
}
|
||||
|
||||
private getPortFromEnv(): string | undefined {
|
||||
|
||||
Reference in New Issue
Block a user