Skip to content

Commit bb4832e

Browse files
1lckclaude
andauthored
feat(run-config): 运行配置的启动前步骤 (#88)
运行配置新增 beforeLaunch,引用内置进程运行,按顺序在配置启动前运行。 Core 展开嵌套步骤、校验引用并对项目文件列出的步骤给出确认指纹; 编辑器表单新增 beforeLaunch 字段,updateOptions 可修改步骤列表。 Refs 1lck/Lithe-IDEA#1616 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4ed7a1f commit bb4832e

15 files changed

Lines changed: 825 additions & 8 deletions

File tree

‎rust/contracts/run-configuration-v2.schema.json‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@
211211
"propertyNames": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
212212
"additionalProperties": { "type": "object" }
213213
},
214+
"beforeLaunch": {
215+
"type": "array",
216+
"maxItems": 16,
217+
"description": "Built-in process runs started in order before this one; each must exit with 0 first. A layer replaces the whole list.",
218+
"items": {
219+
"type": "object",
220+
"required": ["configuration"],
221+
"properties": {
222+
"configuration": { "type": "string", "minLength": 1, "maxLength": 256 }
223+
},
224+
"additionalProperties": false
225+
}
226+
},
214227
"disabled": { "type": "boolean" },
215228
"source": { "type": "string" }
216229
},

‎rust/contracts/rust-core-api.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ or removing a command fails until the table changes in the same commit.
715715
| `runConfig.editorForm` | Describe the editor fields and current values of a built-in run configuration |
716716
| `runConfig.saveConfiguration` | Validate an editor form's values and return field errors or the file changes that save it |
717717
| `runConfig.deleteConfiguration` | Return the file changes that delete a saved user configuration |
718+
| `runConfig.beforeLaunch` | Expand the built-in process runs a configuration starts first, and say whether the user must confirm them |
718719
| `runConfig.createLaunchPlan` | Project one effective configuration into a platform-neutral Run or Debug plan |
719720
| `runConfig.providerLaunchInputs` | Resolve user choices for a provider-owned launch |
720721
| `git.status` | Resolve the repository, current branch, and working-tree changes |
@@ -3885,6 +3886,57 @@ extension namespaces the editor does not show are kept.
38853886
returns `{changes}` that remove the saved `user:` configuration from every layer.
38863887
Generated entries cannot be deleted.
38873888

