4555: VSCode: added patchelf after download for NixOS support r=matklad a=cab404

This adds Nix support, and fixes #4542 

4575: Use Chalk's built-in representations for fn items and pointers r=matklad a=flodiebold

The `TypeName::FnDef` was just added; the function pointer variant has existed for a while, I just forgot about it because it's special (because fn pointers can be higher-ranked over lifetimes).

We *could* also make `FnPtr` a separate `Ty` variant instead of a `TypeCtor` variant, which would make the conversion code a bit less special-casey, but it doesn't seem worth doing right now.

Co-authored-by: Vladimir Serov <me@cab404.ru>
Co-authored-by: Cabia Rangris <me@cab404.ru>
Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
This commit is contained in:
bors[bot] 2020-05-23 11:32:26 +00:00 committed by GitHub
commit 4cc2ff6e39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 227 additions and 19 deletions

View file

@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import * as path from "path";
import * as os from "os";
import { promises as fs } from "fs";
import { promises as fs, PathLike } from "fs";
import * as commands from './commands';
import { activateInlayHints } from './inlay_hints';
@ -12,6 +12,7 @@ import { log, assert, isValidExecutable } from './util';
import { PersistentState } from './persistent_state';
import { fetchRelease, download } from './net';
import { activateTaskProvider } from './tasks';
import { exec } from 'child_process';
let ctx: Ctx | undefined;
@ -188,6 +189,46 @@ async function bootstrapServer(config: Config, state: PersistentState): Promise<
return path;
}
async function patchelf(dest: PathLike): Promise<void> {
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Patching rust-analyzer for NixOS"
},
async (progress, _) => {
const expression = `
{src, pkgs ? import <nixpkgs> {}}:
pkgs.stdenv.mkDerivation {
name = "rust-analyzer";
inherit src;
phases = [ "installPhase" "fixupPhase" ];
installPhase = "cp $src $out";
fixupPhase = ''
chmod 755 $out
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out
'';
}
`;
const origFile = dest + "-orig";
await fs.rename(dest, origFile);
progress.report({ message: "Patching executable", increment: 20 });
await new Promise((resolve, reject) => {
const handle = exec(`nix-build -E - --arg src '${origFile}' -o ${dest}`,
(err, stdout, stderr) => {
if (err != null) {
reject(Error(stderr));
} else {
resolve(stdout);
}
});
handle.stdin?.write(expression);
handle.stdin?.end();
});
await fs.unlink(origFile);
}
);
}
async function getServer(config: Config, state: PersistentState): Promise<string | undefined> {
const explicitPath = process.env.__RA_LSP_SERVER_DEBUG ?? config.serverPath;
if (explicitPath) {
@ -237,6 +278,12 @@ async function getServer(config: Config, state: PersistentState): Promise<string
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
await download(artifact.browser_download_url, dest, "Downloading rust-analyzer server", { mode: 0o755 });
// Patching executable if that's NixOS.
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
await patchelf(dest);
}
await state.updateServerVersion(config.package.version);
return dest;
}