Skip to content

Commit 9c004c8

Browse files
committed
feat: automatically install rust LSP server
1 parent 282db4e commit 9c004c8

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lang/parse.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ func installLanguageServer(language uniast.Language) (string, error) {
192192
return cxx.InstallLanguageServer()
193193
case uniast.Python:
194194
return python.InstallLanguageServer()
195+
case uniast.Rust:
196+
return rust.InstallLanguageServer()
195197
default:
196198
return "", fmt.Errorf("auto installation not supported for language: %s", language)
197199
}

lang/rust/repo.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ import (
2929

3030
const MaxWaitDuration = 5 * time.Minute
3131

32+
func InstallLanguageServer() (string, error) {
33+
// check rustup exe exists
34+
if _, err := exec.LookPath("rustup"); err != nil {
35+
return "", fmt.Errorf("failed to find rustup, please install rustup first: https://rustup.rs")
36+
}
37+
if err := RunCmdInDir(".", "rustup", "component", "add", "rust-analyzer"); err != nil {
38+
return "", fmt.Errorf("failed to install rust-analyzer: %w", err)
39+
}
40+
return "rust-analyzer", nil
41+
}
42+
3243
func CheckRepo(repo string) (string, time.Duration) {
3344
// NOTICE: open the Cargo.toml file is required for Rust projects
3445
openfile := utils.FirstFile(repo, ".rs", filepath.Join(repo, "target"))

0 commit comments

Comments
 (0)