Skip to content

Rollup of 10 pull requests #103604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 73 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
f310d4c
Don't auto-publish lib crates
Veykril Sep 27, 2022
d7fb8d5
Migrate assists to format args captures, part 2
DropDemBits Oct 10, 2022
d5f467a
Substitute some VSCode variables in the VSCode client
Veykril Oct 16, 2022
a2e4f78
Auto merge of #13399 - DropDemBits:assists-format-args-capture-pt2, r…
bors Oct 17, 2022
40cbeb5
Auto merge of #13423 - Veykril:vscode-vars, r=Veykril
bors Oct 17, 2022
f079792
Auto merge of #13302 - Veykril:auto-publish, r=Veykril
bors Oct 17, 2022
6f43597
Refactor language client handling
Veykril Oct 17, 2022
8aaafdd
Properly reload changed configs for server start
Veykril Oct 17, 2022
d68616a
Make more things private
Veykril Oct 17, 2022
0421756
Implement stop and start server commands
Veykril Oct 17, 2022
7b5c943
Downgrade vscode types dependency
Veykril Oct 17, 2022
d63c44e
Cleanup output channels
Veykril Oct 17, 2022
067c410
Auto merge of #13426 - Veykril:client-refactor, r=Veykril
bors Oct 17, 2022
e41023c
Make flycheck workdone progress reports cancellable
Veykril Oct 17, 2022
106285b
Auto merge of #13427 - Veykril:cancel-check, r=Veykril
bors Oct 17, 2022
a762bac
fix: Fix formatting requests hanging when r-a is still starting
Veykril Oct 17, 2022
4d4c05d
Auto merge of #13428 - Veykril:fmt-stuck, r=Veykril
bors Oct 17, 2022
8047512
Revert "feat: Diagnose some incorrect usages of the question mark ope…
Veykril Oct 18, 2022
97b357e
Auto merge of #13433 - rust-lang:revert-13354-try-stuff, r=Veykril
bors Oct 18, 2022
9d3e616
Simplify
Veykril Oct 19, 2022
3392573
Auto merge of #13439 - Veykril:simplify, r=Veykril
bors Oct 19, 2022
653dafa
Add some sysroot logging
Veykril Oct 19, 2022
82ac6f7
Auto merge of #13441 - Veykril:sysroot-logging, r=Veykril
bors Oct 19, 2022
7e2c41d
Implement invocation strategy config for build scripts
Veykril Aug 27, 2022
4a287d2
Implement invocation strategy config for checkOnSave
Veykril Sep 15, 2022
5174b65
Use correct invocation strategy config for checkOnSave
Veykril Sep 15, 2022
7db5029
{manifest-path} interpolation
Veykril Sep 26, 2022
4673236
Remove simplistic interpolation for manifest-path
Veykril Oct 19, 2022
a77ac93
Auto merge of #13128 - Veykril:invocation-strategy, r=Veykril
bors Oct 19, 2022
69b8456
Don't catch the server activation error
Veykril Oct 20, 2022
32614e2
Auto merge of #13444 - Veykril:rethrow-err, r=Veykril
bors Oct 20, 2022
5bff6c5
feat: add multiple getters mode in `generate_getter`
feniljain Oct 7, 2022
f3cce5f
Auto merge of #13365 - feniljain:master, r=Veykril
bors Oct 20, 2022
de195ff
fix: Fix DidSaveDocument requests blocking the server on startup
Veykril Oct 20, 2022
e05df93
Workaround the python vscode extension's polyfill
yotamofek Oct 20, 2022
7741e3d
Auto merge of #13448 - yotamofek:python-ext-polyfill-workaround, r=Ve…
bors Oct 20, 2022
2481721
Auto merge of #13447 - Veykril:didsavedoc-block, r=Veykril
bors Oct 20, 2022
a8e0a20
internal: Properly handle language configuration config changes
Veykril Oct 20, 2022
69f01fd
Auto merge of #13451 - Veykril:lang-config, r=Veykril
bors Oct 20, 2022
1cb4607
internal: Properly handle commands in the VSCode client when the serv…
Veykril Oct 21, 2022
8ee23f4
Auto merge of #13453 - Veykril:disabled-commands, r=Veykril
bors Oct 21, 2022
7ee7225
scip: minor clean-ups
emilio Oct 22, 2022
bd49d01
ide: Remove unnecessary continue.
emilio Oct 22, 2022
ec6d72b
scip: Rewrite tests to be closer to what we actually do.
emilio Oct 21, 2022
b643dd6
Auto merge of #13461 - emilio:ide-cleanup-continue, r=Veykril
bors Oct 22, 2022
d3b7e94
Auto merge of #13460 - emilio:scip-cleanups, r=Veykril
bors Oct 22, 2022
6459d7f
Support const generics for builtin derive macro
lowr Oct 22, 2022
19efa0b
Auto merge of #13463 - lowr:fix/builtin-derive-with-const-generics, r…
bors Oct 22, 2022
0f8904e
Implement invocation location config
Veykril Oct 22, 2022
b25f657
Auto merge of #13466 - Veykril:invocation-location, r=Veykril
bors Oct 22, 2022
859f559
Handle multiple projects sharing dependency correctly in `once` strategy
Veykril Oct 23, 2022
43fb956
Auto merge of #13471 - Veykril:invoc-strategy-once, r=Veykril
bors Oct 23, 2022
63d1a72
rustdoc: don't mark Box<T> as Iterator, Read, etc
jsha Oct 23, 2022
c246a3d
more dupe typos again
Rageking8 Oct 25, 2022
626d7fc
rustdoc: combine shared CSS between `.*-line-numbers`
notriddle Oct 25, 2022
6ea75ae
llvm-16: Don't initialize removed legacy passes
maurer Oct 25, 2022
67c4c1f
Update cargo
weihanglo Oct 26, 2022
99a74af
ptr::eq: clarify that comparing dyn Trait is fragile
RalfJung Oct 26, 2022
1946a18
explicitly mention that both components of wide prts are compared
RalfJung Oct 26, 2022
22a6bc4
:arrow_up: rust-analyzer
lnicola Oct 26, 2022
cce46e9
Fix typo in docs for `guaranteed_ne`
Oct 26, 2022
d1132fb
thread::set_name: debug-assert that things went well
RalfJung Oct 26, 2022
b66f921
rustc_lexer::TokenKind improve docs
tshepang Oct 26, 2022
ec7ffdf
Rollup merge of #103432 - jsha:box-is-not-notable, r=GuillaumeGomez
Oct 26, 2022
cafb63d
Rollup merge of #103526 - Rageking8:more-dupe-typos-again, r=Mark-Sim…
Oct 26, 2022
4907614
Rollup merge of #103537 - notriddle:notriddle/line-numbers, r=Guillau…
Oct 26, 2022
6e1de0e
Rollup merge of #103549 - maurer:llvm-main, r=cuviper
Oct 26, 2022
3bfe39e
Rollup merge of #103558 - weihanglo:update-cargo, r=weihanglo
Oct 26, 2022
26ad51f
Rollup merge of #103567 - RalfJung:ptr-eq-dyn-trait, r=dtolnay
Oct 26, 2022
1d5f328
Rollup merge of #103579 - lnicola:rust-analyzer-2022-10-26, r=lnicola
Oct 26, 2022
77145c0
Rollup merge of #103580 - lukas-code:guaranteed_ne, r=GuillaumeGomez
Oct 26, 2022
b4b3ff4
Rollup merge of #103596 - RalfJung:thread-setname, r=cuviper
Oct 26, 2022
132883e
Rollup merge of #103598 - tshepang:token-kind-docs, r=jackh726
Oct 26, 2022
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
Prev Previous commit
Next Next commit
Refactor language client handling
  • Loading branch information
