diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 3c1fb7df5..0df445b01 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -431,42 +431,7 @@ class VsCodeIde implements IDE { } async getOpenFiles(): Promise { - const openFiles = await this.ideUtils.getOpenFiles(); - return this.convertWslPathsIfNeeded(openFiles); - } - - private async convertWslPathsIfNeeded(paths: string[]): Promise { - if (!this.isWsl()) { - return paths; - } - - const convertedPaths = await Promise.all(paths.map(async (path) => { - if (path.startsWith('/mnt/')) { - try { - const [stdout, stderr] = await this.subprocess(`wslpath -w "${path}"`); - if (stderr) { - console.error(`Error converting WSL path: ${stderr}`); - return path; - } - return stdout.trim(); - } catch (error) { - console.error(`Error executing wslpath command: ${error}`); - return path; - } - } - return path; - })); - - return convertedPaths; - } - - /** - * Tests the remote name of the vscode.env.remoteName to see if it starts with 'wsl' - * - * @returns boolean - */ - private isWsl(): boolean { - return !!vscode.env.remoteName?.toLowerCase().startsWith('wsl'); + return await this.ideUtils.getOpenFiles(); } async getCurrentFile(): Promise { diff --git a/extensions/vscode/src/test/test-suites/vsCodeIde.test.ts b/extensions/vscode/src/test/test-suites/vsCodeIde.test.ts deleted file mode 100644 index 368afbf36..000000000 --- a/extensions/vscode/src/test/test-suites/vsCodeIde.test.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { describe, test, beforeEach, afterEach } from "mocha"; -import assert from "node:assert"; -import sinon from "sinon"; -import { VsCodeIde } from '../../VsCodeIde'; - -// Mock the vscode module -const mockVscode = { - Uri: { - file: (path: string) => ({ fsPath: path }) - }, - workspace: { - fs: { - readDirectory: sinon.stub().resolves([]) - } - } -}; - -// Replace the real vscode module with our mock -import * as vscode from 'vscode'; -(global as any).vscode = mockVscode; - -describe('VsCodeIde', () => { - let ide: VsCodeIde; - let mockIdeUtils: any; - - beforeEach(() => { - mockIdeUtils = { - getOpenFiles: sinon.stub().resolves([]) - }; - - ide = new VsCodeIde(null as any, Promise.resolve(null as any)); - (ide as any).ideUtils = mockIdeUtils; - (ide as any).subprocess = sinon.stub().resolves(['', '']); - }); - - afterEach(() => { - sinon.restore(); - }); - - describe('getOpenFiles', () => { - test('should return open files without conversion when not in WSL', async () => { - sinon.stub(ide as any, 'isWsl').returns(false); - const mockFiles = ['/path/to/file1', '/path/to/file2']; - mockIdeUtils.getOpenFiles.resolves(mockFiles); - - const result = await ide.getOpenFiles(); - - assert.deepStrictEqual(result, mockFiles); - }); - - test('should convert WSL paths when in WSL environment', async () => { - sinon.stub(ide as any, 'isWsl').returns(true); - - const mockFiles = ['/mnt/c/path/to/file1', '/path/to/file2']; - mockIdeUtils.getOpenFiles.resolves(mockFiles); - - (ide as any).subprocess.withArgs('wslpath -w "/mnt/c/path/to/file1"').resolves(['C:\\path\\to\\file1', '']); - - const result = await ide.getOpenFiles(); - - assert.deepStrictEqual(result, ['C:\\path\\to\\file1', '/path/to/file2']); - }); - - test('should handle errors in WSL path conversion', async () => { - sinon.stub(ide as any, 'isWsl').returns(true); - - const mockFiles = ['/mnt/c/path/to/file1', '/path/to/file2']; - mockIdeUtils.getOpenFiles.resolves(mockFiles); - - (ide as any).subprocess.throws(new Error('Command failed')); - - - const result = await ide.getOpenFiles(); - - assert.deepStrictEqual(result, mockFiles); - }); - }); -}); diff --git a/extensions/vscode/src/util/ideUtils.ts b/extensions/vscode/src/util/ideUtils.ts index 33ab80632..206941e1d 100644 --- a/extensions/vscode/src/util/ideUtils.ts +++ b/extensions/vscode/src/util/ideUtils.ts @@ -225,7 +225,7 @@ export class VsCodeIdeUtils { .flat() .filter(Boolean) // filter out undefined values .filter((uri) => this.documentIsCode(uri)) // Filter out undesired documents - .map((uri) => uri.fsPath); + .map((uri) => uriFromFilePath(uri.fsPath).fsPath); } getVisibleFiles(): string[] {