Skip to content
Closed
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
58 changes: 54 additions & 4 deletions vscode-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# EasyCon for VS Code

EasyCon 伊机控 VS Code 插件,为 `.ecs` 脚本文件提供语法高亮、注释切换和脚本执行等功能
EasyCon 伊机控 VS Code 插件,为 `.ecs` 脚本文件提供语法高亮、代码智能和脚本执行等功能

## 功能特性

Expand All @@ -22,11 +22,17 @@ EasyCon 伊机控 VS Code 插件,为 `.ecs` 脚本文件提供语法高亮、

### 代码导航

- **跳转到定义** — 鼠标悬停到变量/常量/方法名上并按住CTRL 键,出现下划线点击可跳转到定义位置
以下功能由 Python 语言服务器(LSP)提供:

- **跳转到定义** — 鼠标悬停到变量、常量、函数名上并按住 CTRL 键,点击可跳转到定义位置
- **悬停提示** — 将鼠标悬停到关键字、内置函数、变量、按键上可查看详细说明
- **自动补全** — 输入 `$`、`_`、`@`、`(` 时自动提示关键字、内置函数、变量名和常量名
- **文档符号** — 在 VS Code 的大纲视图中查看脚本的变量、常量和函数列表
- **语义高亮** — 基于 AST 的精确语义着色,区分按键、方向、变量等不同语义

### 代码格式化

保存正确格式的脚本时会自动格式化代码
保存 `.ecs` 文件时会自动格式化代码。格式化功能由 Python 语言服务器提供,无需安装 `ezcon` 命令行工具即可使用

### 执行脚本

Expand All @@ -46,6 +52,39 @@ videotype=ANY #采集卡打开类型

状态栏会显示当前安装的 EasyCon 版本号。

## 架构说明

EasyCon for VS Code 采用混合架构,部分功能已迁移至新的 Python 语言服务器(LSP)。

### 已迁移至 Python LSP 的功能

这些功能由 `ecs-language-server`(Python / pygls)提供,随插件自动启动,不需要安装 `ezcon` 工具:

| 功能 | 说明 |
|---|---|
| **代码诊断** | 实时显示脚本中的语法错误和语义错误(如未闭合的语句块、无效的按键名等) |
| **跳转到定义** | 变量、常量、函数的定义跳转 |
| **悬停提示** | 关键字、内置函数、变量、按键的详细说明 |
| **自动补全** | 关键字、内置函数、变量名、常量名的智能补全 |
| **代码格式化** | 脚本的自动格式化(缩进、对齐等) |
| **文档符号** | VS Code 大纲视图中的符号列表 |
| **语义高亮** | 基于 AST 的精确语义着色(区分按键、方向键、修饰键等) |

### 保留在旧 C# 系统的功能

这些功能仍由 `ezcon`(.NET 命令行工具)提供:

| 功能 | 说明 |
|---|---|
| **脚本执行** | 通过 `ezcon run` 在 Nintendo Switch 硬件上执行脚本(按 F5 或点击运行按钮) |
| **配置管理** | 读取 `config.toml` 获取串口、摄像头等参数 |
| **版本显示** | 状态栏显示的 EasyCon 版本号 |

### 依赖关系

- **代码格式化、跳转定义、悬停提示、自动补全等编辑功能**:由 Python LSP 提供,不再依赖 `ezcon`
- **脚本执行**:仍然依赖 `ezcon run` 命令,需要安装 EasyCon CLI 工具

## 打包脚本

### 使用 build-vsix 脚本打包插件
Expand All @@ -70,4 +109,15 @@ videotype=ANY #采集卡打开类型

## 前置条件

使用脚本执行和格式化功能需要安装 EasyCon 命令行工具 `ezcon`,可通过设置环境变量 `EASYCON_ROOT` 指定其路径,或将 `ezcon` 添加到系统 PATH 中。
### 脚本执行

使用脚本执行功能需要安装 EasyCon 命令行工具 `ezcon`,可通过设置环境变量 `EASYCON_ROOT` 指定其路径,或将 `ezcon` 添加到系统 PATH 中。

### 语言服务器

代码格式化、跳转定义、悬停提示、自动补全等编辑功能由 Python 语言服务器提供。语言服务器随插件自动启动,支持以下三种运行方式(按优先级):

1. **自定义路径**:在 VS Code 设置中配置 `easycon.languageServer.path` 指定语言服务器可执行文件路径
2. **内置可执行文件**:使用插件 `bin/` 目录下的 `ecs-lsp`(Windows 下为 `ecs-lsp.exe`)
3. **Python 运行**:通过 `python -m easycon_script_lsp` 启动(需要 Python 3.10+)
4. **打包**:cd ecs-language-server && python -m PyInstaller ecs-lsp.spec
2 changes: 2 additions & 0 deletions vscode-plugin/ecs-language-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
dist
42 changes: 42 additions & 0 deletions vscode-plugin/ecs-language-server/ecs-lsp.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files

datas = []
datas += collect_data_files('easycon_grammar')


a = Analysis(
['lsp_entry.py'],
pathex=[],
binaries=[],
datas=datas,
hiddenimports=['easycon_grammar'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='ecs-lsp',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
5 changes: 5 additions & 0 deletions vscode-plugin/ecs-language-server/lsp_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""PyInstaller entry point for EasyCon Script Language Server."""
from easycon_script_lsp.server import main

if __name__ == "__main__":
main()
49 changes: 49 additions & 0 deletions vscode-plugin/ecs-language-server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "ecs-language-server"
version = "0.1.0"
description = "Language Server for EasyCon Script (.ecs) — parser, AST, and LSP server"
readme = "README.md"
requires-python = ">=3.10"
license = { text = "MIT" }
authors = [
{ name = "EasyCon Team" },
]
keywords = ["lsp", "language-server", "easycon", "ecs", "parser"]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"lark>=1.1.0",
"pygls>=2.1.0",
"lsprotocol>=2025.0.0",
]

[project.optional-dependencies]
dev = [
"pytest>=7.0",
]

[project.scripts]
ecs-lsp = "easycon_script_lsp.server:main"

[tool.setuptools.packages.find]
where = ["src"]

[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = ["src"]

[tool.setuptools.package-data]
easycon_grammar = ["grammar/*.lark"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""EasyCon Grammar - Parser and AST for EasyCon Script."""

from .parser import Parser, ParseError
from .compilation import Compilation, CompilationResult
from . import ast

__all__ = ["Parser", "ParseError", "Compilation", "CompilationResult", "ast"]
Loading
Loading