Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
[submodule "pylsp"]
path = pylsp
url = https://github.com/Hoblovski/python-lsp-server.git
branch = abc
16 changes: 8 additions & 8 deletions docs/lsp-installation-en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Language Server Installation

To parse dependencies between symbols in a repository, the abcoder parser requires the use of language servers for various languages. Please install the corresponding language server before running the parser.
ABCoder automatically installs the corresponding language server for most languages.
Should the automatic installation fail, please install manually following the instructions below.

The mapping between languages and language servers is as follows:

Expand All @@ -25,14 +26,13 @@ Ensure the corresponding executable is in PATH before running abcoder.

## Python
* Install Python 3.9+
* Install pylsp from the git submodule:
* Install pylsp
```bash
$ git submodule init
$ git submodule update
$ cd pylsp
$ pip install -e . # Consider executing in a separate conda/venv environment
$ export PATH=$(realpath ./bin):$PATH # Add this to your .rc file, or set it before each abcoder run
$ pylsp --version # Verify successful installation
$ git clone https://github.com/Hoblovski/python-lsp-server.git -b abc
$ cd python-lsp-server
$ pip install .
$ export PATH=$(realpath ./bin):$PATH
$ pylsp --version
```

## C
Expand Down
14 changes: 7 additions & 7 deletions docs/lsp-installation-zh.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Language server 安装
为了解析仓库中符号之间的依赖,abcoder parser 需要使用各语言的 language server。
运行 parser 之前请安装对应的 language server。
多数语言都能自动安装 language server。如果自动安装失败,可以按以下步骤手动安装。

语言和 language server 的对应关系如下

Expand All @@ -25,14 +26,13 @@

## Python
* 安装 Python 3.9+
* 从 git submodule 安装 pylsp
* 安装 pylsp
```bash
$ git submodule init
$ git submodule update
$ cd pylsp
$ pip install -e . # 可以考虑在单独的 conda/venv 环境中执行
$ export PATH=$(realpath ./bin):$PATH # 放到 .rc 文件里,或每次运行 abcoder 前都设置一下
$ pylsp --version # 验证安装成功
$ git clone https://github.com/Hoblovski/python-lsp-server.git -b abc
$ cd python-lsp-server
$ pip install .
$ export PATH=$(realpath ./bin):$PATH
$ pylsp --version
```

## C
Expand Down
2 changes: 1 addition & 1 deletion docs/system_architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ ABCoder 主要通过命令行参数进行配置,没有独立的配置文件(
- **Go**: 运行 ABCoder 本身需要 Go 语言环境 (`go install ...`)。
- **Language Servers**: 为了解析不同语言的仓库,必须在环境中预先安装对应的语言服务器。这在 `docs/lsp-installation-zh.md` 中有详细说明:
- **Rust**: `rust-analyzer`
- **Python**: `pylsp` (通过 git submodule 安装)
- **Python**: `pylsp`
- **C/C++**: `clangd`
- **Git**: 用于克隆代码仓库。

Expand Down
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
18 changes: 13 additions & 5 deletions lang/python/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (

const MaxWaitDuration = 5 * time.Second
const lspName = "pylsp"
const lspUrl = "https://github.com/Hoblovski/python-lsp-server.git"
const lspBranch = "abc"
const lspPath = "pylsp"

func CheckPythonVersion() error {
// Check python3 command availability and get version.
Expand All @@ -56,6 +59,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 All @@ -64,15 +71,15 @@ func InstallLanguageServer() (string, error) {
log.Error("python version check failed: %v", err)
return "", err
}
// git submodule init
log.Error("Installing pylsp...")
if err := exec.Command("git", "submodule", "update", "--remote", "--init", "-f").Run(); err != nil {
// git clone
log.Error("Installing pylsp... Now running git clone -b %s %s %s", lspBranch, lspUrl, lspPath)
if err := exec.Command("git", "clone", "-b", lspBranch, lspUrl, lspPath).Run(); err != nil {
log.Error("git clone failed: %v", err)
return "", err
}
// python -m pip install -e projectRoot/pylsp
log.Error("Running `python3 -m pip install -e pylsp/` .\nThis might take some time, make sure the network connection is ok.")
if err := exec.Command("python3", "-m", "pip", "install", "--break-system-packages", "-e", "pylsp/").Run(); err != nil {
log.Error("Installing pylsp via pip. This might take some time, make sure the network connection is ok.")
if err := exec.Command("python3", "-m", "pip", "install", "--break-system-packages", "-e", lspPath).Run(); err != nil {
log.Error("python3 -m pip install failed: %v", err)
return "", err
}
Expand All @@ -85,6 +92,7 @@ func InstallLanguageServer() (string, error) {
}

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

Expand Down
1 change: 0 additions & 1 deletion pylsp
Submodule pylsp deleted from 0e1ed4
Loading