Veykril committed Oct 17, 2022
commit 6f435977df34e722b45d787d7eadac23cf5b040e
78 changes: 39 additions & 39 deletions editors/code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"dependencies": {
"d3": "^7.6.1",
"d3-graphviz": "^4.1.1",
"vscode-languageclient": "^8.0.0-next.14"
"vscode-languageclient": "^8.0.2"
},
"devDependencies": {
"@types/node": "~16.11.7",
"@types/vscode": "~1.66.0",
"@types/vscode": "~1.72.0",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"@vscode/test-electron": "^2.1.5",
Expand Down
8 changes: 5 additions & 3 deletions editors/code/src/ast_inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
});

constructor(ctx: Ctx) {
ctx.pushCleanup(vscode.languages.registerHoverProvider({ scheme: "rust-analyzer" }, this));
ctx.pushCleanup(vscode.languages.registerDefinitionProvider({ language: "rust" }, this));
ctx.pushExtCleanup(
vscode.languages.registerHoverProvider({ scheme: "rust-analyzer" }, this)
);
ctx.pushExtCleanup(vscode.languages.registerDefinitionProvider({ language: "rust" }, this));
vscode.workspace.onDidCloseTextDocument(
this.onDidCloseTextDocument,
this,
Expand All @@ -53,7 +55,7 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
ctx.subscriptions
);

ctx.pushCleanup(this);
ctx.pushExtCleanup(this);
}
dispose() {
this.setRustEditor(undefined);
Expand Down
148 changes: 148 additions & 0 deletions editors/code/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import * as vscode from "vscode";
import * as os from "os";
import { Config } from "./config";
import { log, isValidExecutable } from "./util";
import { PersistentState } from "./persistent_state";
import { exec } from "child_process";

export async function bootstrap(
context: vscode.ExtensionContext,
config: Config,
state: PersistentState
): Promise<string> {
const path = await getServer(context, config, state);
if (!path) {
throw new Error(
"Rust Analyzer Language Server is not available. " +
"Please, ensure its [proper installation](https://rust-analyzer.github.io/manual.html#installation)."
);
}

log.info("Using server binary at", path);

if (!isValidExecutable(path)) {
if (config.serverPath) {
throw new Error(`Failed to execute ${path} --version. \`config.server.path\` or \`config.serverPath\` has been set explicitly.\
Consider removing this config or making a valid server binary available at that path.`);
} else {
throw new Error(`Failed to execute ${path} --version`);
}
}

return path;
}

async function patchelf(dest: vscode.Uri): Promise<void> {
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Patching rust-analyzer for NixOS",
},
async (progress, _) => {
const expression = `
{srcStr, pkgs ? import <nixpkgs> {}}:
pkgs.stdenv.mkDerivation {
name = "rust-analyzer";
src = /. + srcStr;
phases = [ "installPhase" "fixupPhase" ];
installPhase = "cp $src $out";
fixupPhase = ''
chmod 755 $out
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out
'';
}
`;
const origFile = vscode.Uri.file(dest.fsPath + "-orig");
await vscode.workspace.fs.rename(dest, origFile, { overwrite: true });
try {
progress.report({ message: "Patching executable", increment: 20 });
await new Promise((resolve, reject) => {
const handle = exec(
`nix-build -E - --argstr srcStr '${origFile.fsPath}' -o '${dest.fsPath}'`,
(err, stdout, stderr) => {
if (err != null) {
reject(Error(stderr));
} else {
resolve(stdout);
}
}
);
handle.stdin?.write(expression);
handle.stdin?.end();
});
} finally {
await vscode.workspace.fs.delete(origFile);
}
}
);
}

