[ide-mode] Fix path delimiter for multi-root workspaces on Windows (#6273)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
parent
3c0af3654a
commit
4896c7739f
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import * as path from 'path';
|
||||||
import { IdeClient } from './ide-client.js';
|
import { IdeClient } from './ide-client.js';
|
||||||
|
|
||||||
describe('IdeClient.validateWorkspacePath', () => {
|
describe('IdeClient.validateWorkspacePath', () => {
|
||||||
|
@ -49,7 +50,7 @@ describe('IdeClient.validateWorkspacePath', () => {
|
||||||
|
|
||||||
it('should handle multiple workspace paths and return valid', () => {
|
it('should handle multiple workspace paths and return valid', () => {
|
||||||
const result = IdeClient.validateWorkspacePath(
|
const result = IdeClient.validateWorkspacePath(
|
||||||
'/some/other/path:/Users/person/gemini-cli',
|
['/some/other/path', '/Users/person/gemini-cli'].join(path.delimiter),
|
||||||
'VS Code',
|
'VS Code',
|
||||||
'/Users/person/gemini-cli/sub-dir',
|
'/Users/person/gemini-cli/sub-dir',
|
||||||
);
|
);
|
||||||
|
@ -58,11 +59,20 @@ describe('IdeClient.validateWorkspacePath', () => {
|
||||||
|
|
||||||
it('should return invalid if cwd is not in any of the multiple workspace paths', () => {
|
it('should return invalid if cwd is not in any of the multiple workspace paths', () => {
|
||||||
const result = IdeClient.validateWorkspacePath(
|
const result = IdeClient.validateWorkspacePath(
|
||||||
'/some/other/path:/another/path',
|
['/some/other/path', '/another/path'].join(path.delimiter),
|
||||||
'VS Code',
|
'VS Code',
|
||||||
'/Users/person/gemini-cli/sub-dir',
|
'/Users/person/gemini-cli/sub-dir',
|
||||||
);
|
);
|
||||||
expect(result.isValid).toBe(false);
|
expect(result.isValid).toBe(false);
|
||||||
expect(result.error).toContain('Directory mismatch');
|
expect(result.error).toContain('Directory mismatch');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.skipIf(process.platform !== 'win32')('should handle windows paths', () => {
|
||||||
|
const result = IdeClient.validateWorkspacePath(
|
||||||
|
'c:/some/other/path;d:/Users/person/gemini-cli',
|
||||||
|
'VS Code',
|
||||||
|
'd:/Users/person/gemini-cli/sub-dir',
|
||||||
|
);
|
||||||
|
expect(result.isValid).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -272,7 +272,7 @@ export class IdeClient {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const ideWorkspacePaths = ideWorkspacePath.split(':');
|
const ideWorkspacePaths = ideWorkspacePath.split(path.delimiter);
|
||||||
const realCwd = getRealPath(cwd);
|
const realCwd = getRealPath(cwd);
|
||||||
const isWithinWorkspace = ideWorkspacePaths.some((workspacePath) => {
|
const isWithinWorkspace = ideWorkspacePaths.some((workspacePath) => {
|
||||||
const idePath = getRealPath(workspacePath);
|
const idePath = getRealPath(workspacePath);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
import * as path from 'path';
|
||||||
import { activate } from './extension.js';
|
import { activate } from './extension.js';
|
||||||
|
|
||||||
vi.mock('vscode', () => ({
|
vi.mock('vscode', () => ({
|
||||||
|
@ -102,7 +103,7 @@ describe('activate with multiple folders', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set multiple folder paths, separated by a colon', async () => {
|
it('should set multiple folder paths, separated by OS-specific path delimiter', async () => {
|
||||||
const workspaceFoldersSpy = vi.spyOn(
|
const workspaceFoldersSpy = vi.spyOn(
|
||||||
vscode.workspace,
|
vscode.workspace,
|
||||||
'workspaceFolders',
|
'workspaceFolders',
|
||||||
|
@ -117,7 +118,7 @@ describe('activate with multiple folders', () => {
|
||||||
|
|
||||||
expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
|
expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
|
||||||
'GEMINI_CLI_IDE_WORKSPACE_PATH',
|
'GEMINI_CLI_IDE_WORKSPACE_PATH',
|
||||||
'/foo/bar:/baz/qux',
|
['/foo/bar', '/baz/qux'].join(path.delimiter),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -166,7 +167,7 @@ describe('activate with multiple folders', () => {
|
||||||
|
|
||||||
expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
|
expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
|
||||||
'GEMINI_CLI_IDE_WORKSPACE_PATH',
|
'GEMINI_CLI_IDE_WORKSPACE_PATH',
|
||||||
'/foo/bar:/baz/qux',
|
['/foo/bar', '/baz/qux'].join(path.delimiter),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Simulate removing a folder
|
// Simulate removing a folder
|
||||||
|
@ -183,4 +184,28 @@ describe('activate with multiple folders', () => {
|
||||||
'/baz/qux',
|
'/baz/qux',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.skipIf(process.platform !== 'win32')(
|
||||||
|
'should handle windows paths',
|
||||||
|
async () => {
|
||||||
|
const workspaceFoldersSpy = vi.spyOn(
|
||||||
|
vscode.workspace,
|
||||||
|
'workspaceFolders',
|
||||||
|
'get',
|
||||||
|
);
|
||||||
|
workspaceFoldersSpy.mockReturnValue([
|
||||||
|
{ uri: { fsPath: 'c:/foo/bar' } },
|
||||||
|
{ uri: { fsPath: 'd:/baz/qux' } },
|
||||||
|
] as vscode.WorkspaceFolder[]);
|
||||||
|
|
||||||
|
await activate(context);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
context.environmentVariableCollection.replace,
|
||||||
|
).toHaveBeenCalledWith(
|
||||||
|
'GEMINI_CLI_IDE_WORKSPACE_PATH',
|
||||||
|
'c:/foo/bar;d:/baz/qux',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
import * as path from 'path';
|
||||||
import { IDEServer } from './ide-server.js';
|
import { IDEServer } from './ide-server.js';
|
||||||
import { DiffContentProvider, DiffManager } from './diff-manager.js';
|
import { DiffContentProvider, DiffManager } from './diff-manager.js';
|
||||||
import { createLogger } from './utils/logger.js';
|
import { createLogger } from './utils/logger.js';
|
||||||
|
@ -23,7 +24,7 @@ function updateWorkspacePath(context: vscode.ExtensionContext) {
|
||||||
if (workspaceFolders && workspaceFolders.length > 0) {
|
if (workspaceFolders && workspaceFolders.length > 0) {
|
||||||
const workspacePaths = workspaceFolders
|
const workspacePaths = workspaceFolders
|
||||||
.map((folder) => folder.uri.fsPath)
|
.map((folder) => folder.uri.fsPath)
|
||||||
.join(':');
|
.join(path.delimiter);
|
||||||
context.environmentVariableCollection.replace(
|
context.environmentVariableCollection.replace(
|
||||||
IDE_WORKSPACE_PATH_ENV_VAR,
|
IDE_WORKSPACE_PATH_ENV_VAR,
|
||||||
workspacePaths,
|
workspacePaths,
|
||||||
|
|
Loading…
Reference in New Issue