fix: 🐛 correctly generate uris for remote

This commit is contained in:
Nate Sesti 2023-08-26 23:21:26 -07:00
parent 868875aa5d
commit ab31cb15fa
5 changed files with 24 additions and 20 deletions

View file

@ -820,14 +820,6 @@ Please output the code to be inserted at the cursor in order to fulfill the user
rif_dict[rif.filepath] = rif.contents
for rif in rif_with_contents:
# If the file doesn't exist, ask them to save it first
exists = await sdk.ide.fileExists(rif.filepath)
if not exists:
message = (
f"The file {rif.filepath} does not exist. Please save it first."
)
raise ContinueCustomException(title=message, message=message)
await sdk.ide.setFileOpen(rif.filepath)
await sdk.ide.setSuggestionsLocked(rif.filepath, True)
await self.stream_rif(rif, sdk)

View file

@ -3,7 +3,7 @@ import {
showSuggestion as showSuggestionInEditor,
SuggestionRanges,
} from "./suggestions";
import { openEditorAndRevealRange } from "./util/vscode";
import { openEditorAndRevealRange, uriFromFilePath } from "./util/vscode";
import { FileEdit } from "../schema/FileEdit";
import { RangeInFile } from "../schema/RangeInFile";
import * as vscode from "vscode";
@ -270,7 +270,7 @@ class IdeProtocolClient {
messenger.send("listDirectoryContents", {
contents: (
await vscode.workspace.fs.readDirectory(
vscode.Uri.file(data.directory)
uriFromFilePath(data.directory)
)
)
.map(([name, type]) => name)
@ -439,7 +439,7 @@ class IdeProtocolClient {
async fileExists(filepath: string): Promise<boolean> {
try {
await vscode.workspace.fs.stat(vscode.Uri.file(filepath));
await vscode.workspace.fs.stat(uriFromFilePath(filepath));
return true;
} catch {
return false;
@ -563,7 +563,7 @@ class IdeProtocolClient {
if (typeof contents === "undefined") {
try {
contents = await vscode.workspace.fs
.readFile(vscode.Uri.file(filepath))
.readFile(uriFromFilePath(filepath))
.then((bytes) => new TextDecoder().decode(bytes));
} catch {
contents = "";

View file

@ -1,12 +1,13 @@
import * as vscode from "vscode";
import * as path from "path";
import { uriFromFilePath } from "./util/vscode";
export function showAnswerInTextEditor(
filename: string,
range: vscode.Range,
answer: string
) {
vscode.workspace.openTextDocument(vscode.Uri.file(filename)).then((doc) => {
vscode.workspace.openTextDocument(uriFromFilePath(filename)).then((doc) => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;

View file

@ -5,6 +5,7 @@ import * as vscode from "vscode";
import { extensionContext, ideProtocolClient } from "./activation/activate";
import { getMetaKeyLabel } from "./util/util";
import { devDataPath } from "./activation/environmentSetup";
import { uriFromFilePath } from "./util/vscode";
interface DiffInfo {
originalFilepath: string;
@ -16,13 +17,13 @@ interface DiffInfo {
async function readFile(path: string): Promise<string> {
return await vscode.workspace.fs
.readFile(vscode.Uri.file(path))
.readFile(uriFromFilePath(path))
.then((bytes) => new TextDecoder().decode(bytes));
}
async function writeFile(path: string, contents: string) {
await vscode.workspace.fs.writeFile(
vscode.Uri.file(path),
uriFromFilePath(path),
new TextEncoder().encode(contents)
);
}
@ -42,7 +43,7 @@ class DiffManager {
private async setupDirectory() {
// Make sure the diff directory exists
await vscode.workspace.fs.createDirectory(vscode.Uri.file(DIFF_DIRECTORY));
await vscode.workspace.fs.createDirectory(uriFromFilePath(DIFF_DIRECTORY));
}
constructor() {
@ -72,7 +73,7 @@ class DiffManager {
): Promise<vscode.TextEditor | undefined> {
// If the file doesn't yet exist or the basename is a single digit number (vscode terminal), don't open the diff editor
try {
await vscode.workspace.fs.stat(vscode.Uri.file(newFilepath));
await vscode.workspace.fs.stat(uriFromFilePath(newFilepath));
} catch {
return undefined;
}
@ -80,8 +81,8 @@ class DiffManager {
return undefined;
}
const rightUri = vscode.Uri.file(newFilepath);
const leftUri = vscode.Uri.file(originalFilepath);
const rightUri = uriFromFilePath(newFilepath);
const leftUri = uriFromFilePath(originalFilepath);
const title = "Continue Diff";
console.log(
"Opening diff window with ",
@ -177,7 +178,7 @@ class DiffManager {
vscode.commands.executeCommand(
"workbench.action.files.revert",
vscode.Uri.file(newFilepath)
uriFromFilePath(newFilepath)
);
return newFilepath;

View file

@ -102,3 +102,13 @@ export function openEditorAndRevealRange(
});
});
}
export function uriFromFilePath(filepath: string): vscode.Uri {
if (vscode.env.remoteName) {
return vscode.Uri.parse(
`vscode-remote://${vscode.env.remoteName}${filepath}`
);
} else {
return vscode.Uri.file(filepath);
}
}