Add an RPC to the host bridge to return information about the active editor (#5690)
Add an RPC that returns details about the currently active editor. Right now it just returns the file path. Update the place where this is used. Remove commented out code that references `vscode.window.activeTextEditor`.
This commit is contained in:
1 parent
6f4a4e1ccd
commit
01c4ead155
4 files changed
+18
-2
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as vscode from "vscode"
|
||||
|
||||
import { GetActiveEditorRequest, GetActiveEditorResponse } from "@/shared/proto/index.host"
|
||||
|
||||
export async function getActiveEditor(_: GetActiveEditorRequest): Promise<GetActiveEditorResponse> {
|
||||
const filePath = vscode.window.activeTextEditor?.document.uri.fsPath
|
||||
return { filePath }
|
||||
}
|
||||
+1
-1
@@ -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<string> {
|
||||
const currentFilePath = vscode.window.activeTextEditor?.document.uri.fsPath
|
||||
const currentFilePath = (await HostProvider.window.getActiveEditor({})).filePath
|
||||
if (!currentFilePath) {
|
||||
return await getCwd(defaultCwd)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user