From da5fa4ea4865f01c5e975af94dc57f3a4d089d9e Mon Sep 17 00:00:00 2001 From: Hoblovski Date: Thu, 25 Sep 2025 18:04:16 +0800 Subject: [PATCH 1/3] fix: install lsp in getDefaultLsp instead of Parse --- lang/parse.go | 33 +-------------------------------- lang/python/lib.go | 5 +++++ 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/lang/parse.go b/lang/parse.go index ba7acd51..2c3ac204 100644 --- a/lang/parse.go +++ b/lang/parse.go @@ -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) { diff --git a/lang/python/lib.go b/lang/python/lib.go index 9b93288b..52a06362 100644 --- a/lang/python/lib.go +++ b/lang/python/lib.go @@ -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") @@ -85,6 +89,7 @@ func InstallLanguageServer() (string, error) { } func GetDefaultLSP() (lang uniast.Language, name string) { + InstallLanguageServer() return uniast.Python, lspName } From 1222aaa7ab88a1b4c76f5d5312621c2176ada599 Mon Sep 17 00:00:00 2001 From: Hoblovski Date: Fri, 26 Sep 2025 12:01:25 +0800 Subject: [PATCH 2/3] docs: no more submodules --- docs/lsp-installation-en.md | 16 ++++++++-------- docs/lsp-installation-zh.md | 14 +++++++------- docs/system_architecture.md | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/lsp-installation-en.md b/docs/lsp-installation-en.md index 4046e464..3c6cb59e 100644 --- a/docs/lsp-installation-en.md +++ b/docs/lsp-installation-en.md @@ -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: @@ -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 diff --git a/docs/lsp-installation-zh.md b/docs/lsp-installation-zh.md index f3503fbd..020fe759 100644 --- a/docs/lsp-installation-zh.md +++ b/docs/lsp-installation-zh.md @@ -1,6 +1,7 @@ # Language server 安装 为了解析仓库中符号之间的依赖,abcoder parser 需要使用各语言的 language server。 运行 parser 之前请安装对应的 language server。 +多数语言都能自动安装 language server。如果自动安装失败,可以按以下步骤手动安装。 语言和 language server 的对应关系如下 @@ -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 diff --git a/docs/system_architecture.md b/docs/system_architecture.md index 5592c741..34340924 100644 --- a/docs/system_architecture.md +++ b/docs/system_architecture.md @@ -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**: 用于克隆代码仓库。 From 1b21f3bc2569f15693cab9ddd4d7bb81e9f56450 Mon Sep 17 00:00:00 2001 From: Hoblovski Date: Fri, 26 Sep 2025 12:08:02 +0800 Subject: [PATCH 3/3] fix: use git clone instead of submodule --- .gitmodules | 4 ---- lang/python/lib.go | 13 ++++++++----- pylsp | 1 - 3 files changed, 8 insertions(+), 10 deletions(-) delete mode 160000 pylsp diff --git a/.gitmodules b/.gitmodules index 45907e2c..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "pylsp"] - path = pylsp - url = https://github.com/Hoblovski/python-lsp-server.git - branch = abc diff --git a/lang/python/lib.go b/lang/python/lib.go index 52a06362..3211b1ae 100644 --- a/lang/python/lib.go +++ b/lang/python/lib.go @@ -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. @@ -68,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 } diff --git a/pylsp b/pylsp deleted file mode 160000 index 0e1ed4c2..00000000 --- a/pylsp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0e1ed4c2785b5ff98148ded317b062ec31b932fc