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
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,36 @@ jobs:
if-no-files-found: error
retention-days: 7

jsp-grammar-host:
# Runs on drafts too: it needs neither the Rust Core nor a package, only the
# host's pure-Go editor packages.
name: JSP grammar on the host tokenizer
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Read pinned host revision
id: host
run: echo "revision=$(node -p 'JSON.parse(require("fs").readFileSync("grammar-host.json")).revision')" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
repository: 1lck/Lithe-IDEA
ref: ${{ steps.host.outputs.revision }}
path: .artifacts/grammar-host
sparse-checkout: desktop
persist-credentials: false
- uses: actions/setup-go@v5
with:
go-version-file: .artifacts/grammar-host/desktop/go.mod
cache: false
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Tokenize JSP with the host's TextMate engine
run: node scripts/grammar/host-jsp.mjs .artifacts/grammar-host

native-settings-visual:
name: Native compiler settings screenshots
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,15 @@ node scripts/package/build-windows.mjs /path/to/lithe-java-backend.exe
## Linux ARM64 / x64

Linux 构建、资源归属与原生验证入口见 [Linux 构建与验证](docs/linux-packaging.md)。

## JSP / EL 语法着色

Java Support 把 `.jsp`、`.jspf`、`.tag`、`.tagf` 声明为 JSP 文档,并随插件包提供 TextMate 语法 `grammars/jsp.tmLanguage.json`。语法建立在宿主自带的 HTML 语法(`text.html.basic`)之上,HTML 以及其中 `<script>`、`<style>` 的 JavaScript/CSS 着色与原来把 `.jsp` 当 HTML 打开时一致;JSP 注释、指令、声明、表达式、脚本片段和 `${...}` / `#{...}` EL 以注入方式出现在 HTML 的任何位置(属性值、脚本、样式内也能识别),`<c:forEach>`、`<jsp:include>` 这类带前缀的标签按标签库标签着色,不再被 HTML 标成无法识别。

脚本片段内部只使用 Java 的词法规则(字符串、数字、关键字、修饰符、类型、常量),注释在 `%>` 处结束。原因是 JSP 常把一个 Java 代码块拆在多个脚本片段中(`<% if (ok) { %> … <% } %>`),套用完整的 Java 语法会把中间的 HTML 当成 Java。

语法注入需要桌面端 0.8.4 及以上;更早的宿主只识别 HTML 正文层级的 JSP 结构。

验证:`scripts/package/jsp-grammar.test.mjs` 做静态检查;`node scripts/grammar/host-jsp.mjs <宿主检出>` 用宿主自己的 TextMate 分词器和内置 HTML/CSS/JS/Java 语法逐个检查着色结果,宿主版本固定在 `grammar-host.json`,CI 的 “JSP grammar on the host tokenizer” 任务运行它(Draft PR 也运行)。

**范围边界:** 这只是语法着色及注释/括号配置;未实现 JSP/EL 的语义补全、跨文件跳转、诊断、JSP 断点和热部署。JDT LS 仍只服务 `.java` 文件。
7 changes: 7 additions & 0 deletions docs/feature-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@
| --- | --- | --- | --- | --- |
| Java 项目结构中的 Web Facet 独立原生来源、按 jst.java 限定可选版本、版本读写与修改前 revision 校验;无法安全编辑的 Facet 文件只跳过该来源并上报一次降级 | implemented / verified | implemented / pending | implemented / pending | `backend/src/web_facet.rs` 单元测试;`scripts/compiler/test-module-structure.mjs` 用真实 JDT LS 1.61 覆盖读取、不合规文件、版本限制、保存,以及所有来源和字段 ID 符合 Core 规则;`scripts/compiler/visual.mjs` 在固定宿主上经 Core `ReadSourceSettings` 渲染 Web Facet 页,截图见 `docs/assets/module-structure/web-facet-*.png`。2026-11-18 macOS arm64 本机通过;Linux 由 CI 的同一脚本覆盖;Windows 与原生窗口点按待实机验收 |
| 编辑 WTP .component、IDEA .iml Web Facet、WTP 服务器配置 | not-implemented | not-implemented | not-implemented | 单文件安全修改,不覆盖其他 IDE 模型 |

