Skip to content

Commit 2fe1f71

Browse files
committed
Custom pylsp is based on [python-lsp-server](https://github.com/python-lsp/python-lsp-server), and plus the following pull requests:
1. semanticTokens/full: python-lsp/python-lsp-server#645 2. typeDefinition: python-lsp/python-lsp-server#533 Maybe also 3. implementation: python-lsp/python-lsp-server#644
1 parent e0feb07 commit 2fe1f71

File tree

5 files changed

+143
-0
lines changed

5 files changed

+143
-0
lines changed

lang/collect/collect.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"unicode"
2626

2727
"github.com/cloudwego/abcoder/lang/cxx"
28+
"github.com/cloudwego/abcoder/lang/python"
2829
"github.com/cloudwego/abcoder/lang/log"
2930
. "github.com/cloudwego/abcoder/lang/lsp"
3031
"github.com/cloudwego/abcoder/lang/rust"
@@ -88,6 +89,8 @@ func switchSpec(l uniast.Language) LanguageSpec {
8889
return &rust.RustSpec{}
8990
case uniast.Cxx:
9091
return &cxx.CxxSpec{}
92+
case uniast.Python:
93+
return &python.PythonSpec{}
9194
default:
9295
panic(fmt.Sprintf("unsupported language %s", l))
9396
}

lang/parse.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/cloudwego/abcoder/lang/golang/parser"
3131
"github.com/cloudwego/abcoder/lang/log"
3232
"github.com/cloudwego/abcoder/lang/lsp"
33+
"github.com/cloudwego/abcoder/lang/python"
3334
"github.com/cloudwego/abcoder/lang/rust"
3435
"github.com/cloudwego/abcoder/lang/uniast"
3536
)
@@ -106,6 +107,8 @@ func checkRepoPath(repoPath string, language uniast.Language) (openfile string,
106107
openfile, wait = rust.CheckRepo(repoPath)
107108
case uniast.Cxx:
108109
openfile, wait = cxx.CheckRepo(repoPath)
110+
case uniast.Python:
111+
openfile, wait = python.CheckRepo(repoPath)
109112
default:
110113
openfile = ""
111114
wait = 0
@@ -121,6 +124,8 @@ func checkLSP(language uniast.Language, lspPath string) (l uniast.Language, s st
121124
l, s = rust.GetDefaultLSP()
122125
case uniast.Cxx:
123126
l, s = cxx.GetDefaultLSP()
127+
case uniast.Python:
128+
l, s = python.GetDefaultLSP()
124129
case uniast.Golang:
125130
l = uniast.Golang
126131
s = ""

lang/python/lib.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2025 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package python
16+
17+
import (
18+
"time"
19+
20+
"github.com/cloudwego/abcoder/lang/uniast"
21+
"github.com/cloudwego/abcoder/lang/utils"
22+
)
23+
24+
const MaxWaitDuration = 5 * time.Minute
25+
26+
func GetDefaultLSP() (lang uniast.Language, name string) {
27+
// needs to use the pylsp from https://github.com/python-lsp/python-lsp-server/pull/533
28+
return uniast.Python, "pylsp"
29+
}
30+
31+
func CheckRepo(repo string) (string, time.Duration) {
32+
openfile := ""
33+
// TODO: check if the project compiles.
34+
35+
// NOTICE: wait for Rust projects based on code files
36+
_, size := utils.CountFiles(repo, ".py", "SKIPDIR")
37+
wait := 2*time.Second + time.Second*time.Duration(size/1024)
38+
if wait > MaxWaitDuration {
39+
wait = MaxWaitDuration
40+
}
41+
return openfile, wait
42+
}

lang/python/spec.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2025 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package python
16+
17+
import (
18+
lsp "github.com/cloudwego/abcoder/lang/lsp"
19+
"github.com/cloudwego/abcoder/lang/uniast"
20+
)
21+
22+
type PythonSpec struct {
23+
repo string
24+
}
25+
26+
func NewPythonSpec() *PythonSpec {
27+
return &PythonSpec{}
28+
}
29+
30+
func (c *PythonSpec) WorkSpace(root string) (map[string]string, error) {
31+
panic("TODO")
32+
}
33+
34+
func (c *PythonSpec) NameSpace(path string) (string, string, error) {
35+
panic("TODO")
36+
}
37+
38+
func (c *PythonSpec) ShouldSkip(path string) bool {
39+
panic("TODO")
40+
}
41+
42+
func (c *PythonSpec) DeclareTokenOfSymbol(sym lsp.DocumentSymbol) int {
43+
panic("TODO")
44+
}
45+
46+
func (c *PythonSpec) IsEntityToken(tok lsp.Token) bool {
47+
panic("TODO")
48+
}
49+
50+
func (c *PythonSpec) IsStdToken(tok lsp.Token) bool {
51+
panic("TODO")
52+
}
53+
54+
func (c *PythonSpec) TokenKind(tok lsp.Token) lsp.SymbolKind {
55+
panic("TODO")
56+
}
57+
58+
func (c *PythonSpec) IsMainFunction(sym lsp.DocumentSymbol) bool {
59+
panic("TODO")
60+
}
61+
62+
func (c *PythonSpec) IsEntitySymbol(sym lsp.DocumentSymbol) bool {
63+
panic("TODO")
64+
}
65+
66+
func (c *PythonSpec) IsPublicSymbol(sym lsp.DocumentSymbol) bool {
67+
panic("TODO")
68+
}
69+
70+
func (c *PythonSpec) HasImplSymbol() bool {
71+
panic("TODO")
72+
}
73+
74+
func (c *PythonSpec) ImplSymbol(sym lsp.DocumentSymbol) (int, int, int) {
75+
panic("TODO")
76+
}
77+
78+
func (c *PythonSpec) FunctionSymbol(sym lsp.DocumentSymbol) (int, []int, []int, []int) {
79+
panic("TODO")
80+
}
81+
82+
func (c *PythonSpec) GetUnloadedSymbol(from lsp.Token, define lsp.Location) (string, error) {
83+
panic("TODO")
84+
}
85+
86+
func (c *PythonSpec) FileImports(content []byte) ([]uniast.Import, error) {
87+
panic("TODO")
88+
}

lang/uniast/ast.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
Golang Language = "go"
3131
Rust Language = "rust"
3232
Cxx Language = "cxx"
33+
Python Language = "python"
3334
Unknown Language = ""
3435
)
3536

@@ -41,6 +42,8 @@ func (l Language) String() string {
4142
return "go"
4243
case Cxx:
4344
return "cxx"
45+
case Python:
46+
return "python"
4447
default:
4548
return string(l)
4649
}
@@ -59,6 +62,8 @@ func NewLanguage(lang string) (l Language) {
5962
return Rust
6063
case "cxx":
6164
return Cxx
65+
case "python":
66+
return Python
6267
default:
6368
return Unknown
6469
}

0 commit comments

Comments
 (0)