Skip to content

Commit a7ed01e

Browse files
authored
fix: env setup (#94)
* fix: install lsp in getDefaultLsp instead of Parse * docs: no more submodules * fix: use git clone instead of submodule
1 parent b65f2f0 commit a7ed01e

File tree

7 files changed

+30
-58
lines changed

7 files changed

+30
-58
lines changed

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
[submodule "pylsp"]
2-
path = pylsp
3-
url = https://github.com/Hoblovski/python-lsp-server.git
4-
branch = abc

docs/lsp-installation-en.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Language Server Installation
2-
32
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.
3+
ABCoder automatically installs the corresponding language server for most languages.
4+
Should the automatic installation fail, please install manually following the instructions below.
45

56
The mapping between languages and language servers is as follows:
67

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

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

3838
## C

docs/lsp-installation-zh.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Language server 安装
22
为了解析仓库中符号之间的依赖,abcoder parser 需要使用各语言的 language server。
33
运行 parser 之前请安装对应的 language server。
4+
多数语言都能自动安装 language server。如果自动安装失败,可以按以下步骤手动安装。
45

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

@@ -25,14 +26,13 @@
2526

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

3838
## C

docs/system_architecture.md

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

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: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import (
3030

3131
const MaxWaitDuration = 5 * time.Second
3232
const lspName = "pylsp"
33+
const lspUrl = "https://github.com/Hoblovski/python-lsp-server.git"
34+
const lspBranch = "abc"
35+
const lspPath = "pylsp"
3336

3437
func CheckPythonVersion() error {
3538
// Check python3 command availability and get version.
@@ -56,6 +59,10 @@ func CheckPythonVersion() error {
5659
}
5760

5861
func InstallLanguageServer() (string, error) {
62+
if out, err := exec.Command("pylsp", "--version").CombinedOutput(); err == nil {
63+
log.Info("pylsp already installed: %v", out)
64+
return lspName, nil
65+
}
5966
if _, err := os.Stat("go.mod"); os.IsNotExist(err) {
6067
log.Error("Auto installation requires working directory to be /path/to/abcoder/")
6168
return "", fmt.Errorf("bad cwd")
@@ -64,15 +71,15 @@ func InstallLanguageServer() (string, error) {
6471
log.Error("python version check failed: %v", err)
6572
return "", err
6673
}
67-
// git submodule init
68-
log.Error("Installing pylsp...")
69-
if err := exec.Command("git", "submodule", "update", "--remote", "--init", "-f").Run(); err != nil {
74+
// git clone
75+
log.Error("Installing pylsp... Now running git clone -b %s %s %s", lspBranch, lspUrl, lspPath)
76+
if err := exec.Command("git", "clone", "-b", lspBranch, lspUrl, lspPath).Run(); err != nil {
7077
log.Error("git clone failed: %v", err)
7178
return "", err
7279
}
7380
// python -m pip install -e projectRoot/pylsp
74-
log.Error("Running `python3 -m pip install -e pylsp/` .\nThis might take some time, make sure the network connection is ok.")
75-
if err := exec.Command("python3", "-m", "pip", "install", "--break-system-packages", "-e", "pylsp/").Run(); err != nil {
81+
log.Error("Installing pylsp via pip. This might take some time, make sure the network connection is ok.")
82+
if err := exec.Command("python3", "-m", "pip", "install", "--break-system-packages", "-e", lspPath).Run(); err != nil {
7683
log.Error("python3 -m pip install failed: %v", err)
7784
return "", err
7885
}
@@ -85,6 +92,7 @@ func InstallLanguageServer() (string, error) {
8592
}
8693

8794
func GetDefaultLSP() (lang uniast.Language, name string) {
95+
InstallLanguageServer()
8896
return uniast.Python, lspName
8997
}
9098

pylsp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)