From e06a7a3c81c8c0eb9214c536a4139e2b77f0f1ea Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Wed, 14 Feb 2024 21:31:57 +0100 Subject: [PATCH] Support analysis / types with Rust Analyzer Fixes #881 It still takes a bit until diagnostics arrive, but this way error messages from `cargo` are included as well. --- src/langs/rust/rust.js | 8 ++++++-- src/lsp/LSPClient.js | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/langs/rust/rust.js b/src/langs/rust/rust.js index 29bd494cb..2b5c046c8 100644 --- a/src/langs/rust/rust.js +++ b/src/langs/rust/rust.js @@ -22,8 +22,12 @@ export function setup({ document }) { code_view.handleDiagnostics(params.diagnostics); }, ); - - lspc.start().catch(console.error); + const cacheDir = GLib.get_user_cache_dir(); + const rustAnalyzerCache = `${cacheDir}/rust_analyzer_cache`; + // It shouldn't be necessary to disable `useRustcWrapper`, stop doing that as soon as that issue is fixed + // https://github.com/rust-lang/rust-analyzer/issues/16565#issuecomment-1944354758 + const initializationOptions = {"cargo": {"buildScripts": {"useRustcWrapper": false}}, "rust": {"analyzerTargetDir": rustAnalyzerCache}}; + lspc.start(initializationOptions).catch(console.error); buffer.connect("modified-changed", () => { if (!buffer.get_modified()) return; diff --git a/src/lsp/LSPClient.js b/src/lsp/LSPClient.js index d5207ac42..67f13beae 100644 --- a/src/lsp/LSPClient.js +++ b/src/lsp/LSPClient.js @@ -45,10 +45,10 @@ export default class LSPClient { }; } - async start() { + async start(initializationOptions = {}) { this._start_process(); - await this._initialize(); + await this._initialize(initializationOptions); await this._didOpen(); this.ready = true; @@ -65,7 +65,7 @@ export default class LSPClient { return once(this, "ready"); } - async _initialize() { + async _initialize(initializationOptions = {}) { const { capabilities, rootUri } = this; // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize @@ -74,6 +74,7 @@ export default class LSPClient { clientInfo, capabilities, rootUri, + initializationOptions, locale: "en", });