diff --git a/.agents/notes/implemented/feature/2026-11-18-run-current-file-entrypoint.md b/.agents/notes/implemented/feature/2026-11-18-run-current-file-entrypoint.md new file mode 100644 index 0000000000..e552ace449 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-11-18-run-current-file-entrypoint.md @@ -0,0 +1,55 @@ +# Agent 笔记:当前文件运行(按需运行入口) + +状态:已实现 + +## 先说结论 + +标题栏选“当前文件”后点运行,可以直接运行当前文件里的入口,例如没有在 POM 里写明主类、但带 `main` 方法的 Java 类(#2104): + +- 插件在构建系统里声明入口运行 `{"id": "main", "source": "provider", "entrypoints": true}`,需要 `requires.buildProviders: 1`。入口运行不对应构建目标,不出现在构建树和运行配置列表里,只在用户运行某个文件时才产生配置。 +- 宿主把当前文件(工作区相对路径)交给根目录包含它的构建实例(内层优先)。Core 用 `build.runEntrypointsPlan` 规划 `lithe/build/runEntrypoints` 请求,插件按文件回答入口,Core 用 `build.decodeRunEntrypoints` 校验:运行必须是入口运行、名称和入口长度受限、项目在实例根目录内,答案不合法时整份拒绝。 +- 宿主取第一个入口,按项目路径找到模型里的项目,用 `runConfig.createUserConfiguration` 保存本机配置:名称取入口名(类名),引用的 `targetID` 为空,入口存为 `extensions.build-run.entrypoint`,入口是配置身份的一部分。同一入口再次运行复用已保存的配置。 +- 保存后重新读取配置、在标题栏选中并运行。准备运行时请求不带 `target`,入口通过 `launchOptions.entrypoint` 交给插件。之后用户可以像编辑其他构建提供者运行一样修改参数、环境变量和工作目录。 +- 没有打开文件、没有可回答的构建实例或文件里没有入口时,提示“当前文件没有可运行的入口”。 +- Maven 插件按源码文本回答:文件所在的最近一个含 `pom.xml` 的模块,包名加文件名作为类名,必须有 `static void main(String[])` 或 `String...`;测试源码不算,因为运行使用的运行时类路径不含测试类。不编译,回答很快。 + +## 问题 + +插件读取模型时不编译,也不会把每个 main 类都列成运行配置,否则下拉会被工具类淹没。于是 POM 里没写主类的 main 类没有运行配置,选“当前文件”也只能提示“需要运行配置”,用户只能去改 POM。 + +## 决策 + +- 由插件按文件回答入口,而不是宿主按语言判断:宿主和 Core 不认识 Java,任何构建插件都能用同一机制提供“运行这个文件”。 +- 入口运行不绑定目标,配置引用只到项目。这样构建树不需要为每个可能的入口建目标,入口也能来自模型没有列出的类。 +- 能力版本:`buildProviders` 和 `litheBuild` 都升到 1。旧宿主不声明 1,不会安装需要入口运行的插件版本;SDK 按宿主提供的版本协商最新的一个。 +- 入口作为配置身份的一部分,同一模块里不同类各存一条配置,同一个类不会重复保存。 +- 一个文件有多个入口时先运行第一个;选择菜单以后需要时再加。 + +## 考虑过的备选方案 + +- 模型读取时扫描源码把所有 main 类列成目标:读取变慢、工具类和测试辅助类会淹没下拉(#2074 已否决)。 +- 行号旁运行图标:需要编辑器按语言识别 main 方法或额外的插件协议;标题栏“当前文件”已有入口,先复用它。 +- 入口运行支持调试:Maven 的调试需要声明调试方式(服务运行用 `debug.configurationType`),入口运行的调试和准备方式另行设计,本轮只做运行。 + +## 后果 + +- 插件可以按文件提供可运行的入口;新增语言或构建工具时只需在插件里回答 `lithe/build/runEntrypoints`。 +- 使用入口运行的插件版本需要支持 `buildProviders` 1 的宿主,插件应和支持它的桌面版本一起发布。 +- 以后加入口运行的调试,需要在契约里给入口运行声明调试方式,并在 `decideTitleAction` 的可调试判断里覆盖入口运行。 + +## 验证 + +- Core:`cargo test -p lithe-core provider_run_entrypoints_are_found_by_file_and_start_without_a_target entrypoint_runs_are_saved_per_entrypoint_without_a_target`。 +- 宿主:`./scripts/desktop/desktop-go.sh test ./internal/workbench/ -run TestRunOnCurrentFile -count=1`(合成构建提供者回答入口、准备运行);截图 `TestVisualRunOnCurrentFile`。 +- Maven 插件:`node scripts/test.mjs` 中的入口查找和入口运行检查(真实 Maven)。 + +## 适用范围 + +- `desktop/internal/workbench/title_run_entrypoints.go` +- `desktop/internal/workbench/title_run.go` +- `desktop/internal/workbench/build.go`(`runBuildTargetWith` 接受没有目标的运行) +- `desktop/internal/core/build_entrypoints.go` +- `desktop/internal/pluginservice/builds.go`(`EntrypointRuns`) +- `desktop/internal/pluginhost/pluginhost.go`(`buildProviders` 声明 `[0, 1]`) +- Core:`rust/crates/build/src/run_entrypoints.rs`、`rust/crates/execution/src/configuration/editing.rs` +- Maven 插件:`provider/src/main/java/io/github/litheidea/maven/provider/RunEntrypoints.java` diff --git a/desktop/internal/core/build.go b/desktop/internal/core/build.go index 63c22a3172..bb54adbeb3 100644 --- a/desktop/internal/core/build.go +++ b/desktop/internal/core/build.go @@ -123,8 +123,10 @@ type BuildPlanRequest struct { Refresh bool `json:"refresh,omitempty"` Tool *BuildTool `json:"tool,omitempty"` WorkspaceRoot string `json:"workspaceRoot,omitempty"` - // LaunchOptions are a run configuration's choices (buildProviders 10). + // LaunchOptions are a run configuration's choices. LaunchOptions *RunLaunchOptions `json:"launchOptions,omitempty"` + // File is the workspace-relative source file build.runEntrypointsPlan asks about. + File string `json:"file,omitempty"` } // BuildProviderRequest is the typed request a provider-backed plan names. @@ -277,6 +279,8 @@ type buildOutcome struct { Discovery *BuildTestDiscovery `json:"discovery"` // Tree answers build.modelTree. Tree *BuildModelTree `json:"tree"` + // Entrypoints answers build.decodeRunEntrypoints. + Entrypoints *BuildRunEntrypoints `json:"entrypoints"` } func (o buildOutcome) failure(command string) error { diff --git a/desktop/internal/core/build_entrypoints.go b/desktop/internal/core/build_entrypoints.go new file mode 100644 index 0000000000..a4ea97cbc0 --- /dev/null +++ b/desktop/internal/core/build_entrypoints.go @@ -0,0 +1,86 @@ +package core + +import ( + "context" + "encoding/json" +) + +// BuildRunEntrypoint is one entrypoint a provider found in a source file (buildProviders 1). +// Core checked that Run is an entrypoint run of the build system and that Project is inside +// the instance root; Entrypoint is opaque to the host and goes back as launchOptions.entrypoint. +type BuildRunEntrypoint struct { + Run string `json:"run"` + Name string `json:"name"` + Entrypoint string `json:"entrypoint"` + Project BuildSelection `json:"project"` +} + +// BuildRunEntrypoints is Core's answer to build.decodeRunEntrypoints. +type BuildRunEntrypoints struct { + Entrypoints []BuildRunEntrypoint `json:"entrypoints"` +} + +// BuildDecodeRunEntrypointsRequest carries the plan context the request ran with and the +// litheRunEntrypoints document the provider answered. +type BuildDecodeRunEntrypointsRequest struct { + Root string `json:"root"` + Options map[string]json.RawMessage `json:"options,omitempty"` + PluginDirectory string `json:"pluginDirectory,omitempty"` + WorkspaceStateDirectory string `json:"workspaceStateDirectory,omitempty"` + Result json.RawMessage `json:"result"` +} + +// PlanBuildRunEntrypoints plans the provider request that names the entrypoints of +// request.File. Only a declaration with an entrypoint run accepts it; the request names a file, +// never a project or target. +func (c *Client) PlanBuildRunEntrypoints(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildPlanRequest) (BuildPlan, error) { + return c.planBuild(ctx, "build.runEntrypointsPlan", manifest, buildSystemID, request) +} + +// DecodeBuildRunEntrypoints validates a provider's entrypoints, in the provider's order without +// duplicates. Core rejects the whole document rather than offer a partial list. +func (c *Client) DecodeBuildRunEntrypoints(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildDecodeRunEntrypointsRequest) ([]BuildRunEntrypoint, error) { + const command = "build.decodeRunEntrypoints" + var result buildOutcome + if err := c.Execute(ctx, command, struct { + Manifest json.RawMessage `json:"manifest"` + BuildSystemID string `json:"buildSystemID"` + Request BuildDecodeRunEntrypointsRequest `json:"request"` + }{manifest, buildSystemID, request}, &result); err != nil { + return nil, err + } + if err := result.failure(command); err != nil { + return nil, err + } + if result.Entrypoints == nil { + return nil, newParseError(command, "run entrypoints returned no entrypoints", "") + } + return result.Entrypoints.Entrypoints, nil +} + +// RunEntrypointConfigurationRequest saves the configuration that starts one entrypoint: a +// local build provider configuration whose reference names no target and whose +// extensions.build-run.entrypoint is Entrypoint. Saving the same entrypoint again answers the +// configuration already saved. +type RunEntrypointConfigurationRequest struct { + Root string `json:"root"` + Name string `json:"name"` + Build RunProviderReference `json:"build"` + Entrypoint string `json:"entrypoint"` + Plugins []RunInstalledPlugin `json:"plugins,omitempty"` +} + +// CreateRunEntrypointConfiguration returns the ID of the configuration that starts the +// entrypoint and the file changes that save it. Core writes nothing. +func (c *Client) CreateRunEntrypointConfiguration(ctx context.Context, request RunEntrypointConfigurationRequest) (string, []RunConfigChange, error) { + var result struct { + ID string `json:"id"` + Changes []RunConfigChange `json:"changes"` + } + err := c.Execute(ctx, "runConfig.createUserConfiguration", struct { + RunEntrypointConfigurationRequest + Scope string `json:"scope"` + Kind string `json:"type"` + }{request, "local", "buildProvider"}, &result) + return result.ID, result.Changes, err +} diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 5eee338a6d..ee13403216 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1860,7 +1860,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.title.branchMenu": "Branch menu", "desktop.title.cloneLater": "Cloning repositories comes later", "desktop.title.configurationNotStartable": "{name} cannot be started: no build plugin runs it.", - "desktop.title.currentFileNotRunnable": "The current file cannot run on its own. Choose a project run configuration from the run configuration menu.", + "desktop.title.currentFileNotRunnable": "The current file has no entrypoint to run, such as a class with a main method. Open such a file, or choose a run configuration from the run configuration menu.", "desktop.title.hiddenRunConfigurations": "{count} saved configurations hidden (not runnable)", "desktop.title.keymapLater": "The keymap page comes later", "desktop.title.logsUnavailable": "The log could not be opened when Lithe started", @@ -4760,7 +4760,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.title.branchMenu": "分支菜单", "desktop.title.cloneLater": "克隆仓库稍后提供", "desktop.title.configurationNotStartable": "无法启动 {name}:没有构建插件负责运行它。", - "desktop.title.currentFileNotRunnable": "当前文件不能单独运行。请在运行配置菜单里选择一个项目运行配置。", + "desktop.title.currentFileNotRunnable": "当前文件没有可运行的入口(例如带 main 方法的类)。请打开这样的文件,或在运行配置菜单里选择一个运行配置。", "desktop.title.hiddenRunConfigurations": "已隐藏 {count} 条无法运行的已保存配置", "desktop.title.keymapLater": "快捷键页稍后提供", "desktop.title.logsUnavailable": "Lithe 启动时未能打开日志", diff --git a/desktop/internal/pluginhost/pluginhost.go b/desktop/internal/pluginhost/pluginhost.go index 51745d672f..2e11bc3889 100644 --- a/desktop/internal/pluginhost/pluginhost.go +++ b/desktop/internal/pluginhost/pluginhost.go @@ -98,8 +98,9 @@ type Capabilities map[string][]int // - buildSystems and buildProviders: the Build window detects instances, // loads provider models, resolves the ordered executable candidates Core // returns, runs command and provider tasks, prepares application targets -// and discovers and runs provider tests. Run sessions a backend starts are -// owned by the host. +// and discovers and runs provider tests. Run on Current File asks the +// providers of version 1 for the file's entrypoints and saves the first as a +// run configuration. Run sessions a backend starts are owned by the host. // - toolDefinitions: settings discovery, Build/Run selection and tool // launches use the shared Core resolver. // - commandInstallers: plugin management reports the commands a @@ -167,6 +168,8 @@ func Declared() Capabilities { // Version 1 adds module sidebars, field sections and entry lists, which the // settings window's source forms render. declared["sourceSettings"] = []int{0, 1} + // Version 1 adds entrypoint runs, which Run on Current File starts. + declared["buildProviders"] = []int{0, 1} return declared } diff --git a/desktop/internal/pluginhost/pluginhost_test.go b/desktop/internal/pluginhost/pluginhost_test.go index 0b3f291225..c0e27bba46 100644 --- a/desktop/internal/pluginhost/pluginhost_test.go +++ b/desktop/internal/pluginhost/pluginhost_test.go @@ -73,6 +73,10 @@ func TestDeclaredServesTheBaselineOfEveryWiredCapability(t *testing.T) { if name == "sourceSettings" { wanted = []int{0, 1} } + // Run on Current File starts the entrypoint runs version 1 adds. + if name == "buildProviders" { + wanted = []int{0, 1} + } if versions := declared[name]; !slices.Equal(versions, wanted) { t.Fatalf("%s = %v, want %v", name, versions, wanted) } diff --git a/desktop/internal/pluginservice/builds.go b/desktop/internal/pluginservice/builds.go index f1ca491122..7aafa428a9 100644 --- a/desktop/internal/pluginservice/builds.go +++ b/desktop/internal/pluginservice/builds.go @@ -34,6 +34,10 @@ type BuildSystemDeclaration struct { Provider bool Tasks []BuildTaskDeclaration Runs []BuildRunDeclaration + // EntrypointRuns are the runs declared with entrypoints (buildProviders 1): the provider + // names the entrypoints a source file holds, and each starts in its project without a + // target. They never appear among Runs, which apply to targets. + EntrypointRuns []BuildRunDeclaration // Test is the presentation part of the optional test declaration. Core // still owns whether a selection can run; the window only needs to know // that the system offers tests and on which scopes. @@ -181,6 +185,7 @@ type rawBuildManifest struct { Name string `json:"name"` Source string `json:"source"` Execution string `json:"execution"` + Entrypoints bool `json:"entrypoints"` FromTargets *struct { Tags []string `json:"tags"` } `json:"fromTargets"` @@ -235,6 +240,10 @@ func parseBuildSystems(manifest json.RawMessage) (map[string]BuildSystemDeclarat }) } for _, run := range raw.Run { + if run.ID != "" && run.Source == "provider" && run.Entrypoints { + system.EntrypointRuns = append(system.EntrypointRuns, BuildRunDeclaration{ID: run.ID, Name: run.Name, Execution: "application"}) + continue + } if run.ID == "" || run.Source != "provider" || run.FromTargets == nil { continue } diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 65b5b4da17..976d009f07 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -130,6 +130,11 @@ type Kernel interface { // BuildModelTree lays out a loaded model as the Build tool window's tree (build_tree.go). BuildModelTree(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildModelTreeRequest) (core.BuildModelTree, error) DecodeBuildRun(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildDecodeRunRequest) (core.BuildLaunch, error) + // PlanBuildRunEntrypoints, DecodeBuildRunEntrypoints and CreateRunEntrypointConfiguration + // run the entrypoint the current file holds (title_run_entrypoints.go). + PlanBuildRunEntrypoints(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildPlanRequest) (core.BuildPlan, error) + DecodeBuildRunEntrypoints(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildDecodeRunEntrypointsRequest) ([]core.BuildRunEntrypoint, error) + CreateRunEntrypointConfiguration(ctx context.Context, request core.RunEntrypointConfigurationRequest) (string, []core.RunConfigChange, error) ToolchainRegistryOf(ctx context.Context, manifests []json.RawMessage) (core.ToolchainRegistry, error) // CommandInstallerRequirements, PlanCommandInstaller and CommandInstallerDefaultDirectory // read a plugin's commandInstallers[]: which systemCommand launches name which commands, diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index cdb5f30a46..655df9746a 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -1770,11 +1770,16 @@ func (a *App) runBuildTargetWith(p *project, op *buildOperation, instance *build a.finishBuildError(p, op, errors.New(a.text.Build.ProjectMissing)) return } - target, ok := buildTargetByID(instance.Model, targetID) - if !ok { - a.notifyError(a.text.Build.TargetMissing) - a.finishBuildError(p, op, errors.New(a.text.Build.TargetMissing)) - return + // An entrypoint run names no target: it starts launchOptions.entrypoint in the project. + var selectedTarget *core.BuildSelection + if targetID != "" { + target, ok := buildTargetByID(instance.Model, targetID) + if !ok { + a.notifyError(a.text.Build.TargetMissing) + a.finishBuildError(p, op, errors.New(a.text.Build.TargetMissing)) + return + } + selectedTarget = &core.BuildSelection{Name: target.Name, Path: target.Path, Tags: target.Tags, Properties: target.Properties} } captured := *instance kernel := a.kernel @@ -1790,7 +1795,7 @@ func (a *App) runBuildTargetWith(p *project, op *buildOperation, instance *build WorkspaceRoot: p.root, Run: runID, Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties}, - Target: &core.BuildSelection{Name: target.Name, Path: target.Path, Tags: target.Tags, Properties: target.Properties}, + Target: selectedTarget, LaunchOptions: options, } a.addBuildToolHint(prepare, p, captured, &request) diff --git a/desktop/internal/workbench/runconfig.go b/desktop/internal/workbench/runconfig.go index ba1c4a3a41..faffadf444 100644 --- a/desktop/internal/workbench/runconfig.go +++ b/desktop/internal/workbench/runconfig.go @@ -53,6 +53,9 @@ type runConfigState struct { // start is the configuration a save asked to run, started once the next refresh lists it // so the run reads what was saved. start string + // findingEntrypoint says Run on Current File is asking the build providers for the open + // file's entrypoint (title_run_entrypoints.go), so another press does not ask again. + findingEntrypoint bool // browser is the list that shows the configurations by scope and build system. browser runConfigBrowser // currentFile says the user chose Current File in the title bar, so its Run and Debug act diff --git a/desktop/internal/workbench/tests_provider_test.go b/desktop/internal/workbench/tests_provider_test.go index bc08954749..79780090db 100644 --- a/desktop/internal/workbench/tests_provider_test.go +++ b/desktop/internal/workbench/tests_provider_test.go @@ -69,6 +69,10 @@ func TestProviderTestRunner(t *testing.T) { // discovered tests (build_tests_test.go). _, statErr := os.Stat("discovery.marker") discovery := statErr == nil + // entrypoints.marker selects the entrypoint fixture (title_run_entrypoints_test.go): the + // provider negotiates litheBuild 1 and finds an entrypoint in src/Main.java only. + _, statErr = os.Stat("entrypoints.marker") + entrypoints := statErr == nil reader := bufio.NewReader(os.Stdin) write := func(value any) { body, err := json.Marshal(value) @@ -132,6 +136,9 @@ func TestProviderTestRunner(t *testing.T) { switch request.Method { case "initialize": experimental := map[string]any{"litheBuild": map[string]any{"version": 0}} + if entrypoints { + experimental["litheBuild"] = map[string]any{"version": 1} + } if _, err := os.Stat("settings-action.marker"); err == nil { experimental["litheFunctions"] = map[string]any{"version": 0, "functions": []any{map[string]any{"id": "snapshot.refresh"}}} } @@ -218,7 +225,31 @@ func TestProviderTestRunner(t *testing.T) { }, }, }) + case "lithe/build/runEntrypoints": + var params struct { + File string `json:"file"` + } + if err := json.Unmarshal(request.Params, ¶ms); err != nil { + os.Exit(11) + } + found := []any{} + if params.File == "src/Main.java" { + found = append(found, map[string]any{"run": "main", "name": "Main", "entrypoint": "example.Main", "project": map[string]any{"name": "fixture", "path": "."}}) + } + reply(request.ID, map[string]any{"format": "litheRunEntrypoints", "version": 0, "entrypoints": found}) case "lithe/build/prepareRun": + if entrypoints { + if err := os.WriteFile("prepare-run.json", request.Params, 0o600); err != nil { + os.Exit(9) + } + reply(request.ID, map[string]any{ + "executable": map[string]any{"kind": "command", "value": "fixture-service"}, + "arguments": []string{"-test.run=^TestFixtureEntrypointRunner$"}, + "workingDirectory": ".", + "environment": map[string]string{fixtureEntrypointVariable: "1"}, + }) + continue + } // service.marker selects the service fixture (build_connection_debug_test.go): the // provider records what the host asked for and answers with a process that listens // on the debug port the host chose, as a runtime suspended for a debugger does. diff --git a/desktop/internal/workbench/title_run.go b/desktop/internal/workbench/title_run.go index 59c933c1b8..59672bfd5b 100644 --- a/desktop/internal/workbench/title_run.go +++ b/desktop/internal/workbench/title_run.go @@ -289,11 +289,12 @@ func (p *project) titleConfigurationFacts(index int, reference core.RunProviderR } // performCurrentFileAction is Run or Debug on Current File. The Debug window starts the open -// file under its selected adapter; nothing runs the current file outside a configuration. +// file under its selected adapter; Run starts the entrypoint a build provider finds in the +// open file (runCurrentFileEntrypoint). func (a *App) performCurrentFileAction(p *project, action titleAction) { if action == titleActionDebug { a.whenDebugAdaptersLoaded(p, func() { a.startDebug(p) }) return } - a.notifyInfo(i18n.Shared(a.language(), "desktop.title.currentFileNotRunnable")) + a.runCurrentFileEntrypoint(p) } diff --git a/desktop/internal/workbench/title_run_entrypoints.go b/desktop/internal/workbench/title_run_entrypoints.go new file mode 100644 index 0000000000..e11863eec2 --- /dev/null +++ b/desktop/internal/workbench/title_run_entrypoints.go @@ -0,0 +1,214 @@ +package workbench + +import ( + "context" + "errors" + "path" + "path/filepath" + "slices" + "strings" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" +) + +// Run on Current File starts the entrypoint a build provider finds in the open file, such as a +// Java class with a main method that no build file names (#2104). A build system that declares +// a run with entrypoints (buildProviders 1) answers lithe/build/runEntrypoints for a file; Core +// plans the request and checks the answer. The first entrypoint is saved as a local run +// configuration named after it, selected in the title bar and started like any provider run, +// so the user edits its arguments and runs it again from the run configuration menu. Saving +// the same entrypoint again reuses the saved configuration. + +// entrypointCandidate is one detected instance that may find an entrypoint in the file. +type entrypointCandidate struct { + index int + instance buildInstance +} + +// entrypointFound is the entrypoint a candidate found, with the model project it starts in. +type entrypointFound struct { + instance buildInstance + entry core.BuildRunEntrypoint + project core.BuildProject +} + +// runCurrentFileEntrypoint asks the build providers whose instance holds the open file for its +// entrypoints, innermost instance first, and runs the first one found. An instance's model is +// loaded first, since the configuration names the model's project; a press waits for it as a +// press on a configuration does. +func (a *App) runCurrentFileEntrypoint(p *project) { + s := &p.runConfigs + if s.findingEntrypoint { + return + } + doc := p.selectedDocument(p.docs.group) + if doc == nil || doc.path == "" { + a.notifyInfo(i18n.Shared(a.language(), "desktop.title.currentFileNotRunnable")) + return + } + relative, err := filepath.Rel(p.root, doc.path) + if err != nil || relative == "." || strings.HasPrefix(relative, "..") { + a.notifyInfo(i18n.Shared(a.language(), "desktop.title.currentFileNotRunnable")) + return + } + file := filepath.ToSlash(relative) + if !p.build.loaded { + s.pending = titleActionRun + a.loadBuildSystems(p) + return + } + candidates := entrypointCandidates(p.build.instances, file) + for _, candidate := range candidates { + instance := &p.build.instances[candidate.index] + if instance.modelLoading || (!instance.modelLoaded && instance.modelError == "") { + s.pending = titleActionRun + if !instance.modelLoading { + a.loadBuildModel(p, candidate.index) + } + return + } + } + candidates = slices.DeleteFunc(candidates, func(c entrypointCandidate) bool { return !c.instance.modelLoaded }) + if len(candidates) == 0 { + a.notifyInfo(i18n.Shared(a.language(), "desktop.title.currentFileNotRunnable")) + return + } + a.performed("title.run.currentFile", surfaceToolbar) + s.findingEntrypoint = true + kernel := a.kernel + a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { + found, err := a.findEntrypoint(ctx, p, kernel, candidates, file) + if err == nil && found != nil { + var id string + id, err = a.saveEntrypointConfiguration(ctx, p, kernel, *found) + return func(a *App) { a.startEntrypointConfiguration(p, id, err) } + } + return func(a *App) { + p.runConfigs.findingEntrypoint = false + if err != nil { + a.operationFailed("title_run_current_file", err) + a.notifyError(err.Error()) + return + } + a.operationRejected("title_run_current_file", "no_entrypoint") + a.notifyInfo(i18n.Shared(a.language(), "desktop.title.currentFileNotRunnable")) + } + }) +} + +// entrypointCandidates are the instances that declare an entrypoint run and whose root holds +// file, the innermost root first. +func entrypointCandidates(instances []buildInstance, file string) []entrypointCandidate { + var candidates []entrypointCandidate + for index := range instances { + instance := instances[index] + if len(instance.System.EntrypointRuns) == 0 || !instance.System.Provider { + continue + } + root := path.Clean(instance.Root) + if root != "." && file != root && !strings.HasPrefix(file, root+"/") { + continue + } + candidates = append(candidates, entrypointCandidate{index: index, instance: instance}) + } + slices.SortStableFunc(candidates, func(left, right entrypointCandidate) int { + return len(path.Clean(right.instance.Root)) - len(path.Clean(left.instance.Root)) + }) + return candidates +} + +// findEntrypoint asks each candidate in turn and returns the first entrypoint whose project the +// candidate's model lists. A candidate that fails does not stop the others; its error is +// returned only when no candidate found anything. +func (a *App) findEntrypoint(ctx context.Context, p *project, kernel Kernel, candidates []entrypointCandidate, file string) (*entrypointFound, error) { + var failures []error + for _, candidate := range candidates { + entries, err := a.runEntrypoints(ctx, p, kernel, candidate.instance, file) + if err != nil { + failures = append(failures, err) + continue + } + for _, entry := range entries { + if project, ok := buildProjectByPath(candidate.instance.Model, entry.Project.Path); ok { + return &entrypointFound{instance: candidate.instance, entry: entry, project: project}, nil + } + } + } + return nil, errors.Join(failures...) +} + +// runEntrypoints plans, sends and decodes one instance's lithe/build/runEntrypoints request. +func (a *App) runEntrypoints(ctx context.Context, p *project, kernel Kernel, instance buildInstance, file string) ([]core.BuildRunEntrypoint, error) { + request := core.BuildPlanRequest{Root: instance.Root, Options: instance.Options, PluginDirectory: instance.PackageDirectory, WorkspaceRoot: p.root, File: file} + plan, err := kernel.PlanBuildRunEntrypoints(ctx, instance.Manifest, instance.BuildSystemID, request) + if err != nil { + return nil, err + } + if plan.Provider == nil { + return nil, errors.New("the build system answered with a command plan") + } + client, err := a.buildProvider(ctx, p, instance) + if err != nil { + return nil, err + } + operation, err := client.Execute(ctx, plan.Provider.Method, plan.Provider.Params, int(buildRequestTimeout/time.Millisecond)) + if err != nil { + return nil, err + } + result, err := operation.Wait(ctx) + if err != nil { + return nil, err + } + return kernel.DecodeBuildRunEntrypoints(ctx, instance.Manifest, instance.BuildSystemID, core.BuildDecodeRunEntrypointsRequest{ + Root: instance.Root, Options: instance.Options, PluginDirectory: instance.PackageDirectory, Result: result, + }) +} + +// saveEntrypointConfiguration has Core save the local configuration that starts found and +// writes it, returning its ID. +func (a *App) saveEntrypointConfiguration(ctx context.Context, p *project, kernel Kernel, found entrypointFound) (string, error) { + reference := core.RunProviderReference{ + PluginID: found.instance.PluginID, BuildSystemID: found.instance.BuildSystemID, Root: found.instance.Root, + Run: found.entry.Run, ProjectID: found.project.ID, Execution: "application", UserArguments: []string{}, + } + id, changes, err := kernel.CreateRunEntrypointConfiguration(ctx, core.RunEntrypointConfigurationRequest{ + Root: p.root, Name: found.entry.Name, Build: reference, Entrypoint: found.entry.Entrypoint, + Plugins: a.runConfigPlugins(ctx), + }) + if err != nil { + return "", err + } + if err := applyRunConfigChanges(ctx, p.root, changes); err != nil { + return "", err + } + return id, nil +} + +// startEntrypointConfiguration makes the saved configuration what the title bar runs and starts +// it once the configurations are read again. +func (a *App) startEntrypointConfiguration(p *project, id string, err error) { + s := &p.runConfigs + s.findingEntrypoint = false + if err != nil { + a.operationFailed("title_run_current_file", err) + a.notifyError(err.Error()) + return + } + s.currentFile = false + s.reveal, s.start = id, id + a.refreshRunConfigurations(p) +} + +// buildProjectByPath is the model project at the instance-relative path, as Core names an +// entrypoint's project. +func buildProjectByPath(model core.BuildModel, projectPath string) (core.BuildProject, bool) { + want := path.Clean(projectPath) + for _, project := range model.Projects { + if path.Clean(project.Path) == want { + return project, true + } + } + return core.BuildProject{}, false +} diff --git a/desktop/internal/workbench/title_run_entrypoints_test.go b/desktop/internal/workbench/title_run_entrypoints_test.go new file mode 100644 index 0000000000..e2ad9a2056 --- /dev/null +++ b/desktop/internal/workbench/title_run_entrypoints_test.go @@ -0,0 +1,200 @@ +package workbench + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + "runtime" + "slices" + "strings" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginstate" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" +) + +// fixtureEntrypointVariable tells the copied test binary it is the entrypoint a provider run +// started (TestFixtureEntrypointRunner). +const fixtureEntrypointVariable = "LITHE_FIXTURE_ENTRYPOINT" + +// TestFixtureEntrypointRunner is the program the entrypoint fixture's prepared run starts: it +// prints the arguments it got and exits. +func TestFixtureEntrypointRunner(t *testing.T) { + if os.Getenv(fixtureEntrypointVariable) == "" { + t.Skip("not a fixture entrypoint run") + } + fmt.Println("entrypoint ran") + os.Exit(0) +} + +// providerEntrypointsManifest is the provider fixture with an entrypoint run (buildProviders 1). +var providerEntrypointsManifest = strings.Replace(strings.Replace(providerTestsManifest, + `"requires": {"buildProviders": 0,`, `"requires": {"buildProviders": 1,`, 1), + `"model": {"source": "provider"},`, + `"model": {"source": "provider"}, + "run": [{"id": "main", "source": "provider", "name": "Main Class", "entrypoints": true}],`, 1) + +// entrypointHarness installs the entrypoint provider fixture and puts the fixture build tool +// and the copied test binary, as fixture-service, on PATH. +func entrypointHarness(t *testing.T) *harness { + t.Helper() + return newHarnessWithOptions(t, entrypointOptions(t, "dark", "zh-Hans")) +} + +// entrypointOptions are entrypointHarness's options in theme and language. +func entrypointOptions(t *testing.T, theme, language string) Options { + t.Helper() + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, settingsFile), []byte(`{"theme":"`+theme+`"}`), 0o600); err != nil { + t.Fatal(err) + } + preferences := store.At(dir) + pluginRoot := t.TempDir() + installed := filepath.Join(pluginRoot, "dev.lithe.test.provider-tests", "1.0.0") + if err := os.MkdirAll(installed, 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(installed, "plugin.json"), []byte(providerEntrypointsManifest), 0o600); err != nil { + t.Fatal(err) + } + copyTestBinary(t, filepath.Join(installed, "provider")) + if err := pluginstate.New(preferences).SetEnabled("dev.lithe.test.provider-tests", true); err != nil { + t.Fatal(err) + } + bin := t.TempDir() + tool, program := filepath.Join(bin, "fixture-tool"), filepath.Join(bin, "fixture-service") + if runtime.GOOS == "windows" { + tool, program = tool+".exe", program+".exe" + t.Setenv("PATHEXT", ".EXE") + } + if err := writeFakeExecutable(tool); err != nil { + t.Fatal(err) + } + copyTestBinary(t, program) + t.Setenv("PATH", bin+string(filepath.ListSeparator)+os.Getenv("PATH")) + return Options{ + Kernel: &testKernel{Client: core.NewClient()}, + PluginKernel: &testKernel{Client: core.NewClient()}, + PluginRoot: pluginRoot, + Store: preferences, + Languages: []string{language}, + // The provider is a copy of this large instrumented test binary: under load its start + // can exceed Core's 10s default. The bound stays finite. + PluginInitializeTimeout: 60 * time.Second, + } +} + +// entrypointWorkspace is the fixture workspace: src/Main.java holds the entrypoint the +// provider finds, src/Util.java none. +func entrypointWorkspace(t *testing.T) string { + t.Helper() + root := filepath.Join(t.TempDir(), "EntrypointDemo") + if err := os.MkdirAll(filepath.Join(root, "src"), 0o700); err != nil { + t.Fatal(err) + } + for _, marker := range []string{"fixture.marker", "entrypoints.marker"} { + if err := os.WriteFile(filepath.Join(root, marker), []byte("fixture\n"), 0o600); err != nil { + t.Fatal(err) + } + } + sources := map[string]string{ + "Main.java": "package example;\n\npublic final class Main {\n public static void main(String[] args) {\n System.out.println(\"entrypoint ran\");\n }\n}\n", + "Util.java": "package example;\n\nfinal class Util {\n}\n", + } + for name, text := range sources { + if err := os.WriteFile(filepath.Join(root, "src", name), []byte(text), 0o600); err != nil { + t.Fatal(err) + } + } + return root +} + +// Run on Current File asks the build provider for the open file's entrypoint, saves it as a +// local run configuration named after it, selects it in the title bar and starts it without a +// target, with the entrypoint as launchOptions.entrypoint. A file without an entrypoint says +// so, and running the entrypoint again reuses the saved configuration. +func TestRunOnCurrentFileStartsTheEntrypointAndSavesItsConfiguration(t *testing.T) { + h := entrypointHarness(t) + root := entrypointWorkspace(t) + h.open(root) + p := h.app.project + h.app.post(func(a *App) { a.loadTitleRunConfigs(p) }) + awaitStateWithin(t, h, time.Minute, "the provider model", func() bool { + return len(p.build.instances) == 1 && p.build.instances[0].modelLoaded && p.runConfigsSettled() + }) + if runs := p.build.instances[0].System.EntrypointRuns; len(runs) != 1 || runs[0].ID != "main" { + t.Fatalf("entrypoint runs = %+v, want the declared main run", runs) + } + if len(p.runConfigs.list) != 0 { + t.Fatalf("configurations = %+v, want none before a run: an entrypoint run lists nothing by itself", p.runConfigs.list) + } + + notRunnable := i18n.Shared(h.app.language(), "desktop.title.currentFileNotRunnable") + openSource(t, h, p, filepath.Join(root, "src", "Util.java")) + h.app.post(func(a *App) { + a.chooseTitleConfiguration(p, "") + a.titleRun(p) + }) + awaitStateWithin(t, h, time.Minute, "the answer for a file without an entrypoint", func() bool { + return slices.Contains(noticeTexts(h.app), notRunnable) + }) + if len(p.runConfigs.list) != 0 || p.build.active() { + t.Fatalf("a file without an entrypoint saved %+v or started a run", p.runConfigs.list) + } + + openSource(t, h, p, filepath.Join(root, "src", "Main.java")) + h.app.post(func(a *App) { a.titleRun(p) }) + first := awaitProcessRun(t, h, p, "Main", nil) + if !strings.Contains(first.output.all(), "entrypoint ran") { + t.Fatalf("console:\n%s", first.output.all()) + } + if len(p.runConfigs.list) != 1 || p.runConfigs.currentFile || p.runConfigs.selected != p.runConfigs.list[0].ID { + t.Fatalf("configurations = %+v selected %q current file %v, want the saved Main chosen", p.runConfigs.list, p.runConfigs.selected, p.runConfigs.currentFile) + } + saved := p.runConfigs.list[0] + reference, ok := saved.BuildReference() + if !ok || reference.Run != "main" || reference.TargetID != "" || saved.Name != "Main" { + t.Fatalf("saved configuration = %+v reference %+v", saved, reference) + } + data, err := os.ReadFile(filepath.Join(root, "prepare-run.json")) + if err != nil { + t.Fatal(err) + } + var prepared struct { + Target json.RawMessage `json:"target"` + LaunchOptions struct { + Entrypoint string `json:"entrypoint"` + } `json:"launchOptions"` + } + if err := json.Unmarshal(data, &prepared); err != nil { + t.Fatal(err) + } + if prepared.LaunchOptions.Entrypoint != "example.Main" || (len(prepared.Target) != 0 && string(prepared.Target) != "null") { + t.Fatalf("prepareRun params = %s, want the entrypoint and no target", data) + } + + // Current File again finds the same entrypoint and reuses its configuration. + h.app.post(func(a *App) { + a.chooseTitleConfiguration(p, "") + a.titleRun(p) + }) + awaitProcessRun(t, h, p, "Main", first) + if len(p.runConfigs.list) != 1 || p.runConfigs.list[0].ID != saved.ID { + t.Fatalf("configurations = %+v, want the one saved Main", p.runConfigs.list) + } +} + +// openSource opens file in the editor and waits until it is the selected document, which Run +// on Current File reads. +func openSource(t *testing.T, h *harness, p *project, file string) { + t.Helper() + h.app.post(func(a *App) { a.openFileAtPosition(p, file, 0, 0) }) + awaitStateWithin(t, h, 10*time.Second, "the open "+filepath.Base(file), func() bool { + doc := p.selectedDocument(p.docs.group) + return doc != nil && doc.path == file + }) +} diff --git a/desktop/internal/workbench/title_run_entrypoints_visual_test.go b/desktop/internal/workbench/title_run_entrypoints_visual_test.go new file mode 100644 index 0000000000..62249c98ea --- /dev/null +++ b/desktop/internal/workbench/title_run_entrypoints_visual_test.go @@ -0,0 +1,66 @@ +//go:build vivahead && lithevisual + +package workbench + +import ( + "os" + "path/filepath" + "testing" + "time" + + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/headless" +) + +// TestVisualRunOnCurrentFile captures Run on Current File: the Run window after Main.java's +// main class ran, with the saved Main configuration chosen in the title bar, and the run +// configuration menu that lists it. It needs only LITHE_VISUAL_OUTPUT_DIR; the dark captures +// are in Chinese and the light ones in English. +func TestVisualRunOnCurrentFile(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + for _, look := range []struct{ theme, language string }{{"dark", "zh-Hans"}, {"light", "en-US"}} { + theme, language := look.theme, look.language + t.Run(theme, func(t *testing.T) { + options := entrypointOptions(t, theme, language) + root := entrypointWorkspace(t) + var session *headless.Session + h := newHarnessWithDriver(t, options, func(config app.Config) (*app.Driver, func(), error) { + config.Width, config.Height = 1200, 820 + var err error + session, err = headless.Open(config, nil, headless.Options{}) + if err != nil { + return nil, nil, err + } + return session.Driver(), session.Close, nil + }) + shot := func(scene string) { + t.Helper() + h.settleChain() + if err := session.Screenshot(filepath.Join(out, "run-current-file-"+scene+"-"+theme+".png")); err != nil { + t.Fatal(err) + } + } + h.open(root) + p := h.app.project + h.app.post(func(a *App) { a.loadTitleRunConfigs(p) }) + awaitStateWithin(t, h, time.Minute, "the provider model", func() bool { + return len(p.build.instances) == 1 && p.build.instances[0].modelLoaded && p.runConfigsSettled() + }) + openSource(t, h, p, filepath.Join(root, "src", "Main.java")) + h.app.post(func(a *App) { + a.chooseTitleConfiguration(p, "") + a.titleRun(p) + }) + awaitProcessRun(t, h, p, "Main", nil) + shot("run") + h.app.post(func(a *App) { a.openRunConfigMenu() }) + shot("menu") + }) + } +} diff --git a/docs/assets/run-current-file/run-current-file-menu-dark.png b/docs/assets/run-current-file/run-current-file-menu-dark.png new file mode 100644 index 0000000000..3eaa0962f6 Binary files /dev/null and b/docs/assets/run-current-file/run-current-file-menu-dark.png differ diff --git a/docs/assets/run-current-file/run-current-file-menu-light.png b/docs/assets/run-current-file/run-current-file-menu-light.png new file mode 100644 index 0000000000..adf0bf46b5 Binary files /dev/null and b/docs/assets/run-current-file/run-current-file-menu-light.png differ diff --git a/docs/assets/run-current-file/run-current-file-run-dark.png b/docs/assets/run-current-file/run-current-file-run-dark.png new file mode 100644 index 0000000000..1ee680d64d Binary files /dev/null and b/docs/assets/run-current-file/run-current-file-run-dark.png differ diff --git a/docs/assets/run-current-file/run-current-file-run-light.png b/docs/assets/run-current-file/run-current-file-run-light.png new file mode 100644 index 0000000000..0944c8d776 Binary files /dev/null and b/docs/assets/run-current-file/run-current-file-run-light.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 2961ea96b4..67bac14277 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -27,7 +27,11 @@ native_path() { fi } -# Lithe-core-rust main at bb4832e, #88 squash-merged (on top of 4ed7a1f, #85): a run +# Lithe-core-rust main at d833d6a, #89 squash-merged (on top of bb4832e, #88): buildProviders 1 +# adds runs with entrypoints: true; build.runEntrypointsPlan and build.decodeRunEntrypoints ask a +# provider for the entrypoints of one source file, prepareRunPlan takes an entrypoint run without a +# target, and runConfig.createUserConfiguration saves the entrypoint as part of the entry (#2104). +# #88, squash-merged into main as bb4832e (on top of 4ed7a1f, #85): a run # configuration's beforeLaunch names built-in process runs that start first; runConfig.beforeLaunch # expands and checks them and fingerprints the lists a project file names, the editor form has a # beforeLaunch field and runConfig.updateOptions takes the list (#1616). #85, squash-merged into @@ -210,7 +214,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # the contract, plugin guides, reference and SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), # #15 (git.write cherryPick, revert and reset fields), #14 (word-level changed ranges of diff # rows), #13, #8, #7, #6 and #4. -PINNED_CORE_REVISION="bb4832ee73187c8dffcbd67eb4a68e839869252b" +PINNED_CORE_REVISION="d833d6a71dfeaa5eda39d23f6a3a1a9ee29ff9ed" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 91686447a8..c4ff734a8f 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -11278,7 +11278,7 @@ "desktop.plugins.commandInstallToolMissing": "{tool} not found. Install it first, or set where it is in Settings > Build, Execution, Deployment > Toolchains.", "desktop.plugins.commandInstallError": "Could not install: {reason}", "desktop.title.configurationNotStartable": "{name} cannot be started: no build plugin runs it.", - "desktop.title.currentFileNotRunnable": "The current file cannot run on its own. Choose a project run configuration from the run configuration menu.", + "desktop.title.currentFileNotRunnable": "The current file has no entrypoint to run, such as a class with a main method. Open such a file, or choose a run configuration from the run configuration menu.", "desktop.title.hiddenRunConfigurations": "{count} saved configurations hidden (not runnable)", "desktop.title.nothingToEdit": "This project has no run configurations to edit. Build plugins create them from the project model, and none of the enabled build plugins declares a runnable entry for this project.", "desktop.title.nothingToEditHidden": "This project has no run configurations to edit. Build plugins create them from the project model, and none of the enabled build plugins declares a runnable entry for this project. {count} saved run configurations are hidden because no build plugin runs them, for example entries an earlier version of Lithe saved in .lithe/run.", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 3d33b07d24..79f0d56398 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -11278,7 +11278,7 @@ "desktop.plugins.commandInstallToolMissing": "未找到 {tool}。请先安装它,或在 设置 > 构建、执行、部署 > 工具链 中指定它的位置。", "desktop.plugins.commandInstallError": "无法安装:{reason}", "desktop.title.configurationNotStartable": "无法启动 {name}:没有构建插件负责运行它。", - "desktop.title.currentFileNotRunnable": "当前文件不能单独运行。请在运行配置菜单里选择一个项目运行配置。", + "desktop.title.currentFileNotRunnable": "当前文件没有可运行的入口(例如带 main 方法的类)。请打开这样的文件,或在运行配置菜单里选择一个运行配置。", "desktop.title.hiddenRunConfigurations": "已隐藏 {count} 条无法运行的已保存配置", "desktop.title.nothingToEdit": "这个项目没有可编辑的运行配置。运行配置由构建插件根据项目模型生成,当前启用的构建插件没有为这个项目声明可运行的入口。", "desktop.title.nothingToEditHidden": "这个项目没有可编辑的运行配置。运行配置由构建插件根据项目模型生成,当前启用的构建插件没有为这个项目声明可运行的入口。另有 {count} 条保存的运行配置没有构建插件负责运行,已隐藏,例如旧版 Lithe 保存在 .lithe/run 中的配置。", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index 46abc76ee6..8d417679e4 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -19294,7 +19294,7 @@ }, { "id": "desktop.title.currentFileNotRunnable", - "description": "Desktop title bar: Run pressed while Current File is chosen; nothing runs a file outside a run configuration", + "description": "Desktop title bar: Run pressed while Current File is chosen, but no file is open or no build plugin finds an entrypoint (such as a class with a main method) in the open file", "platforms": [ "desktop" ] diff --git a/shared/platform-feature-matrix/features/run-current-file-entrypoint.json b/shared/platform-feature-matrix/features/run-current-file-entrypoint.json new file mode 100644 index 0000000000..a86108423b --- /dev/null +++ b/shared/platform-feature-matrix/features/run-current-file-entrypoint.json @@ -0,0 +1,29 @@ +{ + "id": "run-current-file-entrypoint", + "area": "运行与调试", + "group": "运行配置", + "capability": "标题栏选“当前文件”后点运行:构建插件(buildProviders 1 的入口运行)找出当前打开文件里的运行入口,例如没有在构建文件里写明主类、但带 main 方法的 Java 类,宿主把它保存为本机运行配置(名称取类名,引用不指向构建目标,入口存为 extensions.build-run.entrypoint),在标题栏选中并运行;之后这条配置出现在运行配置下拉里,可以像其他构建提供者运行一样编辑参数、环境变量和工作目录;同一入口再次运行复用已保存的配置;文件里没有入口时提示原因", + "owner": "Run", + "notes": "Viva 共享实现。入口由插件按文件回答(lithe/build/runEntrypoints),Core 规划请求并校验答案;宿主不按语言或插件分支。一个文件有多个入口时运行第一个。本轮只支持运行,入口运行的调试以后再做。Maven 插件提供 main 类入口(测试源码除外)。", + "verification": "在一个没有配置主类的 Maven 模块里打开带 public static void main 的类,标题栏选“当前文件”点运行:Maven 编译模块后运行该类,运行窗口出现输出,标题栏下拉出现以类名命名的配置并已选中;修改该配置的程序参数后再次运行生效;打开没有 main 方法的类再点运行,提示当前文件没有可运行的入口。自动化:title_run_entrypoints_test.go 的 TestRunOnCurrentFileStartsTheEntrypointAndSavesItsConfiguration(合成构建提供者)。", + "macos": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/title_run_entrypoints.go", + "desktop/internal/core/build_entrypoints.go", + "desktop/internal/pluginservice/builds.go", + "desktop/internal/workbench/title_run_entrypoints_test.go" + ] + }, + "windows": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/title_run_entrypoints.go", + "desktop/internal/core/build_entrypoints.go", + "desktop/internal/pluginservice/builds.go", + "desktop/internal/workbench/title_run_entrypoints_test.go" + ] + } +} diff --git a/shared/platform-feature-matrix/features/viva-title-run-debug.json b/shared/platform-feature-matrix/features/viva-title-run-debug.json index a384c10d5e..ea1f63035d 100644 --- a/shared/platform-feature-matrix/features/viva-title-run-debug.json +++ b/shared/platform-feature-matrix/features/viva-title-run-debug.json @@ -48,6 +48,6 @@ ] }, "owner": "Run", - "verification": "打开带构建提供者的项目(测试内联的合成 Build Provider 即可):标题栏下拉列出检测到的运行配置并记住所选项;运行按钮启动所选配置并打开运行窗口;调试按钮对声明了调试适配器的运行准备并启动调试会话、打开调试窗口,未声明时提示该配置不能调试;声明了公共调试类型的服务运行(合成提供者 + 另一个合成插件的 attach 适配器),调试时提供者收到 `launchOptions.debug`(选中的适配器、类型、本机端口),服务监听后适配器以 attach 连接该端口,在调试窗口停止后服务结束、端口释放;没有或有两个匹配适配器时提示原因且不请求提供者;停用、再启用适配器所在插件后,调试适配器列表随之更新;运行超过准备时限的服务不会被结束(测试把时限缩短到 5 秒);语言服务器就绪后才声明命令时,宿主等到声明再请求端口,从不声明时在时限内结束;准备失败时结束“准备中”并显示原因;选择“当前文件”时提示需要运行配置;项目没有运行配置时点“编辑运行配置…”提示原因,有旧版或其他提供方的已保存配置时说明隐藏了几条。提供者运行准备失败时,运行控制台显示提供者输出的构建日志;未声明名称的运行,配置名就是目标名。单元测试覆盖等待配置读出后运行、没有配置时编辑入口的提示和隐藏条数、当前文件提示、无适配器提示、不经构建提供者启动的配置提示、提供者准备请求、按名称选择适配器和拒绝插件未安装的适配器、准备运行时转发提供者输出、未命名运行按目标命名,声明提供者进程但用命令读取模型和写文件的依赖命令,以及按配置类型连接调试服务运行(选择、拒绝、停止联动)。", - "notes": "Viva 标题栏按钮此前只有外观。运行忙碌时仅提示,不排队;当前文件运行尚未实现,只提示需要配置;同包适配器的提供者调试暂不携带运行配置的启动选项;按配置类型连接的服务运行调试一个项目同时只有一个调试会话。macOS、Windows 原生窗口验收 pending。" + "verification": "打开带构建提供者的项目(测试内联的合成 Build Provider 即可):标题栏下拉列出检测到的运行配置并记住所选项;运行按钮启动所选配置并打开运行窗口;调试按钮对声明了调试适配器的运行准备并启动调试会话、打开调试窗口,未声明时提示该配置不能调试;声明了公共调试类型的服务运行(合成提供者 + 另一个合成插件的 attach 适配器),调试时提供者收到 `launchOptions.debug`(选中的适配器、类型、本机端口),服务监听后适配器以 attach 连接该端口,在调试窗口停止后服务结束、端口释放;没有或有两个匹配适配器时提示原因且不请求提供者;停用、再启用适配器所在插件后,调试适配器列表随之更新;运行超过准备时限的服务不会被结束(测试把时限缩短到 5 秒);语言服务器就绪后才声明命令时,宿主等到声明再请求端口,从不声明时在时限内结束;准备失败时结束“准备中”并显示原因;当前文件没有可运行的入口时提示原因(有入口时的运行见 run-current-file-entrypoint);项目没有运行配置时点“编辑运行配置…”提示原因,有旧版或其他提供方的已保存配置时说明隐藏了几条。提供者运行准备失败时,运行控制台显示提供者输出的构建日志;未声明名称的运行,配置名就是目标名。单元测试覆盖等待配置读出后运行、没有配置时编辑入口的提示和隐藏条数、当前文件提示、无适配器提示、不经构建提供者启动的配置提示、提供者准备请求、按名称选择适配器和拒绝插件未安装的适配器、准备运行时转发提供者输出、未命名运行按目标命名,声明提供者进程但用命令读取模型和写文件的依赖命令,以及按配置类型连接调试服务运行(选择、拒绝、停止联动)。", + "notes": "Viva 标题栏按钮此前只有外观。运行忙碌时仅提示,不排队;当前文件运行由构建插件按文件找出入口(run-current-file-entrypoint);同包适配器的提供者调试暂不携带运行配置的启动选项;按配置类型连接的服务运行调试一个项目同时只有一个调试会话。macOS、Windows 原生窗口验收 pending。" }