diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-08-25 13:38:41 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-08-25 13:38:41 -0700 |
commit | e5f56308c5fd87695278682b2a36ca60df0db863 (patch) | |
tree | c7d66f5a3b56ce762bfd26033890597a07099007 /extension/src/continueIdeClient.ts | |
parent | a55d64127a1e972d03f54a175b54eb0ad78e2b0e (diff) | |
download | sncontinue-e5f56308c5fd87695278682b2a36ca60df0db863.tar.gz sncontinue-e5f56308c5fd87695278682b2a36ca60df0db863.tar.bz2 sncontinue-e5f56308c5fd87695278682b2a36ca60df0db863.zip |
fix: :bug: ssh compatibility by reading from vscode.workspace.fs
Diffstat (limited to 'extension/src/continueIdeClient.ts')
-rw-r--r-- | extension/src/continueIdeClient.ts | 65 |
1 files changed, 49 insertions, 16 deletions
diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts index 430bb9dd..19575b13 100644 --- a/extension/src/continueIdeClient.ts +++ b/extension/src/continueIdeClient.ts @@ -12,10 +12,10 @@ import { rejectSuggestionCommand, } from "./suggestions"; import { FileEditWithFullContents } from "../schema/FileEditWithFullContents"; -import * as fs from "fs"; import { WebsocketMessenger } from "./util/messenger"; import { diffManager } from "./diffs"; const os = require("os"); +const path = require("path"); const continueVirtualDocumentScheme = "continue"; @@ -253,7 +253,7 @@ class IdeProtocolClient { break; case "readFile": messenger.send("readFile", { - contents: this.readFile(data.filepath), + contents: await this.readFile(data.filepath), }); break; case "getTerminalContents": @@ -261,6 +261,44 @@ class IdeProtocolClient { contents: await this.getTerminalContents(), }); break; + case "listDirectoryContents": + messenger.send("listDirectoryContents", { + contents: ( + await vscode.workspace.fs.readDirectory( + vscode.Uri.file(data.directory) + ) + ) + .map(([name, type]) => name) + .filter((name) => { + const DEFAULT_IGNORE_DIRS = [ + ".git", + ".vscode", + ".idea", + ".vs", + ".venv", + "env", + ".env", + "node_modules", + "dist", + "build", + "target", + "out", + "bin", + ".pytest_cache", + ".vscode-test", + ".continue", + "__pycache__", + ]; + if ( + !DEFAULT_IGNORE_DIRS.some((dir) => + name.split(path.sep).includes(dir) + ) + ) { + return name; + } + }), + }); + break; case "editFile": const fileEdit = await this.editFile(data.edit); messenger.send("editFile", { @@ -306,7 +344,7 @@ class IdeProtocolClient { this.showSuggestion(data.edit); break; case "showDiff": - this.showDiff(data.filepath, data.replacement, data.step_index); + await this.showDiff(data.filepath, data.replacement, data.step_index); break; case "getSessionId": case "connected": @@ -385,8 +423,8 @@ class IdeProtocolClient { ); } - showDiff(filepath: string, replacement: string, step_index: number) { - diffManager.writeDiff(filepath, replacement, step_index); + async showDiff(filepath: string, replacement: string, step_index: number) { + await diffManager.writeDiff(filepath, replacement, step_index); } openFile(filepath: string) { @@ -506,19 +544,14 @@ class IdeProtocolClient { }); } - readFile(filepath: string): string { + async readFile(filepath: string): Promise<string> { let contents: string | undefined; - vscode.window.visibleTextEditors - .filter((editor) => this.editorIsCode(editor)) - .forEach((editor) => { - if (editor.document.uri.fsPath === filepath) { - contents = editor.document.getText(); - } - }); if (typeof contents === "undefined") { - if (fs.existsSync(filepath)) { - contents = fs.readFileSync(filepath, "utf-8"); - } else { + try { + contents = await vscode.workspace.fs + .readFile(vscode.Uri.file(filepath)) + .then((bytes) => new TextDecoder().decode(bytes)); + } catch { contents = ""; } } |