## JSP / EL 语法着色

| 能力 | macOS | Windows | Linux | 证据 |
| --- | --- | --- | --- | --- |
| JSP/JSPF/Tag/Tagf 识别;在宿主 HTML 语法之上注入 JSP 指令、脚本片段、注释、EL 和标签库标签着色;注释与括号设置 | implemented / verified | implemented / verified | implemented / verified | `grammars/jsp.tmLanguage.json`;`scripts/grammar/host-jsp.mjs` 用宿主 TextMate 分词器(宿主 commit 见 `grammar-host.json`)逐项检查 24 处着色,2026-11-18 macOS arm64 本机与 CI Linux 通过。分词器与平台无关;原生编辑器窗口内的实际显示待实机验收 |
| JSP/EL 语义补全、诊断、页面断点 | not-implemented | not-implemented | not-implemented | JDT LS 仅为 Java 服务,未来需 JSP 专属语言服务 |
149 changes: 149 additions & 0 deletions e2e/host/desktop/internal/editor/syntax/plugin_jsp_grammar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//go:build lithejsp

// This file belongs to the Java Support plugin repository. scripts/grammar/host-jsp.mjs
// adds it to a Lithe host checkout through a Go overlay, so the plugin's JSP grammar is
// checked by the host's own TextMate tokenizer, with the host's bundled HTML, CSS,
// JavaScript and Java grammars it includes. Nothing of the plugin is copied into the host.
package syntax

import (
"os"
"strings"
"testing"

"github.com/1lck/Lithe-IDEA/desktop/internal/editor/textmate"
)

// scopeCase names a text on a line and what the scopes of the token it starts in must and
// must not contain.
type scopeCase struct {
line, text string
nth int
want, not []string
}

