diff --git a/.agents/notes/implemented/bug-fix/2026-11-13-viva-plugin-run-debug-lifecycle.md b/.agents/notes/implemented/bug-fix/2026-11-13-viva-plugin-run-debug-lifecycle.md index de3fd31cc8..32ffbb5da7 100644 --- a/.agents/notes/implemented/bug-fix/2026-11-13-viva-plugin-run-debug-lifecycle.md +++ b/.agents/notes/implemented/bug-fix/2026-11-13-viva-plugin-run-debug-lifecycle.md @@ -44,8 +44,37 @@ SDK 的通知回调可能由并发工作线程执行,插件加锁的顺序不 Core 保留标准 LSP 进度的所有权;插件不申请转发宿主保留的方法。JDT 自己选择扩展通道,进度通知会跨现有插件通道转发,但普通进度报告只做常量级检查,不会逐条触发动作查询。延迟、恢复和预算耗尽分别进入 SDK 结构化诊断;这不修改宿主 API。Windows 长 classpath 另由插件复用 manifest JAR 规划,JAR 字节交给宿主临时文件接口,运行结束由宿主删除,不写安装目录。长 module-path 仍不属于已完成范围。 +## 无源码依赖的类内容与导航 + +语言服务器能返回目标地址,不代表编辑器能打开它。Java 插件之前只声明支持类内容, +没有注册 `jdt:` 内容提供者;Viva 也没有给只读虚拟文档设置语言标识,并把其地址当作 +磁盘路径重新编码。现在 Java 插件在返回有效服务器启动方案前注册已有内容扩展点, +调用 JDT 的 `java/classFileContents`;宿主只按通用语法注册表选择语言,保留原始 URI, +因此打开后的依赖类仍能继续发起导航。提供者按工作区代际持有订阅,不缓存源码或创建临时源码文件; +内容最多 1 MiB,请求有界,空响应按失败处理。卸载、工作区关闭和代际变化沿用既有清理。 + +原生界面还必须让读取属于发起时可见的文档和光标。用户换标签、移动光标、编辑、关闭文档或 +发起另一次导航后,取消未结束的内容读取;提交只读标签前再次验证归属。否则慢响应会在用户 +已经离开后抢走焦点。该临时光标快照只属于窗口,不作为插件协议或 Java 语义模型。 +准备文本和加载语法在后台完成,窗口线程只提交呈现状态;不为每次导航保留第二份全文。 + +真实残缺类文件另外触发了 JDT 1.61 的上游缺陷:外部类列出但未提供的内部类使 +`FernFlowerDecompiler.scanClassFiles` 抛出 Java Model 异常,整个外部类内容为空。 +JDT 的 `java.decompile` 使用相同内容管理器,换命令不能绕过问题;当时核对的上游 main +也保留相同行为。插件对锁定的开源集成增加“类文件不存在则跳过”的小补丁,反编译、源码附加、 +语义模型与行号映射仍由 JDT/FernFlower 完整子系统负责;不虚构缺失内部类的实现。 +正确做法是显示已有外部类并保留真实行号,不要生成占位类或修改反编译文本来凑落点。 + +补丁只在独立 Java 插件构建阶段执行:校验原始源码和 JAR、修改源码、固定编译器与完整 +class 集合,只修改新组装目录,单次操作的编译临时目录总会删除。修改过的 JDT core JAR +不能保留失效的 Eclipse 签名,因此移除签名及条目摘要、保留 OSGi 主清单,随包提供修改的 +EPL-2.0 源码、补丁身份和生成物哈希。它不再声称由 Eclipse 签名;原生 JVM 签名不变。 +下载缓存、已安装包和 app bundle 都只读,编译输出与组装包不跨 worktree 复用。 +这些是打包补丁的维护成本;上游修复后须先用同一残缺内部类回归验证,再移除补丁。 + ## 考虑过的备选方案 +- 自建反编译器或在宿主识别 `jdt:`:重复成熟上游语义且破坏插件边界;只补上游对残缺输入的遍历,不引入第二套 Java 模型。 - 放宽 Core 声明解码:掩盖宿主把路由信息当成声明的错误,也允许其他无效字段通过。 - 固定增大等待或对所有进度报告重查:前者已在真实冷导入中证明不能恢复丢失的动作,后者会在正常索引时反复触发昂贵查询。只在失败后的工作完成边界重查。 - 要求用户编辑文件或先打开 Debug 面板:把接线时序变成操作前提,不能修复首次使用。 @@ -67,10 +96,13 @@ Core 保留标准 LSP 进度的所有权;插件不申请转发宿主保留的 - `TestJavaPluginCleanupWhilePaused` 在真实 Java 断点暂停后直接返回,跳过成功路径关闭,由始终执行的清理收回运行并确认 Core 返回会话不存在。 - `scripts/desktop/desktop-go.sh test ./...` 与受影响包的 `-race`;本机证据来自 macOS arm64 无头工作台,原生窗口与其他平台未据此标记已验收。 +- `TestJavaPluginBinaryNavigation` 使用自行编译的无源码 JAR,覆盖类型/方法落点、类间连续跳转、缺失内部类和迟到结果不能抢焦点;回归通过前不得据此发布。私有输入只在本地诊断,不进入公开测试或构建产物。 + ## 适用范围 - `desktop/internal/pluginservice/hostactions.go`、`hostproviders.go`、`runs.go` - `desktop/internal/workbench/debug_start.go`、`debug.go`、`pluginworkbench.go`、`pluginbackends.go` - `desktop/internal/workbench/java_plugin_e2e_test.go`、`java_legacy_e2e_test.go`、`java_unmanaged_e2e_test.go` - `desktop/internal/pluginservice/backendlaunch.go`、`backendlaunch_test.go`;Core 的语言服务器引擎握手期限 +- `desktop/internal/workbench/plugincontent.go`、`pluginsync.go`、`pluginsemantics.go`、`java_binary_e2e_test.go`;独立 Java 插件的内容提供者与构建期 JDT 补丁 - 通用职责边界见 [插件后端会话与宿主服务](../architecture/2026-11-10-viva-plugin-host-services-and-backend-sessions.md)。 diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index be7137ed64..1a934e2eab 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -576,7 +576,8 @@ type App struct { // withdraws only its own diagnostics. pluginDiagnostics map[string]*plugindiag.Set // semantics is the editor's pending and presented language answers. - semantics pluginSemantics + semantics pluginSemantics + contentOpen *contentOpenRequest // editor holds the state of the editor features that are not part of the language // semantics: back/forward history, the outline, references and so on (editor_features.go). editor editorFeatures diff --git a/desktop/internal/workbench/java_binary_e2e_test.go b/desktop/internal/workbench/java_binary_e2e_test.go new file mode 100644 index 0000000000..b95776e047 --- /dev/null +++ b/desktop/internal/workbench/java_binary_e2e_test.go @@ -0,0 +1,297 @@ +package workbench + +import ( + "archive/zip" + "context" + "fmt" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" + "sync" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/plugininstall" + "github.com/1lck/Lithe-IDEA/desktop/internal/plugintrust" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" + "github.com/vivaui/viva/gfx" +) + +// Real JDT and a jar generated entirely from this test's own sources: no +// proprietary classes, source attachments, network dependencies or execution. +func TestJavaPluginBinaryNavigation(t *testing.T) { + archive := os.Getenv("LITHE_TEST_JAVA_PLUGIN_ARCHIVE") + if archive == "" { + t.Skip("Java integration archive required") + } + home := os.Getenv("JAVA_HOME") + if home == "" { + t.Fatal("JAVA_HOME with javac is required") + } + javac := filepath.Join(home, "bin", "javac") + if runtime.GOOS == "windows" { + javac += ".exe" + } + library := t.TempDir() + writeFixture(t, library, map[string]string{ + "library/Slow.java": "package library; public class Slow {}", + "library/Entity.java": "package library;\npublic class Entity {\n public String label() { return \"entity\"; }\n public EntitySet owner() { return null; }\n}\n", + "library/Incomplete.java": "package library;\npublic class Incomplete {\n public static class Missing {}\n public String legacyName() { return \"outer\"; }\n}\n", + "library/EntitySet.java": "package library;\npublic class EntitySet {\n public String label() { return \"set\"; }\n public Entity first() { return null; }\n}\n", + }) + classes := filepath.Join(library, "classes") + if err := os.MkdirAll(classes, 0700); err != nil { + t.Fatal(err) + } + compileCtx, compileCancel := context.WithTimeout(context.Background(), 30*time.Second) + command := exec.CommandContext(compileCtx, javac, "--release", "8", "-g", "-d", classes, filepath.Join(library, "library/Entity.java"), filepath.Join(library, "library/EntitySet.java"), filepath.Join(library, "library/Incomplete.java"), filepath.Join(library, "library/Slow.java")) + command.WaitDelay = 2 * time.Second + output, err := command.CombinedOutput() + compileCancel() + if err != nil { + t.Fatalf("compile own binary fixture: %v: %s", err, output) + } + preferenceDir := t.TempDir() + if err := os.WriteFile(filepath.Join(preferenceDir, settingsFile), []byte(`{"theme":"dark"}`), 0600); err != nil { + t.Fatal(err) + } + kernel := &binaryNavigationKernel{testKernel: &testKernel{Client: core.NewClient()}} + h := newHarnessWithOptions(t, Options{Kernel: kernel, PluginKernel: kernel, PluginRoot: t.TempDir(), Store: store.At(preferenceDir), Languages: []string{"en"}}) + service := h.app.plugins + ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second) + defer cancel() + plan, err := service.Installer.Prepare(ctx, plugininstall.Request{ArchivePath: archive, Root: service.Root, Source: plugintrust.Disk}) + if err != nil { + t.Fatal(err) + } + defer func() { + if e := service.Installer.Discard(plan); e != nil { + t.Error(e) + } + }() + installed, err := service.Installer.Commit(plan) + if err != nil { + t.Fatal(err) + } + if err = service.Manager.SetEnabled(plan.ID, true); err != nil { + t.Fatal(err) + } + before := packageDigest(t, installed.Path) + h.app.reloadPluginLanguages() + root, err := filepath.EvalSymlinks(t.TempDir()) + if err != nil { + t.Fatal(err) + } + source := "package app;\nimport library.Entity;\nimport library.EntitySet;\nimport library.Incomplete;\nimport library.Slow;\npublic class Main {\n public static void main(String[] args) {}\n String labels(Entity item, EntitySet set) {return item.label() + set.label();}\n void slow(Slow value) {}\n String legacy(Incomplete old) { return old.legacyName(); }\n}\n" + writeFixture(t, root, map[string]string{ + ".project": `binary-navigationorg.eclipse.jdt.core.javabuilderorg.eclipse.jdt.core.javanature`, + ".classpath": ``, + ".settings/org.eclipse.jdt.core.prefs": "eclipse.preferences.version=1\norg.eclipse.jdt.core.compiler.source=17\norg.eclipse.jdt.core.compiler.compliance=17\norg.eclipse.jdt.core.compiler.codegen.targetPlatform=17\n", + "src/app/Main.java": source, + }) + if err = os.MkdirAll(filepath.Join(root, "lib"), 0700); err != nil { + t.Fatal(err) + } + file, err := os.Create(filepath.Join(root, "lib/library.jar")) + if err != nil { + t.Fatal(err) + } + writer := zip.NewWriter(file) + for _, name := range []string{"Entity", "EntitySet", "Incomplete", "Slow"} { + bytes, e := os.ReadFile(filepath.Join(classes, "library", name+".class")) + if e != nil { + writer.Close() + file.Close() + t.Fatal(e) + } + entry, e := writer.Create("library/" + name + ".class") + if e == nil { + _, e = entry.Write(bytes) + } + if e != nil { + writer.Close() + file.Close() + t.Fatal(e) + } + } + zipErr, fileErr := writer.Close(), file.Close() + if zipErr != nil || fileErr != nil { + t.Fatalf("close binary jar: %v / %v", zipErr, fileErr) + } + t.Cleanup(func() { + if p := h.app.project; p != nil { + h.app.finishCloseProject(p, nil) + awaitStateWithin(t, h, 30*time.Second, "binary project closed", func() bool { return h.app.project == nil }) + } + assertPackageUnchanged(t, installed.Path, before) + }) + h.open(root) + p := h.app.project + t.Cleanup(func() { + if t.Failed() { + t.Logf("notice=%s", h.app.notice) + kernel.mu.Lock() + defer kernel.mu.Unlock() + for _, e := range kernel.events { + t.Logf("definition %s %s => %s error=%s", e.URI, e.OperationID, e.Result, e.Error) + } + } + }) + mainPath := filepath.Join(root, "src/app/Main.java") + h.app.openFile(p, mainPath) + awaitStateWithin(t, h, 120*time.Second, "Java binary project ready", func() bool { + d := documentNamed(p, "Main.java") + return d != nil && len(d.actions) > 0 && service.HasContentProvider(p.root, "jdt://contents/library") + }) + jump := func(d *document, needle, target, symbol string) { + t.Helper() + h.app.selectDocument(p, d.id) + h.app.invalidator.Invalidate() + if err := h.driver.Pump(); err != nil { + t.Fatal(err) + } + text, _ := d.view.Text() + at := strings.Index(string(text), needle) + if at < 0 { + t.Fatalf("missing fixture symbol %q", needle) + } + // Search strings begin at the symbol, including member calls' method name. + prefix := string(text[:at+1]) + line := strings.Count(prefix, "\n") + column := len(prefix) - strings.LastIndex(prefix, "\n") - 1 + d.view.GoToNavigation(line, column, false) + h.app.invalidator.Invalidate() + if err := h.driver.Pump(); err != nil { + t.Fatal(err) + } + + if err := h.driver.Key(gfx.KeyF12, 0); err != nil { + t.Fatal(err) + } + awaitStateWithin(t, h, 30*time.Second, "binary target "+target, func() bool { + v := p.selectedDocument(p.docs.group) + return v != nil && v.virtual && strings.Contains(v.path, "/"+target+".java") + }) + v := p.selectedDocument(p.docs.group) + content, _ := v.view.Text() + line, _ = v.view.CaretUTF16() + lines := strings.Split(string(content), "\n") + if !v.view.ReadOnly() || v.languageID != "java" || line < 0 || line >= len(lines) || !strings.Contains(lines[line], symbol) { + t.Fatalf("binary target %s: language=%s readOnly=%v line=%d expected %s", target, v.languageID, v.view.ReadOnly(), line+1, symbol) + } + } + main := p.docs.byPath(mainPath) + jump(main, "label();", "EntitySet", "label") + jump(main, "Entity item", "Entity", "Entity") + jump(main, "EntitySet set", "EntitySet", "EntitySet") + jump(main, "label() +", "Entity", "label") + jump(main, "label();", "EntitySet", "label") + var entity *document + for _, d := range p.docs.list { + if d.virtual && strings.Contains(d.path, "/Entity.java") { + entity = d + } + } + if entity == nil { + t.Fatal("missing entity view") + } + jump(entity, "EntitySet owner", "EntitySet", "EntitySet") + set := p.selectedDocument(p.docs.group) + jump(set, "Entity first", "Entity", "Entity") + jump(main, "Incomplete old", "Incomplete", "Incomplete") + jump(main, "legacyName();", "Incomplete", "legacyName") + // Hold the real class-content response, move the visible caret, then release it. + // An obsolete navigation must finish without opening a tab or stealing focus. + gate := &binaryContentGate{entered: make(chan struct{}), release: make(chan struct{})} + defer gate.releaseOnce.Do(func() { close(gate.release) }) + kernel.mu.Lock() + kernel.gate = gate + kernel.mu.Unlock() + h.app.selectDocument(p, main.id) + text, _ := main.view.Text() + at := strings.Index(string(text), "Slow value") + 1 + prefix := string(text[:at]) + line := strings.Count(prefix, "\n") + column := len(prefix) - strings.LastIndex(prefix, "\n") - 1 + main.view.GoToNavigation(line, column, false) + h.app.invalidator.Invalidate() + if err := h.driver.Pump(); err != nil { + t.Fatal(err) + } + if err := h.driver.Key(gfx.KeyF12, 0); err != nil { + t.Fatal(err) + } + awaitValueWithin(t, h, 20*time.Second, gate.entered, "class content response held") + if err := h.driver.Key(gfx.KeyRight, 0); err != nil { + t.Fatal(err) + } + gate.releaseOnce.Do(func() { close(gate.release) }) + awaitStateWithin(t, h, 20*time.Second, "obsolete class navigation finished", func() bool { return h.app.contentOpen == nil }) + h.app.invalidator.Invalidate() + if err := h.driver.Pump(); err != nil { + t.Fatal(err) + } + if p.selectedDocument(p.docs.group) != main { + t.Fatal("obsolete class navigation stole focus") + } + for _, d := range p.docs.list { + if d.virtual && strings.Contains(d.path, "/Slow.java") { + t.Fatal("obsolete class navigation opened a tab") + } + } + if len(problemMessages(h.app)) != 0 { + t.Fatalf("fixture has diagnostics: %v", problemMessages(h.app)) + } +} + +// Keep only this fixture's bounded definition results for failure diagnostics. +type binaryNavigationKernel struct { + *testKernel + mu sync.Mutex + events []core.BackendEvent + gate *binaryContentGate +} + +func (k *binaryNavigationKernel) WaitBackendEvents(ctx context.Context, session string, timeout int) ([]core.BackendEvent, error) { + events, err := k.Client.WaitBackendEvents(ctx, session, timeout) + for _, e := range events { + if e.Type == "requestCompleted" && e.Method == "java/classFileContents" { + k.mu.Lock() + gate := k.gate + k.gate = nil + k.mu.Unlock() + if gate != nil { + close(gate.entered) + timer := time.NewTimer(15 * time.Second) + select { + case <-gate.release: + case <-ctx.Done(): + timer.Stop() + return nil, ctx.Err() + case <-timer.C: + return nil, fmt.Errorf("class response gate timed out") + } + timer.Stop() + } + } + if e.Type == "requestCompleted" && e.Method == "textDocument/definition" { + k.mu.Lock() + if len(k.events) < 32 { + k.events = append(k.events, e) + } + k.mu.Unlock() + } + } + return events, err +} + +// This gate is consumed once, released on all assertion paths, and times out on +// the backend worker rather than blocking the UI thread. +type binaryContentGate struct { + entered chan struct{} + release chan struct{} + releaseOnce sync.Once +} diff --git a/desktop/internal/workbench/plugincontent.go b/desktop/internal/workbench/plugincontent.go index 3f1d2531cd..105ec24e5e 100644 --- a/desktop/internal/workbench/plugincontent.go +++ b/desktop/internal/workbench/plugincontent.go @@ -2,8 +2,10 @@ package workbench import ( "context" + "errors" "time" + "github.com/1lck/Lithe-IDEA/desktop/internal/editor/syntax" "github.com/1lck/Lithe-IDEA/desktop/internal/editorview" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" @@ -19,6 +21,36 @@ const contentOpenTimeout = 2 * time.Minute var _ pluginservice.VirtualDocumentHost = pluginWorkbench{} +// The read belongs to the visible source caret. The token stays on the native +// context; it is never part of the plugin protocol or a language-specific rule. +type contentOpenKey struct{} +type contentOpenRequest struct { + project *project + source *document + revision, line, column int + cancel context.CancelFunc +} + +func (r *contentOpenRequest) current(a *App) bool { + if r.project != a.project || r.source == nil || r.project.docs.find(r.source.id) != r.source || r.project.selectedDocument(r.project.docs.group) != r.source { + return false + } + line, column := r.source.view.CaretUTF16() + return r.source.view.Revision() == r.revision && line == r.line && column == r.column +} + +func (a *App) cancelContentOpen() { + if a.contentOpen != nil { + a.contentOpen.cancel() + a.contentOpen = nil + } +} + +func contentOpenAllowed(a *App, ctx context.Context) bool { + request, _ := ctx.Value(contentOpenKey{}).(*contentOpenRequest) + return request == nil || (a.contentOpen == request && request.current(a)) +} + // servedByContentProvider reports whether a plugin serves the URI's scheme. func (a *App) servedByContentProvider(uri string) bool { p := a.project @@ -28,6 +60,7 @@ func (a *App) servedByContentProvider(uri string) bool { // openContentTarget asks the provider for a URI and shows the answer. A failure // opens nothing and tells the user once. func (a *App) openContentTarget(p *project, uri string, line, column int) { + a.cancelContentOpen() if a.plugins == nil { return } @@ -36,12 +69,31 @@ func (a *App) openContentTarget(p *project, uri string, line, column int) { d.view.GoToNavigation(line, column, false) return } + source := p.selectedDocument(p.docs.group) + if source == nil { + return + } + readContext, cancel := context.WithCancel(context.Background()) + row, col := source.view.CaretUTF16() + request := &contentOpenRequest{project: p, source: source, revision: source.view.Revision(), line: row, column: col, cancel: cancel} + a.contentOpen = request + readContext = context.WithValue(readContext, contentOpenKey{}, request) a.background(p, contentOpenTimeout, func(ctx context.Context) func(*App) { - err := a.plugins.OpenContentURI(ctx, p.root, uri, line, column) - if err == nil { - return nil + stop := context.AfterFunc(ctx, cancel) + defer stop() + defer cancel() + err := a.plugins.OpenContentURI(readContext, p.root, uri, line, column) + if errors.Is(err, context.Canceled) && ctx.Err() != nil { + err = ctx.Err() } return func(a *App) { + if a.contentOpen == request { + a.contentOpen = nil + } + // log-exempt: user cancellation: an abandoned navigation opens no tab. + if err == nil || errors.Is(err, context.Canceled) { + return + } a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("plugin_content", err)) a.notifyError(i18n.SharedFormat(a.language(), "desktop.pluginHost.contentFailed", map[string]string{"uri": uri})) } @@ -50,22 +102,43 @@ func (a *App) openContentTarget(p *project, uri string, line, column int) { // OpenVirtualDocument shows provider text in a read-only tab. func (w pluginWorkbench) OpenVirtualDocument(ctx context.Context, root string, document pluginservice.VirtualDocument) error { + registry, err := onWindow(w.app, ctx, func(a *App) (*syntax.Registry, error) { + if !contentOpenAllowed(a, ctx) { + return nil, context.Canceled + } + return a.syntaxRegistry(), nil + }) + if err != nil { + return err + } // Laying the text out takes time in proportion to it, so it is done here and - // the window thread only shows it. + // the window thread only shows it. Grammar loading follows the same path as + // disk documents and must also stay off the window thread. content := editorview.Prepare([]byte(document.Text)) - _, err := onWindow(w.app, ctx, func(a *App) (struct{}, error) { + grammar := registry.SyntaxForPath(document.Name) + languageID := "" + if language, ok := registry.ForPath(document.Name); ok { + languageID = language.ID + } + _, err = onWindow(w.app, ctx, func(a *App) (struct{}, error) { + if !contentOpenAllowed(a, ctx) { + return struct{}{}, context.Canceled + } p, err := a.projectAt(root) if err != nil { return struct{}{}, err } + // The UI commit is synchronous. Clear the read owner before selecting + // its destination, so ordinary focus cleanup cannot cancel this commit. + if request, _ := ctx.Value(contentOpenKey{}).(*contentOpenRequest); request != nil && a.contentOpen == request { + a.contentOpen = nil + } if d := p.docs.byPath(document.URI); d != nil { a.selectDocument(p, d.id) d.view.GoToNavigation(document.Line, document.Column, false) return struct{}{}, nil } - registry := a.syntaxRegistry() - grammar := registry.SyntaxForPath(document.Name) - a.placeDocumentAs(p, document.URI, document.Name, content, grammar, "", true) + a.placeDocumentAs(p, document.URI, document.Name, content, grammar, languageID, true) if d := p.docs.byPath(document.URI); d != nil { d.view.GoToNavigation(document.Line, document.Column, false) } diff --git a/desktop/internal/workbench/pluginsemantics.go b/desktop/internal/workbench/pluginsemantics.go index 454262e387..84e5e3d3f3 100644 --- a/desktop/internal/workbench/pluginsemantics.go +++ b/desktop/internal/workbench/pluginsemantics.go @@ -534,6 +534,7 @@ func (a *App) startPluginUsages(p *project, d *document, line, column int, requi // startPluginLocations asks for a location list (definition or references); usages marks the // references of a declaration a go-to-declaration gesture was made on. func (a *App) startPluginLocations(kind semanticKind, p *project, d *document, line, column int, requireCaret, usages bool) { + a.cancelContentOpen() if a.plugins == nil || p == nil || d == nil || a.project != p { return } @@ -1491,6 +1492,9 @@ func (a *App) pointPluginHover(p *project, d *document, line, column int, anchor // request belongs to the caret it was opened at; moving the caret makes it // stale and closes it. func (a *App) pluginSemanticsCaretSync() { + if a.contentOpen != nil && !a.contentOpen.current(a) { + a.cancelContentOpen() + } state := &a.semantics if state.project == nil || a.project != state.project { return @@ -1549,6 +1553,9 @@ func (a *App) pluginSemanticsEdited(d *document) { // pluginSemanticsDocumentClosed drops state that belonged to a closed tab. func (a *App) pluginSemanticsDocumentClosed(d *document) { + if a.contentOpen != nil && a.contentOpen.source == d { + a.cancelContentOpen() + } if d == nil || a.semantics.documentID != d.id { return } @@ -1570,6 +1577,7 @@ func (a *App) pluginSemanticsReset() { } func (a *App) closePluginSemantics() { + a.cancelContentOpen() a.closeSemanticCompletion() a.closeSemanticDefinition() a.closeSemanticHover() diff --git a/desktop/internal/workbench/pluginsync.go b/desktop/internal/workbench/pluginsync.go index 1396598f3b..5bc4c502d1 100644 --- a/desktop/internal/workbench/pluginsync.go +++ b/desktop/internal/workbench/pluginsync.go @@ -119,7 +119,7 @@ func (a *App) startDocumentSync(p *project, d *document) { return } if !s.opened || s.pluginID != pluginID { - path, languageID := d.path, d.languageID + path, languageID, virtual := d.path, d.languageID, d.virtual text, _ := d.view.Text() revision, generation := d.view.Revision(), s.generation // Bind ownership before Open returns so disabling the plugin also @@ -127,7 +127,13 @@ func (a *App) startDocumentSync(p *project, d *document) { s.pluginID = pluginID s.running = true a.background(p, documentSyncTimeout, func(ctx context.Context) func(*App) { - uri, err := a.kernel.PluginDocumentURI(ctx, path, "auto") + // Provider documents already carry a URI; only disk-backed views + // need a native-path conversion. Core validates both at Open. + uri := path + var err error + if !virtual { + uri, err = a.kernel.PluginDocumentURI(ctx, path, "auto") + } if err == nil { var identity string identity, err = server.session.Documents.Open(ctx, pluginlsp.Document{ diff --git a/desktop/internal/workbench/pluginsync_test.go b/desktop/internal/workbench/pluginsync_test.go index 89ca63c5e8..958ee04785 100644 --- a/desktop/internal/workbench/pluginsync_test.go +++ b/desktop/internal/workbench/pluginsync_test.go @@ -2,9 +2,11 @@ package workbench import ( "context" + "errors" "os" "path/filepath" "testing" + "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginlsp" @@ -142,3 +144,56 @@ func TestReleasePluginInvalidatesOpeningDocument(t *testing.T) { t.Fatal("a late Open restored synchronization for the released plugin") } } + +// Providers may serve any language. Preserve the document's URI verbatim so +// subsequent definitions refer to the same identity that supplied its text. +func TestVirtualDocumentPreservesLanguageAndSyncURI(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + root, _ := openNote(t, h, "x") + uri := "dependency-source://library/Widget.go?revision=one%2Ftwo" + _, err := callOnWindow(h, "virtual language document", func(ctx context.Context) (struct{}, error) { + return struct{}{}, (pluginWorkbench{app: h.app}).OpenVirtualDocument(ctx, root, pluginservice.VirtualDocument{URI: uri, Name: "Widget.go", Text: "package dependency\ntype Widget struct{}\n"}) + }) + if err != nil { + t.Fatal(err) + } + p := h.app.project + d := p.docs.byPath(uri) + if d == nil || d.languageID != "go" { + t.Fatal("virtual source did not retain its Go language") + } + capture := &virtualSyncKernel{request: make(chan core.PluginDocumentSyncRequest, 1)} + tracker := pluginlsp.New(capture, "virtual-session") + original := h.app.plugins + h.app.plugins = &pluginservice.Service{} + h.app.pluginServers = map[string]*pluginServer{"dependency": {session: &pluginservice.LanguageSession{PluginID: "dependency", Documents: tracker}, cancel: func() {}}} + h.app.pluginServerLanguages = map[string]string{"go": "dependency"} + defer func() { h.app.plugins = original; h.app.pluginServers = nil; h.app.pluginServerLanguages = nil }() + h.app.startDocumentSync(p, d) + awaitStateWithin(t, h, 3*time.Second, "virtual synchronization", func() bool { return !d.sync.running }) + if !d.sync.opened || d.sync.uri != uri { + t.Fatalf("virtual sync lost identity: %+v", d.sync) + } + select { + case got := <-capture.request: + if got.URI != uri || got.LanguageID != "go" { + t.Fatalf("sync request = %+v", got) + } + default: + t.Fatal("virtual source was not synchronized") + } +} + +type virtualSyncKernel struct { + closeRecordKernel + request chan core.PluginDocumentSyncRequest +} + +func (k *virtualSyncKernel) SyncPluginDocument(_ context.Context, r core.PluginDocumentSyncRequest) (core.PluginDocumentSync, error) { + select { + case k.request <- r: + default: + return core.PluginDocumentSync{}, errors.New("unexpected duplicate virtual sync") + } + return core.PluginDocumentSync{URI: r.URI, DocumentVersion: 1, Changed: true}, nil +} diff --git a/docs/ci-builds.md b/docs/ci-builds.md index cf9b6df962..3dee5bb9c9 100644 --- a/docs/ci-builds.md +++ b/docs/ci-builds.md @@ -428,6 +428,15 @@ macOS Build 偏好编辑复用同一文档,只在明确 Save/Reset 后条件 也可重开。持续修改最多重试一次,关闭释放观察,不新增下载、持久缓存或可复用资源。 +独立 Java 插件的反编译补丁只在插件仓库构建时执行:原始 JDT/JDK 下载仍为只读、按锁校验的输入, +`/.artifacts/package///` 与 +`.artifacts/windows-package-/` 是每次组装的输出;`/lithe-jdt-decompiler-*/` +由单次编译拥有并在成功或失败时删除。补丁验证上游源码/JAR、修改源码、编译器版本/平台/归档哈希、 +生成 class 集合与各项哈希;这些不构成可复用 worktree identity,三类输出均经 +`official-plugin-packages` 拒绝路由,任何阶段都不复制或共享。修改后的 JDT core JAR +移除已失效的 Eclipse JAR 签名,随包提供修改后的 EPL 源码和补丁清单;原生 JVM 签名不变。 +运行时只读取安装包,索引和配置继续走平台可写状态目录,不影响应用签名或 Sparkle delta。 + Windows 注册表 stdio 调试器状态位于 `//plugin-state//debug-adapters///`。 由当前插件/适配器/工作区拥有;停止会话关闭进程,卸载插件清理其状态。语言服务器托管适配器 diff --git a/scripts/resources/reuse-worktree-resources.mjs b/scripts/resources/reuse-worktree-resources.mjs index de4d7e5d75..160f976f1e 100644 --- a/scripts/resources/reuse-worktree-resources.mjs +++ b/scripts/resources/reuse-worktree-resources.mjs @@ -428,6 +428,8 @@ async function main() { // official-plugin-packages also rejects dist/packages, dist/verify, per-architecture // release ZIPs, synthetic published-index.fixture.json and java-plugin-distribution probes; // origin trust and build-index ownership are not transferable. + // This also rejects independent Java plugin patched package staging and + // lithe-jdt-decompiler-* compiler scratch; only original locked downloads reuse. // Includes agent-hook-library-state: user commands, native ownership journals and locks have no copy stage. // Includes agent-instruction-library-state: user text and sync locks have no build identity or copy stage. // Includes mcp-tool-probe-state: SDK sessions, native tool exclusions and diff --git a/scripts/resources/test-reuse-worktree-resources.mjs b/scripts/resources/test-reuse-worktree-resources.mjs index 49f90c7ddf..93e5a2d3ef 100644 --- a/scripts/resources/test-reuse-worktree-resources.mjs +++ b/scripts/resources/test-reuse-worktree-resources.mjs @@ -427,6 +427,11 @@ try { const registry = JSON.parse(await fs.readFile(path.join(scriptDirectory, "worktree-resources.json"), "utf8")); const packages = registry.excludedResources.find(item => item.id === "official-plugin-packages"); assert.ok(packages.locations.includes("dist/packages///")); + assert.ok(packages.locations.includes("/.artifacts/package///")); + assert.ok(packages.locations.includes("/.artifacts/windows-package-/")); + assert.ok(packages.locations.includes("/lithe-jdt-decompiler-*/")); + assert.match(packages.identity, /compiler version\/platform\/archive hash/); + assert.match(packages.reason, /read-only inputs/); assert.ok(packages.locations.includes("dist/verify///")); assert.ok(packages.locations.includes(".artifacts/java-plugin-distribution/")); assert.ok(packages.locations.includes("/lithe-package-verification.*/published-index.fixture.json")); diff --git a/scripts/resources/worktree-resources.json b/scripts/resources/worktree-resources.json index 0c3c4e091d..6f1b279bb5 100644 --- a/scripts/resources/worktree-resources.json +++ b/scripts/resources/worktree-resources.json @@ -208,10 +208,13 @@ "//plugin-state//build-systems///", "//plugin-state//toolchain-queries///", "//plugin-state//debug-adapters///", - "/.state///desktop-debug-/" + "/.state///desktop-debug-/", + "/.artifacts/package///", + "/.artifacts/windows-package-/", + "/lithe-jdt-decompiler-*/" ], - "identity": "Assembled plugin packages carry build-time downloads (JDT LS, its extensions and one JDK per target architecture for Java Support) and an optional publisher signature; no reliable worktree identity stamp. Plugin state directories are mutable language-server state of one installation. Independent release archives bind plugin version, darwin architecture, upstream input hashes, API/requires and final publisher signature; host-sealed bundled copies are a different origin, never a reusable package Build Provider model/dependency snapshots and output state are mutable per-plugin/build-system/workspace inputs; they have no version/platform/architecture/toolchain identity stamp.", - "reason": "Assemble each official declarative plugin independently in every worktree and validate it with LitheOfficialPluginVerifier; do not copy or symlink it across worktrees. Java Support is assembled from the reusable jdtls and jdk download caches by Plugins/mac/Official/JavaSupport/assemble-package.sh, so reuse those caches rather than the package. Never copy or share plugin state at any stage. Release verification extracts a separate copy and checks its publisher signature; delete per-run dist/verify and local integration output when no longer needed. Never transfer a sealed-origin exception to user-installed copies. Runtime installation versions stay read-only, preserving app signatures and Sparkle delta baselines. Distribution decisions read the current checkout index or explicit LITHE_OFFICIAL_PLUGIN_INDEX/--marketplace-index build input; synthetic packaging indexes are per-test fixtures, never reusable or publishable source indexes. Maven uses existing Provider state instead of the removed macOS Maven dependency-tree temporary adapter. Never reconstruct a JAR path from a legacy tree. Windows Build Provider startup uses the same platform app-data owner with a separate build-system subtree, never a language-server state directory or package resource. Workspace hashes identify runtime owners, not reusable build artifacts. Native toolchain-provider backends are owned only by one Build preparation, reuse their process within that operation and stop before returning; their exclusive per-plugin/operation/workspace state is mutable, has no build identity and is never copied at any stage; stop owned processes before deleting that state. Registry stdio debugger state is mutable per-plugin/adapter/workspace state with no build identity stamp and no permitted copy stage; language-server hosted adapters retain the existing language-server state owner, and stopping Debug never removes shared server state. Viva stdio Debug creates only Core-required scratch directories under its per-session writable plugin state, removes them after startup and native process cleanup, and never writes the installed version or bundle. This session state has no reusable identity and all reuse stages reject it." + "identity": "Assembled plugin packages carry build-time downloads (JDT LS, its extensions and one JDK per target architecture for Java Support) and an optional publisher signature; no reliable worktree identity stamp. Plugin state directories are mutable language-server state of one installation. Independent release archives bind plugin version, darwin architecture, upstream input hashes, API/requires and final publisher signature; host-sealed bundled copies are a different origin, never a reusable package Build Provider model/dependency snapshots and output state are mutable per-plugin/build-system/workspace inputs; they have no version/platform/architecture/toolchain identity stamp. The Java decompiler patch is bound to the pinned upstream source/JAR, modified source, exact generated class set, compiler version/platform/archive hash and patched JAR/class hashes; these checks do not create a reusable worktree identity.", + "reason": "Assemble each official declarative plugin independently in every worktree and validate it with LitheOfficialPluginVerifier; do not copy or symlink it across worktrees. Java Support is assembled from the reusable jdtls and jdk download caches by Plugins/mac/Official/JavaSupport/assemble-package.sh, so reuse those caches rather than the package. Never copy or share plugin state at any stage. Release verification extracts a separate copy and checks its publisher signature; delete per-run dist/verify and local integration output when no longer needed. Never transfer a sealed-origin exception to user-installed copies. Runtime installation versions stay read-only, preserving app signatures and Sparkle delta baselines. Distribution decisions read the current checkout index or explicit LITHE_OFFICIAL_PLUGIN_INDEX/--marketplace-index build input; synthetic packaging indexes are per-test fixtures, never reusable or publishable source indexes. Maven uses existing Provider state instead of the removed macOS Maven dependency-tree temporary adapter. Never reconstruct a JAR path from a legacy tree. Windows Build Provider startup uses the same platform app-data owner with a separate build-system subtree, never a language-server state directory or package resource. Workspace hashes identify runtime owners, not reusable build artifacts. Native toolchain-provider backends are owned only by one Build preparation, reuse their process within that operation and stop before returning; their exclusive per-plugin/operation/workspace state is mutable, has no build identity and is never copied at any stage; stop owned processes before deleting that state. Registry stdio debugger state is mutable per-plugin/adapter/workspace state with no build identity stamp and no permitted copy stage; language-server hosted adapters retain the existing language-server state owner, and stopping Debug never removes shared server state. Viva stdio Debug creates only Core-required scratch directories under its per-session writable plugin state, removes them after startup and native process cleanup, and never writes the installed version or bundle. This session state has no reusable identity and all reuse stages reject it. The independent lithe-plugin-java scripts/package/patch-jdt-decompiler.mjs compiles only into invocation-owned OS temporary output, repacks only fresh staging and removes temporary output in finally. Never reuse patched staging or compiler output; verified original JDT/JDK download caches remain read-only inputs. The rebuilt JDT core JAR removes its invalid upstream Eclipse signature while preserving OSGi metadata; packaged modified EPL source and patch hashes record that boundary. Native JVM signatures and runtime app/Sparkle source bytes are unchanged." }, { "id": "language-tools", diff --git a/shared/platform-feature-matrix/features/java-support-plugin.json b/shared/platform-feature-matrix/features/java-support-plugin.json index 70e831ff96..c84f2bebb8 100644 --- a/shared/platform-feature-matrix/features/java-support-plugin.json +++ b/shared/platform-feature-matrix/features/java-support-plugin.json @@ -2,7 +2,7 @@ "id": "java-support-plugin", "area": "语言支持", "group": "Java", - "capability": "Java 语言支持由独立插件 io.github.lithe-idea.java-support 提供:JDT LS、调试适配器、测试与运行入口由插件包和插件后端拥有,可安装、卸载和更新;宿主只提供通用的语言服务器、构建、工具链、调试适配器与插件函数中转契约,不内置任何 Java 逻辑", + "capability": "Java 语言支持由独立插件 io.github.lithe-idea.java-support 提供:JDT LS、调试适配器、测试与运行入口由插件包和插件后端拥有,可安装、卸载和更新;宿主只提供通用的语言服务器、构建、工具链、调试适配器与插件函数中转契约,不内置任何 Java 逻辑;二进制类只读源码和类间导航由插件内容提供者接入,宿主按通用语言注册表同步虚拟文档", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -12,6 +12,7 @@ "desktop/internal/workbench/java_unmanaged_e2e_test.go", "desktop/internal/workbench/java_web_e2e_test.go", "desktop/internal/workbench/java_gradle_e2e_test.go", + "desktop/internal/workbench/java_binary_e2e_test.go", ".agents/notes/implemented/bug-fix/2026-11-13-viva-plugin-run-debug-lifecycle.md" ] }, @@ -24,11 +25,12 @@ "desktop/internal/workbench/java_unmanaged_e2e_test.go", "desktop/internal/workbench/java_web_e2e_test.go", "desktop/internal/workbench/java_gradle_e2e_test.go", + "desktop/internal/workbench/java_binary_e2e_test.go", ".agents/notes/implemented/bug-fix/2026-11-13-viva-plugin-run-debug-lifecycle.md" ] }, "owner": "Java Support", - "verification": "Viva 显式无头集成使用真实独立插件 ZIP、隔离用户存储、JDT 与 java-debug,覆盖普通 Maven、Java 8 旧布局、多模块/Profile、外部 JAR、普通源码、Eclipse/Ant 源码布局、Gradle Wrapper reactor,以及 WAR/Tomcat 的 JSP HTTP 请求和 Servlet 断点;核对编译版本、补全、运行结果、变量、继续/停止、错误编译拒绝旧 class、关闭后进程清理与安装目录哈希。Ant 布局不等于执行 Ant target,JSP 请求/Servlet 调试不等于 JSP 源码断点或补全验收。需逐平台执行这些用例,并另验收原生窗口、导航/虚拟源码、行内测试、失败/取消和日志 UI。历史 Java 5/7 源码级别当前被 ECJ 拒绝,不能以安全拒绝测试表示支持。", + "verification": "Viva 显式无头集成使用真实独立插件 ZIP、隔离用户存储、JDT 与 java-debug,覆盖普通 Maven、Java 8 旧布局、多模块/Profile、外部 JAR、普通源码、Eclipse/Ant 源码布局、Gradle Wrapper reactor,以及 WAR/Tomcat 的 JSP HTTP 请求和 Servlet 断点;核对编译版本、补全、运行结果、变量、继续/停止、错误编译拒绝旧 class、关闭后进程清理与安装目录哈希。Ant 布局不等于执行 Ant target,JSP 请求/Servlet 调试不等于 JSP 源码断点或补全验收。需逐平台执行这些用例,并另验收原生窗口、导航/虚拟源码、行内测试、失败/取消和日志 UI。历史 Java 5/7 源码级别当前被 ECJ 拒绝,不能以安全拒绝测试表示支持。 二进制回归使用自建无源码 JAR,覆盖类型/方法落点、虚拟类间继续跳转、缺少内部类的外部类、过期导航取消及安装目录哈希不变;私有文件仅本地诊断,不进入 fixture 或公开产物。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": {