Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions desktop/internal/core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,32 @@ type BuildModelOptionSelection struct {
ActiveChoices map[string][]string `json:"activeChoices"`
}

// BuildRunEntry is a command Run entry Core derived from a decoded model: one
// command run declaration applied to a model target or task, with its command
// line expanded at the options the model was read with. Provider runs have no
// entry; they are prepared on demand.
// RunTypeReference identifies a declared run configuration type together with
// its field values, as emitted by build.decodeModel (`runConfigurationTypes` 0)
// and stored under `extensions.build` on `build.run-type` configurations.
type RunTypeReference struct {
PluginID string `json:"pluginID"`
BuildSystemID string `json:"buildSystemID"`
Type string `json:"type"`
Values map[string]json.RawMessage `json:"values,omitempty"`
}

// BuildRunEntry is a Run entry Core derived from a decoded model: either a
// command entry with expanded Arguments, or a generated `build.run-type` entry
// carrying RunType. Provider runs have no entry; they are prepared on demand.
type BuildRunEntry struct {
ID string `json:"id"`
Name string `json:"name"`
Provider string `json:"provider,omitempty"`
Execution string `json:"execution"`
// Arguments follow the build tool, which the host resolves as for a task.
Arguments []string `json:"args"`
// WorkingDirectory is relative to the workspace root, like a plan's.
WorkingDirectory string `json:"cwd"`
Environment map[string]string `json:"env"`
BuildSystem BuildRunEntryBinding `json:"buildSystem"`
// RunType is populated when a run declaration targets a runConfigurationType.
RunType *RunTypeReference `json:"runType,omitempty"`
}

// BuildRunEntryBinding names the model item a Run entry was derived from:
Expand Down
16 changes: 11 additions & 5 deletions desktop/internal/core/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ type RunProviderReference struct {
UserArguments []string `json:"userArguments"`
}

// RunProviderRun is one entry of the providerRuns snapshot: a run the current
// build models offer, under the workspace-relative project path that owns it.
// RunProviderRun is one entry of the providerRuns snapshot: either a build
// provider selector (Reference) or a generated run-configuration-type entry
// (RunType, CWD, Execution, Selector), under the workspace-relative project
// path that owns it.
type RunProviderRun struct {
ProjectPath string `json:"projectPath"`
Name string `json:"name"`
Reference RunProviderReference `json:"reference"`
ProjectPath string `json:"projectPath"`
Name string `json:"name"`
Reference *RunProviderReference `json:"reference,omitempty"`
CWD string `json:"cwd,omitempty"`
Execution string `json:"execution,omitempty"`
Selector string `json:"selector,omitempty"`
RunType *RunTypeReference `json:"runType,omitempty"`
}

// RunConfiguration is one effective run configuration after Core merged the
Expand Down
47 changes: 45 additions & 2 deletions desktop/internal/core/run_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestProviderRunsResolveAndLaunchInputs(t *testing.T) {
}
reference := RunProviderReference{PluginID: "dev.example.engine", BuildSystemID: "engine", Root: "app", Run: "application",
ProjectID: "app", TargetID: "main", UserArguments: []string{}}
runs, err := json.Marshal([]RunProviderRun{{ProjectPath: "app", Name: "Run Main", Reference: reference}})
runs, err := json.Marshal([]RunProviderRun{{ProjectPath: "app", Name: "Run Main", Reference: &reference}})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestRunConfigurationOptionsRoundTrip(t *testing.T) {
}
reference := RunProviderReference{PluginID: "dev.example.engine", BuildSystemID: "engine", Root: "app", Run: "application",
ProjectID: "app", TargetID: "main", UserArguments: []string{}}
runs, err := json.Marshal([]RunProviderRun{{ProjectPath: "app", Name: "Run Main", Reference: reference}})
runs, err := json.Marshal([]RunProviderRun{{ProjectPath: "app", Name: "Run Main", Reference: &reference}})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -212,3 +212,46 @@ func TestBuiltInProcessRunRoundTrip(t *testing.T) {
t.Fatalf("resolve after delete = %+v, %v", resolved, err)
}
}