func TestPluginJSPGrammarOnHostTokenizer(t *testing.T) {
path := os.Getenv("LITHE_JSP_GRAMMAR")
if path == "" {
t.Fatal("LITHE_JSP_GRAMMAR is not set; run scripts/grammar/host-jsp.mjs")
}
grammar, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
r := NewRegistry()
jsp := PluginLanguage{ID: "jsp", Extensions: []string{"jsp", "jspf", "tag", "tagf"}, Grammar: grammar}
if failed, _ := r.SetPluginLanguages([]PluginLanguage{jsp}); len(failed) != 0 {
t.Fatalf("the host refused the JSP grammar: %v", failed)
}
if language, ok := r.ForPath("WEB-INF/views/index.jsp"); !ok || language.ID != "jsp" {
t.Fatalf("index.jsp opens as %+v, %v", language, ok)
}
s := r.Syntax("jsp")
if s == nil {
t.Fatal("no syntax for the JSP language")
}
source := []string{
`<%@ page contentType="text/html;charset=UTF-8" %>`,
`<% int n = 0; // counted %><p>${user.name}</p>`,
`<a href="<%= url %>" title="${title}">x</a>`,
`<c:forEach items="${items}" var="item">`,
`<script>var label = '${js}'; var more = a > b;</script>`,
`<style>.a { color: red }</style>`,
`<%-- ${hidden} <% ignored %> --%>`,
`<p>\${literal} #{bean.value}</p>`,
`<% if (ok) { %>`,
`<b>yes</b>`,
`<% } %>`,
`<% /* left open %>`,
`<i>after</i>`,
`<jsp:include page="/footer.jsp"/>`,
}
cases := []scopeCase{
{line: source[0], text: "page", want: []string{"meta.directive.jsp", "keyword.control.directive.jsp"}},
{line: source[0], text: "contentType", want: []string{"entity.other.attribute-name.jsp"}},
{line: source[1], text: "int", want: []string{"source.java.embedded.jsp", "storage.type.primitive.java"}},
{line: source[1], text: "// counted", want: []string{"comment.line.double-slash.java"}},
{line: source[1], text: "%>", want: []string{"punctuation.section.embedded.end.jsp"}, not: []string{"comment"}},
{line: source[1], text: "p>", want: []string{"entity.name.tag"}, not: []string{"source.java"}},
{line: source[1], text: "name", want: []string{"meta.expression.el.jsp", "variable.other.el.jsp"}},
{line: source[2], text: "url", want: []string{"string.quoted", "meta.embedded.block.jsp"}},
{line: source[2], text: "title}", want: []string{"string.quoted", "meta.expression.el.jsp"}},
{line: source[3], text: "c", want: []string{"entity.name.tag.namespace.jsp"}, not: []string{"invalid"}},
{line: source[3], text: "forEach", want: []string{"entity.name.tag.jsp"}, not: []string{"invalid"}},
{line: source[3], text: "items}", want: []string{"meta.expression.el.jsp"}},
{line: source[4], text: "var", want: []string{"source.js"}},
{line: source[4], text: "js}", want: []string{"source.js", "meta.expression.el.jsp"}},
{line: source[5], text: "color", want: []string{"source.css", "support.type.property-name"}},
{line: source[6], text: "hidden", want: []string{"comment.block.jsp"}, not: []string{"meta.expression.el.jsp"}},
{line: source[6], text: "ignored", want: []string{"comment.block.jsp"}, not: []string{"meta.embedded"}},
{line: source[7], text: "literal", not: []string{"meta.expression.el.jsp"}},
{line: source[7], text: "bean", want: []string{"meta.expression.el.jsp"}},
{line: source[9], text: "b>", want: []string{"entity.name.tag"}, not: []string{"source.java"}},
{line: source[10], text: "}", want: []string{"source.java.embedded.jsp"}},
{line: source[12], text: "i>", want: []string{"entity.name.tag"}, not: []string{"comment", "source.java"}},
{line: source[13], text: "jsp", want: []string{"entity.name.tag.namespace.jsp"}, not: []string{"invalid"}},
{line: source[13], text: "include", want: []string{"entity.name.tag.jsp"}},
}
tokens := tokenizeLines(t, s.grammar, source)
for _, c := range cases {
index := -1
for i, line := range source {
if line == c.line {
index = i
break
}
}
offset := strings.Index(c.line, c.text)
if index < 0 || offset < 0 {
t.Fatalf("case %q not found in %q", c.text, c.line)
}
scopes := scopesAt(tokens[index], offset)
for _, want := range c.want {
if !strings.Contains(scopes, want) {
t.Errorf("%q in %q: scopes %q lack %q", c.text, c.line, scopes, want)
}
}
for _, not := range c.not {
if strings.Contains(scopes, not) {
t.Errorf("%q in %q: scopes %q must not contain %q", c.text, c.line, scopes, not)
}
}
}
for i, line := range tokens {
for _, token := range line {
if scopes := token.Scopes.String(); strings.Contains(scopes, "invalid") {
t.Errorf("line %q: a token is marked invalid: %s", source[i], scopes)
}
}
}
}

func tokenizeLines(t *testing.T, grammar *textmate.Grammar, lines []string) [][]textmate.Token {
t.Helper()
tokenizer := grammar.NewTokenizer()
var state *textmate.StateStack
out := make([][]textmate.Token, len(lines))
for i, line := range lines {
var tokens []textmate.Token
var stopped bool
tokens, state, stopped = tokenizer.TokenizeLine(nil, []byte(line), state, 0)
if stopped {
t.Fatalf("tokenizing %q stopped", line)
}
out[i] = append([]textmate.Token(nil), tokens...)
}
return out
}

// scopesAt returns the scopes of the token that the ASCII offset starts in.
func scopesAt(tokens []textmate.Token, offset int) string {
scopes := ""
for _, token := range tokens {
if token.Start > offset {
break
}
scopes = token.Scopes.String()
}
return scopes
}
5 changes: 5 additions & 0 deletions grammar-host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"repository": "https://github.com/1lck/Lithe-IDEA",
"revision": "08ccf3ab6ae0f30b41200ec93c1d0aeefdcb7a5c",
"note": "Host whose TextMate tokenizer and bundled HTML, CSS, JavaScript and Java grammars check grammars/jsp.tmLanguage.json (scripts/grammar/host-jsp.mjs). Grammar injections need desktop 0.8.4 or later; on older hosts the root-level JSP rules still apply."
}
Loading
Loading