Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 1 addition & 32 deletions lang/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,38 +165,7 @@ func checkLSP(language uniast.Language, lspPath string, args ParseOptions) (l un
return uniast.Unknown, "", fmt.Errorf("unsupported language: %s", language)
}
}

// lsp already installed
if absLspPath, err := exec.LookPath(s); err == nil {
return l, absLspPath, nil
}

// install the lsp.
log.Error("Language server %s not found. Trying to auto install.\n", s)
s, err = installLanguageServer(language)
if err == nil {
if absLspPath, err := exec.LookPath(s); err == nil {
log.Error("Auto installation ok. lspPath=%s.", absLspPath)
return l, absLspPath, nil
}
}

// install failed or broken (lsp not in PATH)
log.Info("Failed to install language server %s: %+w.\n", s, err)
return uniast.Unknown, "", err
}

func installLanguageServer(language uniast.Language) (string, error) {
switch language {
case uniast.Cxx:
return cxx.InstallLanguageServer()
case uniast.Python:
return python.InstallLanguageServer()
case uniast.Rust:
return rust.InstallLanguageServer()
default:
return "", fmt.Errorf("auto installation not supported for language: %s", language)
}
return l, s, nil
}

func collectSymbol(ctx context.Context, cli *lsp.LSPClient, repoPath string, opts collect.CollectOption) (repo *uniast.Repository, err error) {
Expand Down
5 changes: 5 additions & 0 deletions lang/python/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func CheckPythonVersion() error {
}

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

func GetDefaultLSP() (lang uniast.Language, name string) {
InstallLanguageServer()
return uniast.Python, lspName
}

Expand Down
Loading