Skip to content

Commit

Permalink
Support analysis / types with Rust Analyzer
Browse files Browse the repository at this point in the history
Fixes #881
It still takes a bit until diagnostics arrive, but this way error messages from `cargo` are included as well.
  • Loading branch information
Hofer-Julian committed Feb 14, 2024
1 parent 99d35b7 commit e06a7a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/langs/rust/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}};

Check failure on line 29 in src/langs/rust/rust.js

View workflow job for this annotation

GitHub Actions / CI

Replace `"cargo":·{"buildScripts":·{"useRustcWrapper":·false}},·"rust":·{"analyzerTargetDir":·rustAnalyzerCache}` with `⏎····cargo:·{·buildScripts:·{·useRustcWrapper:·false·}·},⏎····rust:·{·analyzerTargetDir:·rustAnalyzerCache·},⏎··`
lspc.start(initializationOptions).catch(console.error);

buffer.connect("modified-changed", () => {
if (!buffer.get_modified()) return;
Expand Down
7 changes: 4 additions & 3 deletions src/lsp/LSPClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -74,6 +74,7 @@ export default class LSPClient {
clientInfo,
capabilities,
rootUri,
initializationOptions,
locale: "en",
});

Expand Down

0 comments on commit e06a7a3

Please sign in to comment.