about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-09-27 21:35:10 +0200
committerGitHub <noreply@github.com>2024-09-27 21:35:10 +0200
commit243c6d67ffb13ba5ec8536e32f810fee0578c3bc (patch)
tree4cccdfbb0db819fe2ae0d00b3418242a27d06133
parent22c1009e7f3ba4749428b35eb1be94afdda7a8b5 (diff)
parenta1846ec22f33748aca79b2106fa85c3576e5db68 (diff)
downloadrust-243c6d67ffb13ba5ec8536e32f810fee0578c3bc.tar.gz
rust-243c6d67ffb13ba5ec8536e32f810fee0578c3bc.zip
Rollup merge of #130932 - mrkajetanp:editors, r=jieyouxu
etc: Add sample rust-analyzer configs for eglot & helix

LSP configuration in editors like Emacs (eglot) and helix does not
use the same JSON format as vscode and vim do. It is not obvious
how to set up LSP for rustc in those editors and the dev guide currently
does not cover them. Adding sample configuration files for those editors
alongside the currently existing JSON one would be helpful.

I figured having those included in the repo like the JSON one might save
someone some time and frustration otherwise spent on trying to get the
more niche editors' LSP to work properly. I'll add a section in the dev
guide too.
-rw-r--r--.gitignore1
-rw-r--r--src/etc/rust_analyzer_eglot.el29
-rw-r--r--src/etc/rust_analyzer_helix.toml49
3 files changed, 79 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 2e6499081a6..d6d8b99f602 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,6 +25,7 @@ Session.vim
 .favorites.json
 .settings/
 .vs/
+.dir-locals.el
 
 ## Tool
 .valgrindrc
diff --git a/src/etc/rust_analyzer_eglot.el b/src/etc/rust_analyzer_eglot.el
new file mode 100644
index 00000000000..e55d80d98de
--- /dev/null
+++ b/src/etc/rust_analyzer_eglot.el
@@ -0,0 +1,29 @@
+((rustic-mode
+  .((eglot-workspace-configuration
+     . (:rust-analyzer
+        ( :check ( :invocationLocation "root"
+                   :invocationStrategy "once"
+                   :overrideCommand ["python3"
+                                     "x.py"
+                                     "check"
+                                     "--json-output"])
+          :linkedProjects ["Cargo.toml"
+                           "src/tools/x/Cargo.toml"
+                           "src/bootstrap/Cargo.toml"
+                           "src/tools/rust-analyzer/Cargo.toml"
+                           "compiler/rustc_codegen_cranelift/Cargo.toml"
+                           "compiler/rustc_codegen_gcc/Cargo.toml"]
+          :rustfmt ( :overrideCommand ["build/host/rustfmt/bin/rustfmt"
+                                       "--edition=2021"])
+          :procMacro ( :server "build/host/stage0/libexec/rust-analyzer-proc-macro-srv"
+                       :enable t)
+          :cargo ( :buildScripts ( :enable t
+                                   :invocationLocation "root"
+                                   :invocationStrategy "once"
+                                   :overrideCommand ["python3"
+                                                     "x.py"
+                                                     "check"
+                                                     "--json-output"])
+                   :sysrootSrc "./library"
+                   :extraEnv (:RUSTC_BOOTSTRAP "1"))
+          :rustc ( :source "./Cargo.toml" )))))))
diff --git a/src/etc/rust_analyzer_helix.toml b/src/etc/rust_analyzer_helix.toml
new file mode 100644
index 00000000000..642350cad34
--- /dev/null
+++ b/src/etc/rust_analyzer_helix.toml
@@ -0,0 +1,49 @@
+[language-server.rust-analyzer.config]
+linkedProjects = [
+    "Cargo.toml",
+    "src/tools/x/Cargo.toml",
+    "src/bootstrap/Cargo.toml",
+    "src/tools/rust-analyzer/Cargo.toml",
+    "compiler/rustc_codegen_cranelift/Cargo.toml",
+    "compiler/rustc_codegen_gcc/Cargo.toml"
+]
+
+[language-server.rust-analyzer.config.check]
+invocationLocation = "root"
+invocationStrategy = "once"
+overrideCommand = [
+    "python3",
+    "x.py",
+    "check",
+    "--json-output",
+]
+
+[language-server.rust-analyzer.config.rustfmt]
+overrideCommand = [
+    "build-rust-analyzer/host/rustfmt/bin/rustfmt",
+    "--edition=2021"
+]
+
+[language-server.rust-analyzer.config.procMacro]
+server = "build-rust-analyzer/host/stage0/libexec/rust-analyzer-proc-macro-srv"
+enable = true
+
+[language-server.rust-analyzer.config.rustc]
+source = "./Cargo.toml"
+
+[language-server.rust-analyzer.config.cargo]
+sysrootSrc = "./library"
+
+[language-server.rust-analyzer.config.cargo.extraEnv]
+RUSTC_BOOTSTRAP = "1"
+
+[language-server.rust-analyzer.config.cargo.buildScripts]
+enable = true
+invocationLocation = "root"
+invocationStrategy = "once"
+overrideCommand = [
+    "python3",
+    "x.py",
+    "check",
+    "--json-output",
+]