Skip to content

Commit 24b2188

Browse files
committed
feat: parses flask
1 parent a471a24 commit 24b2188

6 files changed

Lines changed: 27 additions & 24 deletions

File tree

lang/collect/collect.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,22 @@ func NewCollector(repo string, cli *LSPClient) *Collector {
108108
}
109109

110110
func (c *Collector) Collect(ctx context.Context) error {
111+
// Example code to configure the LSP client
112+
// if c.Language == uniast.Python {
113+
// conf := map[string]interface{}{
114+
// "settings": map[string]interface{}{
115+
// "pylsp": map[string]interface{}{
116+
// "plugins": map[string]interface{}{
117+
// "jedi_definition": map[string]interface{}{
118+
// "follow_builtin_definitions": false,
119+
// },
120+
// },
121+
// },
122+
// },
123+
// }
124+
// c.cli.Notify(ctx, "workspace/didChangeConfiguration", conf)
125+
// }
126+
111127
excludes := make([]string, len(c.Excludes))
112128
for i, e := range c.Excludes {
113129
if !filepath.IsAbs(e) {

lang/collect/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
320320
case lsp.SKStruct, lsp.SKTypeParameter, lsp.SKInterface, lsp.SKEnum, lsp.SKClass:
321321
obj.SubStruct = append(obj.SubStruct, uniast.NewDependency(*depid, c.fileLine(dep.Location)))
322322
default:
323-
log.Error("dep symbol %s not collected for \n", dep.Symbol, id)
323+
log.Error("dep symbol %s not collected for %v\n", dep.Symbol, id)
324324
}
325325
}
326326
}

lang/lsp/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (rwc rwc) Close() error {
225225

226226
// start a LSP process and return its io
227227
func startLSPSever(path string) (io.ReadWriteCloser, error) {
228-
// Launch rust-analyzer
228+
// Launch LSP server
229229
cmd := exec.Command(path)
230230

231231
stdin, err := cmd.StdinPipe()

lang/lsp/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ loop:
9393

9494
func (h *lspHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
9595
// This method will be called for both requests and notifications
96-
log.Info("handle method: %s\n", req.Method)
96+
log.Debug("handle method: %s\n", req.Method)
9797
if req.Params != nil {
98-
log.Info("param: %s\n", string(*req.Params))
98+
log.Debug("param: %s\n", string(*req.Params))
9999
}
100100
if req.Notif {
101101
// This is a notification

lang/python/lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/cloudwego/abcoder/lang/utils"
2222
)
2323

24-
const MaxWaitDuration = 5 * time.Second
24+
const MaxWaitDuration = 2 * time.Second
2525

2626
func GetDefaultLSP() (lang uniast.Language, name string) {
2727
// needs to use the custom pylsp (see commit message)

lang/python/spec.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,20 @@ func (c *PythonSpec) WorkSpace(root string) (map[string]string, error) {
4343
return nil, err
4444
}
4545

46-
num_projfiles := 0
47-
scanner := func(path string, info os.FileInfo, err error) error {
48-
if err != nil {
49-
return err
50-
}
51-
base := filepath.Base(path)
52-
if base == "pyproject.toml" {
53-
num_projfiles++
54-
if num_projfiles > 1 {
55-
panic("multiple pyproject.toml files found")
56-
}
57-
// it's hard to infer the name or package from pyproject.toml
58-
}
59-
return nil
60-
}
61-
if err := filepath.Walk(root, scanner); err != nil {
62-
return nil, err
63-
}
46+
// TODO: maybe infer from pyproject.toml?
47+
// should ignore {tests,examples}/**/pyproject.toml
6448

6549
// XXX ad-hoc way
6650
if strings.Contains(c.repo, "astropy") {
6751
panic("TODO")
52+
} else if strings.Contains(c.repo, "flask") {
53+
c.topModulePath = absPath + "/src"
54+
c.topModuleName = "flask"
6855
} else {
6956
c.topModulePath = absPath
7057
c.topModuleName = "current"
71-
rets[c.topModuleName] = c.topModulePath
7258
}
59+
rets[c.topModuleName] = c.topModulePath
7360
return rets, nil
7461
}
7562

0 commit comments

Comments
 (0)