// A generated run-configuration-type snapshot entry resolves as a `build.run-type`
// configuration with a stable `generated:run-type:*` ID and its declared RunTypeKey.
func TestGeneratedRunTypeSnapshotResolvesAsDeclaredKind(t *testing.T) {
client := NewClient()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
root := t.TempDir()
if err := os.MkdirAll(filepath.Join(root, "sub"), 0o755); err != nil {
t.Fatal(err)
}
runs, err := json.Marshal([]RunProviderRun{{
ProjectPath: "sub",
Name: "build",
CWD: "sub",
Execution: "task",
Selector: "tasker.target:sub:build",
RunType: &RunTypeReference{
PluginID: "dev.example.tasker",
BuildSystemID: "tasker",
Type: "target",
Values: map[string]json.RawMessage{
"targets": json.RawMessage(`["build"]`),
},
},
}})
if err != nil {
t.Fatal(err)
}
if _, err := client.GenerateRunConfigurations(ctx, root, runs); err != nil {
t.Fatal(err)
}
resolved, err := client.ResolveRunConfigurations(ctx, root, nil)
if err != nil || len(resolved.Configurations) != 1 {
t.Fatalf("resolve = %+v, %v", resolved, err)
}
cfg := resolved.Configurations[0]
key, ok := cfg.RunTypeReference()
if !ok || !strings.HasPrefix(cfg.ID, "generated:run-type:") || cfg.Provider != RunTypeProvider || cfg.UserDefined() ||
key != (RunTypeKey{PluginID: "dev.example.tasker", BuildSystemID: "tasker", Type: "target"}) || cfg.Cwd != "sub" {
t.Fatalf("configuration = %+v key = %+v ok = %v", cfg, key, ok)
}
}
2 changes: 1 addition & 1 deletion desktop/internal/core/run_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestGenerateRunConfigurationsNeverWritesTheWorkspace(t *testing.T) {
}
reference := RunProviderReference{PluginID: "dev.example.engine", BuildSystemID: "engine", Root: "app", Run: "application",
ProjectID: "app", TargetID: "main", UserArguments: []string{}}
runs, err := json.Marshal([]RunProviderRun{{ProjectPath: "app", Name: "Run Main", Reference: reference}})
runs, err := json.Marshal([]RunProviderRun{{ProjectPath: "app", Name: "Run Main", Reference: &reference}})
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 5 additions & 2 deletions desktop/internal/pluginhost/pluginhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ type Capabilities map[string][]int
// - runConfigurationTypes: the Run/Debug Configurations dialog lists the
// kinds a build system declares after the built-in ones, edits them with the
// form Core describes in the plugin's translation, saves them and runs them
// with the command Core plans for the detected instance. A declared kind has
// no debugger.
// with the command Core plans for the detected instance. buildSystems[].run[]
// may also target a declared kind via configurationType and values so
// discovered model targets materialize generated configurations under the
// same group, icon, editor form and launch plan. A declared kind has no
// debugger.
// - beforeLaunchTasks: the Add New Task menu of every configuration's Before
// launch list offers the tasks a build system declares, edits each with the
// form Core describes in the plugin's translation, and runs the step with
Expand Down
12 changes: 12 additions & 0 deletions desktop/internal/workbench/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,18 @@ func (a *App) runBuildEntry(p *project, entryID string) {
if instance == nil {
return
}
for index := range instance.Model.Run {
entry := &instance.Model.Run[index]
if entry.ID == entryID && entry.RunType != nil {
if id, ok := p.generatedRunTypeConfigurationID(*entry); ok {
a.runConfiguration(p, id)
return
}
a.operationRejected("build_run_entry", "target_missing")
a.notifyError(a.text.Build.TargetMissing)
return
}
}
instanceID := instance.ID
a.startRun(p, "entry:"+instanceID+"/"+entryID, func(a *App, p *project) { a.startBuildEntry(p, instanceID, entryID) })
}
Expand Down
72 changes: 70 additions & 2 deletions desktop/internal/workbench/runconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"path"
"slices"
"strings"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
Expand Down Expand Up @@ -86,7 +87,8 @@ func (s *runConfigState) configuration(id string) *core.RunConfiguration {
}

// providerRuns is the providerRuns snapshot of the instances whose model has loaded:
// each target a run declaration applies to, under its workspace-relative project path.
// each target a provider run declaration applies to, plus each model run entry targeting
// a declared runConfigurationType, under its workspace-relative project path.
// ok is false while no model has loaded, so a refresh does not withdraw every detected
// run before the models answer.
func providerRuns(instances []buildInstance) ([]core.RunProviderRun, bool) {
Expand All @@ -110,17 +112,83 @@ func providerRuns(instances []buildInstance) ([]core.RunProviderRun, bool) {
runs = append(runs, core.RunProviderRun{
ProjectPath: path.Clean(path.Join(instance.Root, project.Path)),
Name: run.EntryName(target.Name),
Reference: core.RunProviderReference{
Reference: &core.RunProviderReference{
PluginID: instance.PluginID, BuildSystemID: instance.BuildSystemID, Root: instance.Root,
Run: run.ID, ProjectID: project.ID, TargetID: target.ID, Execution: run.Execution, UserArguments: []string{},
},
})
}
}
for _, entry := range instance.Model.Run {
if entry.RunType == nil {
continue
}
cwd := entry.WorkingDirectory
if cwd == "" {
cwd = instance.Root
}
cwd = path.Clean(cwd)
projectPath := cwd
if project, ok := buildProjectByID(instance.Model, entry.BuildSystem.ProjectID); ok && project.Path != "" {
candidate := path.Clean(project.Path)
if cwd == "." || candidate == cwd || strings.HasPrefix(candidate, cwd+"/") {
projectPath = candidate
} else {
projectPath = path.Clean(path.Join(instance.Root, candidate))
}
}
runType := *entry.RunType
runs = append(runs, core.RunProviderRun{
ProjectPath: projectPath,
Name: entry.Name,
CWD: cwd,
Execution: entry.Execution,
Selector: entry.ID,
RunType: &runType,
})
}
}
return runs, loaded
}

