Skip to content

Commit da5fa4e

Browse files
committed
fix: install lsp in getDefaultLsp instead of Parse
1 parent b65f2f0 commit da5fa4e

2 files changed

Lines changed: 6 additions & 32 deletions

File tree

lang/parse.go

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -165,38 +165,7 @@ func checkLSP(language uniast.Language, lspPath string, args ParseOptions) (l un
165165
return uniast.Unknown, "", fmt.Errorf("unsupported language: %s", language)
166166
}
167167
}
168-
169-
// lsp already installed
170-
if absLspPath, err := exec.LookPath(s); err == nil {
171-
return l, absLspPath, nil
172-
}
173-
174-
// install the lsp.
175-
log.Error("Language server %s not found. Trying to auto install.\n", s)
176-
s, err = installLanguageServer(language)
177-
if err == nil {
178-
if absLspPath, err := exec.LookPath(s); err == nil {
179-
log.Error("Auto installation ok. lspPath=%s.", absLspPath)
180-
return l, absLspPath, nil
181-
}
182-
}
183-
184-
// install failed or broken (lsp not in PATH)
185-
log.Info("Failed to install language server %s: %+w.\n", s, err)
186-
return uniast.Unknown, "", err
187-
}
188-
189-
func installLanguageServer(language uniast.Language) (string, error) {
190-
switch language {
191-
case uniast.Cxx:
192-
return cxx.InstallLanguageServer()
193-
case uniast.Python:
194-
return python.InstallLanguageServer()
195-
case uniast.Rust:
196-
return rust.InstallLanguageServer()
197-
default:
198-
return "", fmt.Errorf("auto installation not supported for language: %s", language)
199-
}
168+
return l, s, nil
200169
}
201170

202171
func collectSymbol(ctx context.Context, cli *lsp.LSPClient, repoPath string, opts collect.CollectOption) (repo *uniast.Repository, err error) {

lang/python/lib.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func CheckPythonVersion() error {
5656
}
5757

5858
func InstallLanguageServer() (string, error) {
59+
if out, err := exec.Command("pylsp", "--version").CombinedOutput(); err == nil {
60+
log.Info("pylsp already installed: %v", out)
61+
return lspName, nil
62+
}
5963
if _, err := os.Stat("go.mod"); os.IsNotExist(err) {
6064
log.Error("Auto installation requires working directory to be /path/to/abcoder/")
6165
return "", fmt.Errorf("bad cwd")
@@ -85,6 +89,7 @@ func InstallLanguageServer() (string, error) {
8589
}
8690

8791
func GetDefaultLSP() (lang uniast.Language, name string) {
92+
InstallLanguageServer()
8893
return uniast.Python, lspName
8994
}
9095

0 commit comments

Comments
 (0)