Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`parse python` panics in `LSPClient.Locate` (`slice bounds out of range`) when following imports into `.venv`

未关闭
#186 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

  • #187 来自 @SAY-5 —— 已关闭,未合并
  • #196 来自 @SAY-5 —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
go, python
领域
devtools, tooling

调研方向

从 lang/lsp/lsp_methods.go:316 和 lang/collect/collect.go:2114 开始,然后在包含已填充 .venv 的 Python 3.12 项目中使用 abcoder parse python . -o /tmp/ast.json 重现。确认格式错误的范围不再导致 panic,并且受影响的 token 会被跳过或作为错误报告;比较使用 --exclude .venv 时的行为。

由索引模型根据 Issue 内容生成。

描述

parse python panics in LSPClient.Locate (slice bounds out of range [13:6]) when following imports into .venv

Repo: cloudwego/abcoder
Labels: bug, language/python, crash

Summary

When parsing a Python project whose source imports modules from a .venv/ containing Python 3.12 syntax that the bundled jedi 0.19.1 / parso 0.8.4 cannot fully parse, abcoder hard-crashes:

panic: runtime error: slice bounds out of range [13:6]

goroutine 1 [running]:
github.com/cloudwego/abcoder/lang/lsp.(*LSPClient).Locate(...)
    /tmp/abcoder-build/lang/lsp/lsp_methods.go:316 +0x430
github.com/cloudwego/abcoder/lang/collect.(*Collector).getSymbolByLocation(...)
    /tmp/abcoder-build/lang/collect/collect.go:2114 +0xe58
github.com/cloudwego/abcoder/lang/collect.(*Collector).getSymbolByTokenWithLimit(...)
github.com/cloudwego/abcoder/lang/collect.(*Collector).getDepsWithLimit(...)
github.com/cloudwego/abcoder/lang/collect.(*Collector).processSymbol(...)
    /tmp/abcoder-build/lang/collect/collect.go:2245 +0x328
github.com/cloudwego/abcoder/lang/collect.(*Collector).Collect(...)
    /tmp/abcoder-build/lang/collect/collect.go:206 +0x3c0

The panic is preceded by hundreds of warnings like:

[ERROR] collect.go:2306: get type symbol for token {file:///.../.venv/lib/python3.12/site-packages/redis/_parsers/socket.py:115:24-115:32 function [] readline} failed: definition of token ... not found

…and pylsp stderr noise from the pylsp_semantic_tokens hook:

WARNING - pylsp.config.config - Failed to load hook pylsp_semantic_tokens:
  'Newline' object has no attribute 'children'
  AttributeError in jedi/inference/syntax_tree.py:460 (infer_or_test)

jedi/parso returns a malformed range (start 13 > end 6), and lang/lsp/lsp_methods.go:316 slices a string with that range without bounds-checking → panic.

Reproduction

# Project: any Python 3.12 project with a populated .venv that contains
# files using PEP 701 f-strings or other 3.12-only syntax (e.g. attrs, redis).
abcoder parse python . -o /tmp/ast.json
# …jedi follows imports into .venv/...redis/_parsers/socket.py
# panic: runtime error: slice bounds out of range [13:6]

Expected

  • LSPClient.Locate should validate the Range it receives (Start <= End, both within document bounds) and return an error instead of panicking.
  • Higher up, Collector.getSymbolByLocation should swallow such errors as a "skip this token" rather than propagating a panic.
  • Optionally: parse python should default to excluding common virtualenv directories (.venv, venv, env) since they're never the parse target — they're only ever followed transitively, which is what triggers the bad ranges.

Workaround

Pass --exclude .venv (and any other vendored Python trees):

abcoder parse python . -o /tmp/ast.json --exclude .venv

Root cause notes (for triage)

The malformed range originates from jedi's syntax-tree inference on certain 3.12 constructs that parso 0.8.4 represents incorrectly (e.g. Newline nodes appearing where parso normally yields simple_stmt children). Bumping parso to ≥0.8.5 in the bundled pylsp fork's deps may eliminate the source — but the Go side should still bounds-check defensively.

Environment

  • abcoder v0.0.0-20260427034146-9d8ecc5873be+dirty
  • macOS 25.3.0 (arm64)
  • jedi 0.19.1, parso 0.8.4 (in miniconda Python 3.10)
  • Project: Python 3.12 with .venv containing attrs, redis, pydantic, etc.
主要语言
Go
星标
389
派生
58
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cloudwego/abcoder 的其他 Issue

查看 cloudwego/abcoder 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。