3889+
#### Steps before launch
3890+
3891+
A configuration of any provider may name `beforeLaunch`, an ordered list of at
3892+
most 16 `{configuration}` steps. Each step is the ID of a built-in process run
3893+
of the same project, which starts and must exit with 0 before the next step,
3894+
and the configuration itself, starts (IntelliJ IDEA's "Before launch: Run
3895+
Another Configuration"). A shell script that compiles a module or a program
3896+
that generates sources is saved as a process run and named as a step, so a step
3897+
has the interpreter, arguments, working directory, environment and launch plan
3898+
a process run already has. A layer replaces the whole list: an empty list in the
3899+
local layer hides the steps the project layer names. A step that names the
3900+
configuration itself makes the configuration unavailable
3901+
(`invalidConfiguration`); a step whose target is missing or cannot run is
3902+
reported when the configuration starts, so the list still resolves.
3903+
3904+
`runConfig.beforeLaunch` accepts `{root, configurationId, localDocument?}` and
3905+
replies `{status: "ok", steps, confirmation}` or `{status: "rejected", refusal:
3906+
{code, configurationId}}`. `steps` are the runs to start, in order, each
3907+
`{configurationId, name, summary}`; `summary` is one line naming what it starts
3908+
(the program or script and its arguments) for the confirmation. A step whose run
3909+
names steps of its own starts them first, as starting that run alone would; at
3910+
most 32 steps are expanded. `refusal.code` is `notFound` (no such
3911+
configuration), `notAllowed` (not a built-in process run), `unavailable` (the
3912+
run cannot start, see its `availability`), `cycle` (a step leads back to a
3913+
configuration being started) or `tooLong`; `configurationId` names the step.
3914+
3915+
`confirmation` is `{fingerprint}` when the project layer names any of the
3916+
expanded lists, and `null` otherwise. Those steps run code from the repository
3917+
that nobody chose on this machine, so the host asks the user before running
3918+
them, showing each step's name and summary, and remembers the fingerprint per
3919+
project in its own storage, never in the project. The fingerprint is a SHA-256
3920+
over the lists and the definitions of the runs they start, so changing either
3921+
asks again; it does not cover the contents of a script file a step runs. A list
3922+
the local layer names, including one that starts runs the project defines, was
3923+
chosen on this machine and needs no confirmation. The host runs each step
3924+
through `runConfig.createLaunchPlan`, writes its output to the console of the
3925+
configuration that starts, stops it with that configuration, and does not start
3926+
the configuration when a step fails or is stopped. Run and Debug both run the
3927+
steps.
3928+
3929+
`runConfig.editorForm` adds a `beforeLaunch` field to every process run with
3930+
`candidates: [{id, name}]`, the runnable process runs other than the edited one;
3931+
its value is the list of IDs. `runConfig.saveConfiguration` checks it like
3932+
`runConfig.beforeLaunch` and reports `{field: "beforeLaunch", code}` with
3933+
`notFound`, `notAllowed`, `unavailable`, `conflict` (a cycle) or `tooLong`.
3934+
`runConfig.updateOptions` and `runConfig.saveEditorChanges` accept an optional
3935+
`beforeLaunch` list of IDs for any configuration: omission keeps the saved
3936+
steps, an empty list removes them from the edited layer (and in the local layer
3937+
hides the project's), and a list that cannot run is `invalid_request` with
3938+
`beforeLaunch: <code>` in the details.
3939+
38883940
`runConfig.createLaunchPlan` accepts `root`, `configurationId`, optional
38893941
`localDocument` and optional `inlineScriptBase`. It resolves the configuration
38903942
through the same layers and rejects a missing, disabled or unavailable one.

‎rust/crates/core/src/protocol/command.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,8 @@ pub enum RunConfigCommand {
740740
SaveConfiguration,
741741
/// Removes a user-authored run configuration (`runConfig.deleteConfiguration`).
742742
DeleteConfiguration,
743+
/// Expands the steps run before a configuration starts (`runConfig.beforeLaunch`).
744+
BeforeLaunch,
743745
/// Produces the process plan for one configuration (`runConfig.createLaunchPlan`).
744746
CreateLaunchPlan,
745747
/// Resolves user choices for a provider-owned launch (`runConfig.providerLaunchInputs`).
@@ -1427,6 +1429,7 @@ impl CoreCommand {
14271429
"runConfig.deleteConfiguration" => {
14281430
Some(Self::RunConfig(RunConfigCommand::DeleteConfiguration))
14291431
}
1432+
"runConfig.beforeLaunch" => Some(Self::RunConfig(RunConfigCommand::BeforeLaunch)),
14301433
"runConfig.createLaunchPlan" => {
14311434
Some(Self::RunConfig(RunConfigCommand::CreateLaunchPlan))
14321435
}

‎rust/crates/core/src/runtime/dispatcher/run_config.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,21 @@ pub(super) fn dispatch(
217217
Err(error) => CoreResponse::failure(id, error),
218218
}
219219
}
220+
RunConfigCommand::BeforeLaunch => {
221+
match serde_json::from_value::<crate::execution::BeforeLaunchRequest>(payload)
222+
.map_err(|error| {
223+
CoreError::new(
224+
ErrorCode::InvalidRequest,
225+
"Invalid run configuration before launch request",
226+
)
227+
.with_details(error.to_string())
228+
})
229+
.and_then(crate::execution::before_launch)
230+
{
231+
Ok(data) => CoreResponse::success(id, data),
232+
Err(error) => CoreResponse::failure(id, error),
233+
}
234+
}
220235
RunConfigCommand::DeleteConfiguration => {
221236
match serde_json::from_value::<crate::execution::DeleteConfigurationRequest>(payload)
222237
.map_err(|error| {

0 commit comments

Comments
 (0)