diff --git a/proto/host/window.proto b/proto/host/window.proto index 1c2a8c1b..a551bfcd 100644 --- a/proto/host/window.proto +++ b/proto/host/window.proto @@ -31,6 +31,9 @@ service WindowService { // Returns the visible tabs. rpc getVisibleTabs(GetVisibleTabsRequest) returns (GetVisibleTabsResponse); + + // Returns information about the current editor + rpc getActiveEditor(GetActiveEditorRequest) returns (GetActiveEditorResponse); } message ShowTextDocumentRequest { @@ -138,3 +141,9 @@ message GetVisibleTabsRequest {} message GetVisibleTabsResponse { repeated string paths = 1; } + +message GetActiveEditorRequest {} + +message GetActiveEditorResponse { + optional string file_path = 1; +} diff --git a/src/extension.ts b/src/extension.ts index 66cda55f..31766e48 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -125,7 +125,6 @@ export async function activate(context: vscode.ExtensionContext) { // (this example uses webviewProvider activation event which is necessary to deserialize cached webview, but since we use retainContextWhenHidden, we don't need to use that event) // https://github.com/microsoft/vscode-extension-samples/blob/main/webview-sample/src/extension.ts const tabWebview = HostProvider.get().createWebviewProvider(WebviewProviderType.TAB) as VscodeWebviewProvider - //const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined const lastCol = Math.max(...vscode.window.visibleTextEditors.map((editor) => editor.viewColumn || 0)) // Check if there are any visible text editors, otherwise open a new group to the right diff --git a/src/hosts/vscode/hostbridge/window/getActiveEditor.ts b/src/hosts/vscode/hostbridge/window/getActiveEditor.ts new file mode 100644 index 00000000..684e1f87 --- /dev/null +++ b/src/hosts/vscode/hostbridge/window/getActiveEditor.ts @@ -0,0 +1,8 @@ +import * as vscode from "vscode" + +import { GetActiveEditorRequest, GetActiveEditorResponse } from "@/shared/proto/index.host" + +export async function getActiveEditor(_: GetActiveEditorRequest): Promise { + const filePath = vscode.window.activeTextEditor?.document.uri.fsPath + return { filePath } +} diff --git a/src/utils/path.ts b/src/utils/path.ts index 4a5ea816..ba01b015 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -115,7 +115,7 @@ export function getDesktopDir() { // Returns the workspace path of the file in the current editor. // If there is no open file, it returns the top level workspace directory. export async function getWorkspacePath(defaultCwd = ""): Promise { - const currentFilePath = vscode.window.activeTextEditor?.document.uri.fsPath + const currentFilePath = (await HostProvider.window.getActiveEditor({})).filePath if (!currentFilePath) { return await getCwd(defaultCwd) }