Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,39 @@ name: CI

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
branches: [main]

permissions:
contents: read

concurrency:
group: ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
platforms:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
commands: ${{ steps.matrix.outputs.commands }}
steps:
- id: matrix
env:
FULL: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
run: |
if [[ "$FULL" == true ]]; then
echo 'commands={"include":[{"os":"ubuntu-latest","platform":"linux-x64"},{"os":"macos-latest","platform":"darwin-arm64"},{"os":"windows-latest","platform":"windows-x64"},{"os":"windows-11-arm","platform":"windows-arm64"}]}' >> "$GITHUB_OUTPUT"
else
echo 'commands={"include":[{"os":"ubuntu-latest","platform":"linux-x64"}]}' >> "$GITHUB_OUTPUT"
fi

package:
uses: ./.github/workflows/package.yml

verify-store:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
needs: package
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down Expand Up @@ -50,21 +72,12 @@ jobs:
"

commands:
needs: package
needs: [package, platforms]
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: linux-x64
- os: macos-latest
platform: darwin-arm64
- os: windows-latest
platform: windows-x64
- os: windows-11-arm
platform: windows-arm64
matrix: ${{ fromJSON(needs.platforms.outputs.commands) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down Expand Up @@ -93,6 +106,7 @@ jobs:
node scripts/test.mjs

host-e2e:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
needs: package
runs-on: macos-latest
timeout-minutes: 45
Expand Down
42 changes: 20 additions & 22 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,29 @@ permissions:
contents: read

jobs:
platforms:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
package: ${{ steps.matrix.outputs.package }}
steps:
- id: matrix
env:
FULL: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
run: |
if [[ "$FULL" == true ]]; then
echo 'package={"include":[{"os":"macos-latest","platform":"darwin-arm64","target":"aarch64-apple-darwin"},{"os":"macos-15-intel","platform":"darwin-x64","target":"x86_64-apple-darwin"},{"os":"ubuntu-latest","platform":"linux-x64","target":"x86_64-unknown-linux-musl"},{"os":"ubuntu-24.04-arm","platform":"linux-arm64","target":"aarch64-unknown-linux-musl"},{"os":"windows-latest","platform":"windows-x64","target":"x86_64-pc-windows-msvc"},{"os":"windows-11-arm","platform":"windows-arm64","target":"aarch64-pc-windows-msvc"}]}' >> "$GITHUB_OUTPUT"
else
echo 'package={"include":[{"os":"ubuntu-latest","platform":"linux-x64","target":"x86_64-unknown-linux-musl"}]}' >> "$GITHUB_OUTPUT"
fi

package:
needs: platforms
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
platform: darwin-arm64
target: aarch64-apple-darwin
- os: macos-15-intel
platform: darwin-x64
target: x86_64-apple-darwin
- os: ubuntu-latest
platform: linux-x64
target: x86_64-unknown-linux-musl
- os: ubuntu-24.04-arm
platform: linux-arm64
target: aarch64-unknown-linux-musl
- os: windows-latest
platform: windows-x64
target: x86_64-pc-windows-msvc
- os: windows-11-arm
platform: windows-arm64
target: aarch64-pc-windows-msvc
matrix: ${{ fromJSON(needs.platforms.outputs.package) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -46,8 +44,8 @@ jobs:
env:
TARGET: ${{ matrix.target }}
run: |
rustup toolchain install 1.87 --profile minimal --target "$TARGET"
rustup override set 1.87
rustup toolchain install 1.100.0 --profile minimal --target "$TARGET"
rustup override set 1.100.0
- name: Test backend
run: cargo test --locked --manifest-path backend/Cargo.toml
- name: Assemble plugin archive
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ Pyrefly 和 debugpy 随插件包分发,Python 解释器、pytest、uv、conda
> [#2316](https://github.com/1lck/Lithe-IDEA/issues/2316) 的版本),旧版本不能安装,请继续用 1.1.0(支持 0.8.9 或更新版本)。
> 各版本的变化见 [docs/releases](docs/releases)。

## 当前文件与单个函数/测试运行

普通 `.py` / `.pyw` 文件直接执行 `python ./文件名`,不要求 `__main__` guard;pytest 函数和类方法通过精确 node ID 单独运行。

点击前重新读取文档、校验路径和版本,保存成功后才启动;rerun 会重新验证当前声明。工作区相对路径统一使用 `/`,拒绝绝对路径、盘符、反斜杠、`.`、`..` 与控制字符。gutter 使用宿主选择的 Python;旧的 Python executable 绝对路径覆盖设置只作用于原有构建流程,不覆盖新 gutter 入口。

2026-11-30,Windows 11 x64 的真实运行、精确单测试、陈旧版本、保存失败、rerun 和不安全路径回归通过。截图由固定 Viva 无头宿主生成,覆盖明暗主题、中英文及 before/after/hover,见 [截图目录](docs/assets/current-file-runs/)。macOS 原生窗口仍待 CI/实机复验。后端构建工具链固定 Rust 1.100.0。

## 功能

| 功能 | 说明 |
| --- | --- |
| 代码智能 | 补全、自动导入、跳转定义、悬停、类型诊断,由随包的 [Pyrefly](https://github.com/facebook/pyrefly) 1.4.1 提供 |
| 识别文件 | `.py`、`.pyi`、`.pyw`;首行是 Python shebang 的无后缀脚本也按 Python 打开 |
| 运行 | 工具栏「当前文件」运行带 `if __name__ == "__main__"` 的脚本和包里的 `__main__.py`;构建窗口列出 `[project.scripts]`、Django `manage.py`、FastAPI、Flask 等入口;「运行/调试配置 → + → Python」可以手动配置脚本或模块 |
| 运行 | 工具栏「当前文件」运行普通脚本和包里的 `__main__.py`(不要求 main guard);构建窗口列出 `[project.scripts]`、Django `manage.py`、FastAPI、Flask 等入口;「运行/调试配置 → + → Python」可以手动配置脚本或模块 |
| 测试 | `pytest --collect-only` 收集函数、类方法、参数化用例和 doctest,组成测试树;可以运行整个套件或单个用例 |
| 依赖 | 构建窗口的「依赖」列出所选解释器里已安装的包、版本和依赖关系,不需要 pip |
| 任务 | `pip install -r requirements.txt`、`mypy`;有 `uv.lock` 时 `uv sync`、`uv lock`;有 `environment.yml` 或 `environment.yaml` 时 `conda env update`(两者都有时使用 `environment.yml`);有 `ruff.toml` 或 `.ruff.toml` 时 `ruff check`、`ruff format`,优先使用项目虚拟环境里的 Ruff |
Expand All @@ -30,6 +38,7 @@ Pyrefly 和 debugpy 随插件包分发,Python 解释器、pytest、uv、conda
| 工具链 | 找到项目的 `.venv`,Poetry、Pipenv、Hatch、virtualenvwrapper 建在项目外的环境,以及电脑上 uv、pyenv、conda、Homebrew、python.org 装的 Python;按 `.python-version` 和 `requires-python` 选版本,见下文“Python 解释器” |
| 设置预览 | 语言页和构建工具页画出设置的效果和解释器的查找顺序,见下文“设置预览” |


## 设置

**插件设置**(「语言与框架 › Python」,也在 设置 → 插件 → Python Support →「设置」),除覆盖路径外都立即生效:
Expand Down Expand Up @@ -131,7 +140,7 @@ Pyrefly 和 debugpy 的启动结果由 Lithe 记在插件的日志通道。debug

## 本地打包

需要 Node.js 22+、Rust 1.87+ 和对应的 target(`rustup target add`)。上游的 Pyrefly、debugpy、Tomli、Packaging 按 `vendor-lock.json`
需要 Node.js 22+、Rust 1.100.0+ 和对应的 target(`rustup target add`)。上游的 Pyrefly、debugpy、Tomli、Packaging 按 `vendor-lock.json`
的 SHA-256 下载到 `.cache/`,可以复制到其他工作树复用。

```bash
Expand Down
106 changes: 106 additions & 0 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "lithe-python-backend"
version = "0.1.0"
edition = "2021"
rust-version = "1.87"
rust-version = "1.100"
license = "Apache-2.0"
publish = false

Expand All @@ -14,6 +14,8 @@ pep440_rs = "0.7"
serde_json = "1"
sha2 = "0.10"
toml = "0.9"
tree-sitter = "0.25.10"
tree-sitter-python = "0.25.0"

[profile.release]
strip = "symbols"
7 changes: 7 additions & 0 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ mod discovery;
mod inspect;
mod pyrefly;
mod requirements;
mod run;
mod run_targets;
mod type_errors;
mod view;

use lithe_plugin_sdk::Backend;

fn main() {
let mut backend = Backend::new("python-support-backend");
let runs = run::Runs::register(&mut backend).expect("run action functions register");
backend.on_contexts_changed(move |_| {
runs.sync_reporting();
Ok(())
});
let launch = pyrefly::LaunchResolver::default();
backend
.function("pyrefly.resolveLaunch", move |params, context| {
Expand Down
Loading
Loading