Skip to content

Commit e06a7a3

Browse files
committed
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.
1 parent 99d35b7 commit e06a7a3

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/langs/rust/rust.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ export function setup({ document }) {
2222
code_view.handleDiagnostics(params.diagnostics);
2323
},
2424
);
25-
26-
lspc.start().catch(console.error);
25+
const cacheDir = GLib.get_user_cache_dir();
26+
const rustAnalyzerCache = `${cacheDir}/rust_analyzer_cache`;
27+
// It shouldn't be necessary to disable `useRustcWrapper`, stop doing that as soon as that issue is fixed
28+
// https://github.com/rust-lang/rust-analyzer/issues/16565#issuecomment-1944354758
29+
const initializationOptions = {"cargo": {"buildScripts": {"useRustcWrapper": false}}, "rust": {"analyzerTargetDir": rustAnalyzerCache}};
30+
lspc.start(initializationOptions).catch(console.error);
2731

2832
buffer.connect("modified-changed", () => {
2933
if (!buffer.get_modified()) return;

src/lsp/LSPClient.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ export default class LSPClient {
4545
};
4646
}
4747

48-
async start() {
48+
async start(initializationOptions = {}) {
4949
this._start_process();
5050

51-
await this._initialize();
51+
await this._initialize(initializationOptions);
5252
await this._didOpen();
5353

5454
this.ready = true;
@@ -65,7 +65,7 @@ export default class LSPClient {
6565
return once(this, "ready");
6666
}
6767

68-
async _initialize() {
68+
async _initialize(initializationOptions = {}) {
6969
const { capabilities, rootUri } = this;
7070

7171
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize
@@ -74,6 +74,7 @@ export default class LSPClient {
7474
clientInfo,
7575
capabilities,
7676
rootUri,
77+
initializationOptions,
7778
locale: "en",
7879
});
7980

0 commit comments

Comments
 (0)