async function getServer(
context: vscode.ExtensionContext,
config: Config,
state: PersistentState
): Promise<string | undefined> {
const explicitPath = serverPath(config);
if (explicitPath) {
if (explicitPath.startsWith("~/")) {
return os.homedir() + explicitPath.slice("~".length);
}
return explicitPath;
}
if (config.package.releaseTag === null) return "rust-analyzer";

const ext = process.platform === "win32" ? ".exe" : "";
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
const bundledExists = await vscode.workspace.fs.stat(bundled).then(
() => true,
() => false
);
if (bundledExists) {
let server = bundled;
if (await isNixOs()) {
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer${ext}`);
let exists = await vscode.workspace.fs.stat(dest).then(
() => true,
() => false
);
if (exists && config.package.version !== state.serverVersion) {
await vscode.workspace.fs.delete(dest);
exists = false;
}
if (!exists) {
await vscode.workspace.fs.copy(bundled, dest);
await patchelf(dest);
}
server = dest;
}
await state.updateServerVersion(config.package.version);
return server.fsPath;
}

await state.updateServerVersion(undefined);
await vscode.window.showErrorMessage(
"Unfortunately we don't ship binaries for your platform yet. " +
"You need to manually clone the rust-analyzer repository and " +
"run `cargo xtask install --server` to build the language server from sources. " +
"If you feel that your platform should be supported, please create an issue " +
"about that [here](https://github.com/rust-lang/rust-analyzer/issues) and we " +
"will consider it."
);
return undefined;
}
function serverPath(config: Config): string | null {
return process.env.__RA_LSP_SERVER_DEBUG ?? config.serverPath;
}

async function isNixOs(): Promise<boolean> {
try {
const contents = (
await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))
).toString();
const idString = contents.split("\n").find((a) => a.startsWith("ID=")) || "ID=linux";
return idString.indexOf("nixos") !== -1;
} catch {
return false;
}
}
43 changes: 10 additions & 33 deletions editors/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import * as ra from "../src/lsp_ext";
import * as Is from "vscode-languageclient/lib/common/utils/is";
import { assert } from "./util";
import { WorkspaceEdit } from "vscode";
import { Workspace } from "./ctx";
import { substituteVariablesInEnv, substituteVSCodeVariables } from "./config";
import { outputChannel, traceOutputChannel } from "./main";
import { substituteVSCodeVariables } from "./config";
import { randomUUID } from "crypto";

export interface Env {
Expand Down Expand Up @@ -65,41 +63,17 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri
}

export async function createClient(
serverPath: string,
workspace: Workspace,
extraEnv: Env
traceOutputChannel: vscode.OutputChannel,
outputChannel: vscode.OutputChannel,
initializationOptions: vscode.WorkspaceConfiguration,
serverOptions: lc.ServerOptions
): Promise<lc.LanguageClient> {
// '.' Is the fallback if no folder is open
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
// It might be a good idea to test if the uri points to a file.

const newEnv = substituteVariablesInEnv(Object.assign({}, process.env, extraEnv));
const run: lc.Executable = {
command: serverPath,
options: { env: newEnv },
};
const serverOptions: lc.ServerOptions = {
run,
debug: run,
};

let rawInitializationOptions = vscode.workspace.getConfiguration("rust-analyzer");

if (workspace.kind === "Detached Files") {
rawInitializationOptions = {
detachedFiles: workspace.files.map((file) => file.uri.fsPath),
...rawInitializationOptions,
};
}

const initializationOptions = substituteVSCodeVariables(rawInitializationOptions);

const clientOptions: lc.LanguageClientOptions = {
documentSelector: [{ scheme: "file", language: "rust" }],
initializationOptions,
diagnosticCollectionName: "rustc",
traceOutputChannel: traceOutputChannel(),
outputChannel: outputChannel(),
traceOutputChannel,
outputChannel,
middleware: {
workspace: {
async configuration(
Expand Down Expand Up @@ -273,6 +247,9 @@ export async function createClient(
}

class ExperimentalFeatures implements lc.StaticFeature {
getState(): lc.FeatureState {
return { kind: "static" };
}
fillClientCapabilities(capabilities: lc.ClientCapabilities): void {
const caps: any = capabilities.experimental ?? {};
caps.snippetTextEdit = true;
Expand Down
Loading