Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions editors/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export async function deactivate() {
}

async function bootstrap(config: Config, state: PersistentState): Promise<string> {
await vscode.workspace.fs.createDirectory(config.globalStorageUri);
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();

if (!config.currentExtensionIsNightly) {
await state.updateNightlyReleaseId(undefined);
Expand Down Expand Up @@ -277,11 +277,11 @@ async function patchelf(dest: vscode.Uri): Promise<void> {
'';
}
`;
const origFile = vscode.Uri.file(dest.path + "-orig");
const origFile = vscode.Uri.file(dest.fsPath + "-orig");
await vscode.workspace.fs.rename(dest, origFile);
progress.report({ message: "Patching executable", increment: 20 });
await new Promise((resolve, reject) => {
const handle = exec(`nix-build -E - --argstr srcStr '${origFile.path}' -o '${dest.path}'`,
const handle = exec(`nix-build -E - --argstr srcStr '${origFile.fsPath}' -o '${dest.fsPath}'`,
(err, stdout, stderr) => {
if (err != null) {
reject(Error(stderr));
Expand Down Expand Up @@ -338,14 +338,14 @@ async function getServer(config: Config, state: PersistentState): Promise<string
await state.updateServerVersion(undefined);
}

if (state.serverVersion === config.package.version) return dest.path;
if (state.serverVersion === config.package.version) return dest.fsPath;

if (config.askBeforeDownload) {
const userResponse = await vscode.window.showInformationMessage(
`Language server version ${config.package.version} for rust-analyzer is not installed.`,
"Download now"
);
if (userResponse !== "Download now") return dest.path;
if (userResponse !== "Download now") return dest.fsPath;
}

const releaseTag = config.package.releaseTag;
Expand All @@ -372,7 +372,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
}

await state.updateServerVersion(config.package.version);
return dest.path;
return dest.fsPath;
}

function serverPath(config: Config): string | null {
Expand All @@ -383,7 +383,7 @@ async function isNixOs(): Promise<boolean> {
try {
const contents = (await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))).toString();
return contents.indexOf("ID=nixos") !== -1;
} catch (e) {
} catch {
return false;
}
}
Expand Down
8 changes: 4 additions & 4 deletions editors/code/src/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function download(opts: DownloadOpts) {
// to prevent partially downloaded files when user kills vscode
// This also avoids overwriting running executables
const randomHex = crypto.randomBytes(5).toString("hex");
const rawDest = path.parse(opts.dest.path);
const rawDest = path.parse(opts.dest.fsPath);
const tempFilePath = vscode.Uri.joinPath(vscode.Uri.file(rawDest.dir), `${rawDest.name}${randomHex}`);

await vscode.window.withProgress(
Expand All @@ -116,7 +116,7 @@ export async function download(opts: DownloadOpts) {
}
);

await vscode.workspace.fs.rename(tempFilePath, opts.dest);
await vscode.workspace.fs.rename(tempFilePath, opts.dest, { overwrite: true });
}

async function downloadFile(
Expand Down Expand Up @@ -148,15 +148,15 @@ async function downloadFile(
const totalBytes = Number(res.headers.get('content-length'));
assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol");

log.debug("Downloading file of", totalBytes, "bytes size from", urlString, "to", destFilePath.path);
log.debug("Downloading file of", totalBytes, "bytes size from", urlString, "to", destFilePath.fsPath);

let readBytes = 0;
res.body.on("data", (chunk: Buffer) => {
readBytes += chunk.length;
onProgress(readBytes, totalBytes);
});

const destFileStream = fs.createWriteStream(destFilePath.path, { mode });
const destFileStream = fs.createWriteStream(destFilePath.fsPath, { mode });
const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body;

await pipeline(srcStream, destFileStream);
Expand Down
16 changes: 12 additions & 4 deletions editors/code/src/toolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const getPathForExecutable = memoize(
// it is not mentioned in docs and cannot be infered by the type signature...
const standardPath = vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo", "bin", executableName);

if (isFile(standardPath.path)) return standardPath.path;
if (isFileAtUri(standardPath)) return standardPath.fsPath;
} catch (err) {
log.error("Failed to read the fs info", err);
}
Expand All @@ -177,9 +177,17 @@ function lookupInPath(exec: string): boolean {
: [candidate];
});

return candidates.some(isFile);
return candidates.some(isFileAtPath);
}

async function isFile(path: string): Promise<boolean> {
return ((await vscode.workspace.fs.stat(vscode.Uri.file(path))).type & vscode.FileType.File) !== 0;
async function isFileAtPath(path: string): Promise<boolean> {
return isFileAtUri(vscode.Uri.file(path));
}

async function isFileAtUri(uri: vscode.Uri): Promise<boolean> {
try {
return ((await vscode.workspace.fs.stat(uri)).type & vscode.FileType.File) !== 0;
} catch {
return false;
}
}