diff --git a/core/commands/slash/multifileEdit.ts b/core/commands/slash/multifileEdit.ts index 797f27bf2..ffda6b703 100644 --- a/core/commands/slash/multifileEdit.ts +++ b/core/commands/slash/multifileEdit.ts @@ -1,5 +1,6 @@ import { SlashCommand } from "../.."; import { getFullyQualifiedPath } from "../../../extensions/vscode/src/util/util"; +import { VsCodeIde } from "../../../extensions/vscode/src/VsCodeIde"; import { stripImages } from "../../llm/images"; const MultiFileEditSlashCommand: SlashCommand = { @@ -11,7 +12,7 @@ const MultiFileEditSlashCommand: SlashCommand = { selectedCode.map(async (item) => { // Split the range string from the filename, e.g. `filename.ts (1-2) -> [filename.ts, (1-2)]` const [filepath, rangeStr] = item.filepath.split(" "); - const fullPath = getFullyQualifiedPath(filepath); + const fullPath = getFullyQualifiedPath(ide as VsCodeIde, filepath); if (!fullPath) { return ""; diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index bb020c302..41d047730 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -34,6 +34,7 @@ import { Battery } from "./util/battery"; import { getFullyQualifiedPath } from "./util/util"; import { uriFromFilePath } from "./util/vscode"; import type { VsCodeWebviewProtocol } from "./webviewProtocol"; +import { VsCodeIde } from "./VsCodeIde"; let fullScreenPanel: vscode.WebviewPanel | undefined; @@ -188,7 +189,7 @@ function focusGUI() { // Copy everything over from extension.ts const commandsMap: ( - ide: IDE, + ide: VsCodeIde, extensionContext: vscode.ExtensionContext, sidebar: ContinueGUIWebviewViewProvider, configHandler: ConfigHandler, @@ -261,8 +262,10 @@ const commandsMap: ( if (fullPath instanceof vscode.Uri) { fullPath = fullPath.fsPath; + } else if (fullPath) { + fullPath = getFullyQualifiedPath(ide, fullPath); } else { - fullPath = getFullyQualifiedPath(fullPath); + console.warn(`Unable to resolve filepath: ${newFilepath}`); } verticalDiffManager.clearForFilepath(fullPath, true); @@ -278,8 +281,11 @@ const commandsMap: ( if (fullPath instanceof vscode.Uri) { fullPath = fullPath.fsPath; + } else if (fullPath) { + fullPath = getFullyQualifiedPath(ide, fullPath); } else { - fullPath = getFullyQualifiedPath(fullPath); + console.warn(`Unable to resolve filepath: ${newFilepath}`); + return; } verticalDiffManager.clearForFilepath(fullPath, false); @@ -807,7 +813,7 @@ const commandsMap: ( export function registerAllCommands( context: vscode.ExtensionContext, - ide: IDE, + ide: VsCodeIde, extensionContext: vscode.ExtensionContext, sidebar: ContinueGUIWebviewViewProvider, configHandler: ConfigHandler, diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 954f30349..d7ed63a5f 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -86,7 +86,7 @@ export class VsCodeMessenger { ) { /** WEBVIEW ONLY LISTENERS **/ this.onWebview("showFile", (msg) => { - const fullPath = getFullyQualifiedPath(msg.data.filepath); + const fullPath = getFullyQualifiedPath(this.ide, msg.data.filepath); if (fullPath) { this.ide.openFile(fullPath); @@ -159,7 +159,7 @@ export class VsCodeMessenger { }); this.onWebview("applyToFile", async ({ data }) => { - const fullPath = getFullyQualifiedPath(data.filepath); + const fullPath = getFullyQualifiedPath(ide, data.filepath); if (!fullPath) { return; diff --git a/extensions/vscode/src/util/util.ts b/extensions/vscode/src/util/util.ts index 4ac832455..9b5c11bfe 100644 --- a/extensions/vscode/src/util/util.ts +++ b/extensions/vscode/src/util/util.ts @@ -1,6 +1,7 @@ const os = require("node:os"); import path from "node:path"; import * as vscode from "vscode"; +import { VsCodeIde } from "../VsCodeIde"; function charIsEscapedAtIndex(index: number, str: string): boolean { if (index === 0) { @@ -123,17 +124,12 @@ export function getExtensionVersion(): string { return extension?.packageJSON.version || "0.1.0"; } -export function getFullyQualifiedPath(filepath?: string) { - if (!filepath) return; - if (path.isAbsolute(filepath)) return filepath; +export function getFullyQualifiedPath(ide: VsCodeIde, filepath: string) { + if (ide.ideUtils.path.isAbsolute(filepath)) return filepath; const workspaceFolders = vscode.workspace.workspaceFolders; if (workspaceFolders && workspaceFolders.length > 0) { - return path.join(workspaceFolders[0].uri.fsPath, filepath); - } else { - vscode.window.showErrorMessage( - "Unable to resolve filepath: no workspace folder found", - ); + return ide.ideUtils.path.join(workspaceFolders[0].uri.fsPath, filepath); } }