// generatedRunTypeConfigurationID finds the resolved generated `build.run-type`
// configuration corresponding to a decoded BuildRunEntry.
func (p *project) generatedRunTypeConfigurationID(entry core.BuildRunEntry) (string, bool) {
if entry.RunType == nil {
return "", false
}
wantKey := core.RunTypeKey{
PluginID: entry.RunType.PluginID,
BuildSystemID: entry.RunType.BuildSystemID,
Type: entry.RunType.Type,
}
wantJSON, _ := json.Marshal(entry.RunType)
fallback := ""
for index := range p.runConfigs.list {
cfg := &p.runConfigs.list[index]
if !strings.HasPrefix(cfg.ID, "generated:run-type:") {
continue
}
key, ok := cfg.RunTypeReference()
if !ok || key != wantKey {
continue
}
if cfg.Cwd == entry.WorkingDirectory {
var ref core.RunTypeReference
if json.Unmarshal(cfg.Extensions["build"], &ref) == nil {
gotJSON, _ := json.Marshal(&ref)
if string(gotJSON) == string(wantJSON) {
return cfg.ID, true
}
}
}
if fallback == "" && (cfg.Name == entry.Name || cfg.Name == entry.Name+" ("+entry.WorkingDirectory+")") {
fallback = cfg.ID
}
}
return fallback, fallback != ""
}

// refreshRunConfigurations has Core generate the runs the loaded models declare and
// resolve the configurations again. Nothing is written into the workspace. It runs
// without any loaded model too, so built-in process runs list and start while no
Expand Down
74 changes: 74 additions & 0 deletions desktop/internal/workbench/runconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,77 @@ func TestRunConfigurationRunsWithItsSavedChoices(t *testing.T) {
t.Fatalf("run request = %+v options = %+v", request, options)
}
}

// A model run entry targeting a declared runConfigurationType becomes a generated
// `build.run-type` snapshot entry and lands in the exact same Run/Debug Configurations
// dialog group as a user-created configuration of that kind.
func TestGeneratedRunTypeSharesDialogGroupWithUserConfiguration(t *testing.T) {
ref := &core.RunTypeReference{
PluginID: "dev.example.tasker",
BuildSystemID: "tasker",
Type: "target",
Values: map[string]json.RawMessage{"targets": json.RawMessage(`["build"]`)},
}
instance := buildInstance{
BuildInstance: core.BuildInstance{ID: "tasker@sub", PluginID: "dev.example.tasker", BuildSystemID: "tasker", Root: "sub"},
PluginID: "dev.example.tasker",
Model: core.BuildModel{
Projects: []core.BuildProject{{ID: "sub", Path: "sub", Name: "sub"}},
Run: []core.BuildRunEntry{{
ID: "tasker.target:sub:build",
Name: "build",
Provider: core.RunTypeProvider,
Execution: "task",
WorkingDirectory: "sub",
BuildSystem: core.BuildRunEntryBinding{ProjectID: "sub", TargetID: "sub:build"},
RunType: ref,
}},
},
modelLoaded: true,
}
runs, loaded := providerRuns([]buildInstance{instance})
if !loaded || len(runs) != 1 || runs[0].Reference != nil || runs[0].RunType == nil ||
runs[0].ProjectPath != "sub" || runs[0].CWD != "sub" || runs[0].Selector != "tasker.target:sub:build" {
t.Fatalf("runs = %+v loaded = %v", runs, loaded)
}

key := core.RunTypeKey{PluginID: "dev.example.tasker", BuildSystemID: "tasker", Type: "target"}
ext, err := json.Marshal(ref)
if err != nil {
t.Fatal(err)
}
app := &App{}
p := &project{}
p.runConfigs.types = []core.RunConfigurationType{{
Provider: core.RunTypeProvider,
RunType: &key,
DisplayName: "Tasker Target",
Execution: "task",
}}
p.runConfigs.list = []core.RunConfiguration{
{
ID: "generated:run-type:0123456789abcdef",
Name: "build",
Provider: core.RunTypeProvider,
Execution: "task",
Cwd: "sub",
Extensions: map[string]json.RawMessage{"build": ext},
},
{
ID: "user:custom-build",
Name: "Custom Build",
Provider: core.RunTypeProvider,
Execution: "task",
Cwd: "sub",
Extensions: map[string]json.RawMessage{"build": ext},
},
}
p.collectRunConfigDialogRows(app)
if len(p.runConfigs.dialog.groups) != 1 {
t.Fatalf("dialog groups = %+v, want 1 unified group", p.runConfigs.dialog.groups)
}
group := p.runConfigs.dialog.groups[0]
if group.title != "Tasker Target" || len(group.keys) != 2 {
t.Fatalf("group = %+v, want title Tasker Target with 2 entries", group)
}
}
Loading
Loading