Move logic for manipulating tabs into the host bridge (#5631)
* Switch the DiffViewProvider to use the util `openFile` This part of the work to migrate the vscode API calls `vscode.window.tabGroups.close`, `vscode.window.tabGroups.all` and `vscode.window.activeTextEditor` to the host bridge. `openFile` contains logic that uses these APIs to avoid re-avoiding tabs in the IDE. The end goal is to move all this logic into `vscode/hostbridge/showTextDocument.ts`. I am going to switch all the places that use `showTextDocument` over to use `openFile`. Once everywhere that was using `showTextDocument` has been switched, and is verified to work the same as before I will move the tab logic in `vscode/hostbridge/showTextDocument.ts`. * Update src/integrations/editor/DiffViewProvider.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * Switch export-markdown to use the util `openFile`. * Apply suggestion from @ellipsis-dev[bot] Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * Move tab logic into vscode/showTextDocument --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
feb92c45ce
commit
4aaca09389
4 files changed
+28
-40
No files matched your search
@@ -1,9 +1,29 @@
|
||||
import * as vscode from "vscode"
|
||||
import { ShowTextDocumentRequest, TextEditorInfo } from "@/shared/proto/host/window"
|
||||
import { arePathsEqual } from "@/utils/path"
|
||||
|
||||
export async function showTextDocument(request: ShowTextDocumentRequest): Promise<TextEditorInfo> {
|
||||
// Convert file path to URI
|
||||
const uri = vscode.Uri.file(request.path)
|
||||
|
||||
// Check if the document is already open in a tab group that's not in the active editor's column.
|
||||
// If it is, then close it (if not dirty) so that we don't duplicate tabs
|
||||
try {
|
||||
for (const group of vscode.window.tabGroups.all) {
|
||||
const existingTab = group.tabs.find(
|
||||
(tab) => tab.input instanceof vscode.TabInputText && arePathsEqual(tab.input.uri.fsPath, uri.fsPath),
|
||||
)
|
||||
if (existingTab) {
|
||||
const activeColumn = vscode.window.activeTextEditor?.viewColumn
|
||||
const tabColumn = vscode.window.tabGroups.all.find((group) => group.tabs.includes(existingTab))?.viewColumn
|
||||
if (activeColumn && activeColumn !== tabColumn && !existingTab.isDirty) {
|
||||
await vscode.window.tabGroups.close(existingTab)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch {} // not essential, sometimes tab operations fail
|
||||
|
||||
const options: vscode.TextDocumentShowOptions = {}
|
||||
|
||||
if (request.options?.preview !== undefined) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as iconv from "iconv-lite"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { DiagnosticSeverity, FileDiagnostics } from "@/shared/proto/index.cline"
|
||||
import { diagnosticsToProblemsString, getNewDiagnostics } from "@/integrations/diagnostics"
|
||||
import { openFile } from "../misc/open-file"
|
||||
|
||||
export abstract class DiffViewProvider {
|
||||
editType?: "create" | "modify"
|
||||
@@ -261,13 +262,7 @@ export abstract class DiffViewProvider {
|
||||
// get text after save in case there is any auto-formatting done by the editor
|
||||
const postSaveContent = (await this.getDocumentText()) || ""
|
||||
|
||||
await HostProvider.window.showTextDocument({
|
||||
path: this.absolutePath,
|
||||
options: {
|
||||
preview: false,
|
||||
preserveFocus: true,
|
||||
},
|
||||
})
|
||||
await openFile(this.absolutePath, true)
|
||||
await this.closeAllDiffViews()
|
||||
|
||||
const newProblems = await this.getNewDiagnosticProblems()
|
||||
@@ -338,13 +333,7 @@ export abstract class DiffViewProvider {
|
||||
await this.saveDocument()
|
||||
console.log(`File ${this.absolutePath} has been reverted to its original content.`)
|
||||
if (this.documentWasOpen) {
|
||||
await HostProvider.window.showTextDocument({
|
||||
path: this.absolutePath,
|
||||
options: {
|
||||
preview: false,
|
||||
preserveFocus: true,
|
||||
},
|
||||
})
|
||||
openFile(this.absolutePath, true)
|
||||
}
|
||||
await this.closeAllDiffViews()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as path from "path"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { writeFile } from "@utils/fs"
|
||||
import { openFile } from "./open-file"
|
||||
|
||||
export async function downloadTask(dateTs: number, conversationHistory: Anthropic.MessageParam[]) {
|
||||
// File name
|
||||
@@ -42,10 +43,7 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
|
||||
try {
|
||||
// Write content to the selected location
|
||||
await writeFile(saveResponse.selectedPath, markdownContent)
|
||||
await HostProvider.window.showTextDocument({
|
||||
path: saveResponse.selectedPath,
|
||||
options: { preview: true },
|
||||
})
|
||||
await openFile(saveResponse.selectedPath, false, true)
|
||||
} catch (error) {
|
||||
await HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
|
||||
@@ -31,30 +31,11 @@ export async function openImage(dataUri: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function openFile(absolutePath: string) {
|
||||
export async function openFile(absolutePath: string, preserveFocus: boolean = false, preview: boolean = false) {
|
||||
try {
|
||||
const uri = vscode.Uri.file(absolutePath)
|
||||
|
||||
// Check if the document is already open in a tab group that's not in the active editor's column. If it is, then close it (if not dirty) so that we don't duplicate tabs
|
||||
try {
|
||||
for (const group of vscode.window.tabGroups.all) {
|
||||
const existingTab = group.tabs.find(
|
||||
(tab) => tab.input instanceof vscode.TabInputText && arePathsEqual(tab.input.uri.fsPath, uri.fsPath),
|
||||
)
|
||||
if (existingTab) {
|
||||
const activeColumn = vscode.window.activeTextEditor?.viewColumn
|
||||
const tabColumn = vscode.window.tabGroups.all.find((group) => group.tabs.includes(existingTab))?.viewColumn
|
||||
if (activeColumn && activeColumn !== tabColumn && !existingTab.isDirty) {
|
||||
await vscode.window.tabGroups.close(existingTab)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch {} // not essential, sometimes tab operations fail
|
||||
|
||||
await HostProvider.window.showTextDocument({
|
||||
path: uri.fsPath,
|
||||
options: { preview: false },
|
||||
path: absolutePath,
|
||||
options: { preserveFocus, preview },
|
||||
})
|
||||
} catch (error) {
|
||||
HostProvider.window.showMessage({
|
||||
|
||||
Reference in new issue
Block a user