From fe393cb01a4627c12fba80834cccb4eab2d69a39 Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Tue, 17 Nov 2026 23:44:17 -0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(desktop):=20=E6=8F=92=E4=BB=B6=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=94=B9=E5=8A=A8=E5=90=8E=E9=87=8D=E5=90=AF=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E6=8F=90=E4=BE=9B=E8=80=85=EF=BC=8C=E5=B9=B6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=8F=90=E4=BE=9B=E8=80=85=E8=87=AA=E5=B7=B1=E7=9A=84?= =?UTF-8?q?=E6=8A=A5=E9=94=99=20(#2142,=20#2143)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 构建提供者按启动时的插件设置(全局 + 项目)记录;设置变了,下一次请求启动新进程, 旧进程在手上的请求结束后关闭,关闭项目时与其他提供者一起立即关闭。符合契约 “A change of the plugin's settings restarts it on the next request”。 - buildprovider 解码 Core 的 underlyingMessage,取提供者 JSON-RPC 错误的 message; 运行、调试准备、构建模型和依赖树失败时显示它,日志仍只记录 Core 的代码和消息。 Co-Authored-By: Claude Opus 5.5 --- .../internal/buildprovider/buildprovider.go | 61 ++++- .../lifecycle_regression_test.go | 56 +++++ desktop/internal/workbench/build.go | 118 ++++++++-- .../internal/workbench/build_dependencies.go | 2 +- .../workbench/build_provider_restart_test.go | 218 ++++++++++++++++++ .../internal/workbench/command_installers.go | 10 +- .../internal/workbench/tests_provider_test.go | 23 ++ 7 files changed, 466 insertions(+), 22 deletions(-) create mode 100644 desktop/internal/workbench/build_provider_restart_test.go diff --git a/desktop/internal/buildprovider/buildprovider.go b/desktop/internal/buildprovider/buildprovider.go index cfae978fec..7edf5e396f 100644 --- a/desktop/internal/buildprovider/buildprovider.go +++ b/desktop/internal/buildprovider/buildprovider.go @@ -13,6 +13,7 @@ import ( "encoding/json" "errors" "fmt" + "strings" "sync" "sync/atomic" "time" @@ -329,6 +330,32 @@ func (c *Client) Cancel(ctx context.Context, operation *Operation) error { return c.runner.Cancel(ctx, c.session, operation.ID) } +// Drain waits until the operations running when it is called reached their +// terminal event, the session ended, or ctx is done. A caller that stops +// handing the client new requests uses it to close the client without failing +// the requests it already sent. +func (c *Client) Drain(ctx context.Context) error { + if c == nil { + return nil + } + c.mu.Lock() + running := make([]*Operation, 0, len(c.pending)) + for _, operation := range c.pending { + running = append(running, operation) + } + c.mu.Unlock() + for _, operation := range running { + select { + case <-operation.done: + case <-c.done: + return nil + case <-ctx.Done(): + return ctx.Err() + } + } + return nil +} + // Close stops the session this client started. func (c *Client) Close(ctx context.Context) error { if c == nil { @@ -475,10 +502,14 @@ func (c *Client) ended() error { } // ProviderError is the failure a provider completed an operation with: the -// stable code Core kept or normalised, and the bounded message. +// stable code Core kept or normalised, and the bounded message. Detail is the +// message of the provider's own JSON-RPC error, which Core keeps apart under its +// serverError code and generic message: it is the plugin's text for the user, +// so Error, which logs record, leaves it out. type ProviderError struct { Code string Message string + Detail string } func (e *ProviderError) Error() string { @@ -488,17 +519,39 @@ func (e *ProviderError) Error() string { return e.Code + ": " + e.Message } +// UserMessage is what the window shows of the failure: the provider's own +// message when it sent one, else Core's message. +func (e *ProviderError) UserMessage() string { + if e.Detail != "" { + return e.Detail + } + return e.Message +} + func providerError(raw json.RawMessage) error { var failure ProviderError var decoded struct { - Code string `json:"code"` - Message string `json:"message"` + Code string `json:"code"` + Message string `json:"message"` + Underlying string `json:"underlyingMessage"` } if json.Unmarshal(raw, &decoded) == nil && decoded.Message != "" { - failure.Code, failure.Message = decoded.Code, decoded.Message + failure.Code, failure.Message, failure.Detail = decoded.Code, decoded.Message, providerMessage(decoded.Underlying) return &failure } return fmt.Errorf("build provider failed: %s", string(raw)) } +// providerMessage is the message of the provider's JSON-RPC error that Core +// passes as the failure's underlyingMessage, or "" when it carries none. +func providerMessage(underlying string) string { + var reply struct { + Message string `json:"message"` + } + if underlying == "" || json.Unmarshal([]byte(underlying), &reply) != nil { + return "" + } + return strings.TrimSpace(reply.Message) +} + var nextOperation atomic.Uint64 diff --git a/desktop/internal/buildprovider/lifecycle_regression_test.go b/desktop/internal/buildprovider/lifecycle_regression_test.go index 7dac1a8d23..44769850ab 100644 --- a/desktop/internal/buildprovider/lifecycle_regression_test.go +++ b/desktop/internal/buildprovider/lifecycle_regression_test.go @@ -134,3 +134,59 @@ func (k *blockingRequestKernel) RequestPluginBuild(context.Context, core.PluginB <-k.release return "", errors.New("request rejected") } + +// Core keeps a provider's JSON-RPC error under its serverError code and generic message and +// passes the provider's own message apart; the window shows that message, logs keep only Core's. +func TestProviderErrorKeepsTheProvidersOwnMessageApart(t *testing.T) { + err := providerError(json.RawMessage(`{"code":"serverError","stage":"request","method":"lithe/build/prepareRun","message":"Language server returned an error.","underlyingMessage":"{\"code\":-32603,\"message\":\"Choose the installation in the plugin's settings.\"}"}`)) + var failure *ProviderError + if !errors.As(err, &failure) { + t.Fatalf("decoded %T, want *ProviderError", err) + } + if failure.UserMessage() != "Choose the installation in the plugin's settings." { + t.Fatalf("user message = %q, want the provider's", failure.UserMessage()) + } + if strings.Contains(err.Error(), "installation") { + t.Fatalf("Error, which logs record, carries the plugin's text: %q", err.Error()) + } + for _, raw := range []string{ + `{"code":"timeout","message":"The request timed out."}`, + `{"code":"serverError","message":"The request timed out.","underlyingMessage":"not a JSON-RPC error"}`, + } { + plain := providerError(json.RawMessage(raw)) + if !errors.As(plain, &failure) || failure.UserMessage() != "The request timed out." { + t.Fatalf("a failure without a provider message = %v", plain) + } + } +} + +// Drain returns once the operations running when it was called ended, and at once when the +// session ended first. +func TestDrainWaitsForRunningOperations(t *testing.T) { + client := newClient(nil, pluginbackend.Session{ID: "shared"}) + operation := newOperation("op", "lithe/build/execute") + client.pending["op"] = operation + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + drained := make(chan error, 1) + go func() { drained <- client.Drain(ctx) }() + select { + case err := <-drained: + t.Fatalf("Drain returned while an operation still ran: %v", err) + default: + } + client.Observe(core.BackendEvent{Type: "requestCompleted", OperationID: "op", Result: json.RawMessage(`{"value":{}}`)}) + select { + case err := <-drained: + if err != nil { + t.Fatalf("Drain: %v", err) + } + case <-ctx.Done(): + t.Fatal("Drain did not return after the operation completed") + } + + idle := newClient(nil, pluginbackend.Session{ID: "idle"}) + if err := idle.Drain(ctx); err != nil { + t.Fatalf("Drain of an idle client: %v", err) + } +} diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index 655df9746a..faff32ac11 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "errors" + "fmt" "os" "os/exec" "path/filepath" @@ -350,6 +351,12 @@ type buildRuntime struct { launches pluginLaunches mu sync.Mutex providers map[string]*buildprovider.Client + // settings is, for each running provider, the plugin settings it was started with + // (buildSettingsKey). The contract restarts a provider on the next request after they change. + settings map[string]string + // retired are providers a settings change replaced. Each closes once the requests it already + // had finished; a detach closes them at once with the others. + retired map[*buildprovider.Client]struct{} // shared maps a plugin and language to the client attached to that // language server's session. shared map[string]*buildprovider.Client @@ -363,27 +370,46 @@ type buildRuntime struct { // outside the lock, so detaching on the window thread never waits for a start; a start that lost // to another one or to a detach is stopped again. logDirectory gives the process's ${logDir}, and // is asked only when a process starts. -func (r *buildRuntime) provider(ctx context.Context, runner *pluginbackend.Runner, pluginRoot, root, rootURI string, instance buildInstance, settings core.PluginSettingsState, logDirectory func(context.Context, string) string) (*buildprovider.Client, error) { +// +// A provider started with other plugin settings than settings holds is replaced, as the contract +// says: a change of the plugin's settings restarts it on the next request, so its launch +// arguments reflect the current values. The replaced provider is returned as retired; the +// caller closes it with retire once the requests it already had finished. +func (r *buildRuntime) provider(ctx context.Context, runner *pluginbackend.Runner, pluginRoot, root, rootURI string, instance buildInstance, settings core.PluginSettingsState, logDirectory func(context.Context, string) string) (client, retired *buildprovider.Client, err error) { key := instance.PluginID + "\x00" + instance.BuildSystemID errClosing := buildprovider.ErrClosed + launchedWith, err := buildSettingsKey(settings) + if err != nil { + return nil, nil, err + } r.mu.Lock() closed, client, detached := r.closed, r.providers[key], r.detached + if !closed && client != nil && !client.Closed() && r.settings[key] != launchedWith { + retired = client + delete(r.providers, key) + delete(r.settings, key) + if r.retired == nil { + r.retired = make(map[*buildprovider.Client]struct{}) + } + r.retired[retired] = struct{}{} + client = nil + } r.mu.Unlock() if closed { - return nil, errClosing + return nil, nil, errClosing } if client != nil && !client.Closed() { - return client, nil + return client, nil, nil } state := buildStateDirectory(pluginRoot, root, instance) if err := os.MkdirAll(state, 0o700); err != nil { - return nil, err + return nil, retired, err } workspaceState := filepath.Join(state, "workspace") temporaryDirectory := filepath.Join(state, "tmp") for _, directory := range []string{workspaceState, temporaryDirectory} { if err := os.MkdirAll(directory, 0o700); err != nil { - return nil, err + return nil, retired, err } } started, err := buildprovider.Start(ctx, runner, pluginbackend.StartRequest{ @@ -404,7 +430,7 @@ func (r *buildRuntime) provider(ctx context.Context, runner *pluginbackend.Runne WorkingDirectory: root, }) if err != nil { - return nil, err + return nil, retired, err } r.mu.Lock() current := !r.closed && r.detached == detached && ctx.Err() == nil @@ -412,21 +438,63 @@ func (r *buildRuntime) provider(ctx context.Context, runner *pluginbackend.Runne if current && (client == nil || client.Closed()) { if r.providers == nil { r.providers = make(map[string]*buildprovider.Client) + r.settings = make(map[string]string) } r.providers[key] = started + r.settings[key] = launchedWith r.mu.Unlock() - return started, nil + return started, retired, nil } r.mu.Unlock() stopCtx, cancel := context.WithTimeout(context.Background(), buildStopTimeout) defer cancel() if err := started.Close(stopCtx); err != nil { - return nil, err + return nil, retired, err } if !current { - return nil, errClosing + return nil, retired, errClosing } - return client, nil + return client, retired, nil +} + +// retire closes a provider that provider replaced, once the requests it already had finished or +// buildRequestTimeout passed; requests still running then end with the close. It leaves the +// client alone when a detach took it first and closes it itself. The error reports a provider +// that outlived the wait or failed to stop. +func (r *buildRuntime) retire(client *buildprovider.Client) error { + drainCtx, cancelDrain := context.WithTimeout(context.Background(), buildRequestTimeout) + defer cancelDrain() + var failures []error + if err := client.Drain(drainCtx); err != nil { + failures = append(failures, fmt.Errorf("the replaced build provider still served requests after %s: %w", buildRequestTimeout, err)) + } + r.mu.Lock() + _, owned := r.retired[client] + delete(r.retired, client) + r.mu.Unlock() + if !owned { + return nil + } + stopCtx, cancel := context.WithTimeout(context.Background(), buildStopTimeout) + defer cancel() + if err := client.Close(stopCtx); err != nil { + failures = append(failures, err) + } + return errors.Join(failures...) +} + +// buildSettingsKey identifies the plugin settings a provider starts with: the global values and +// the project's, each keyed by setting ID. encoding/json writes map keys sorted, so equal settings +// give equal keys. +func buildSettingsKey(settings core.PluginSettingsState) (string, error) { + encoded, err := json.Marshal(struct { + Settings map[string]json.RawMessage `json:"settings"` + ProjectSettings map[string]json.RawMessage `json:"projectSettings"` + }{settings.Settings, settings.ProjectSettings}) + if err != nil { + return "", fmt.Errorf("encode build provider settings: %w", err) + } + return string(encoded), nil } // detach takes every session the runtime holds, its own providers before the clients attached to @@ -443,7 +511,10 @@ func (r *buildRuntime) detach(closing bool) []*buildprovider.Client { for _, provider := range r.shared { clients = append(clients, provider) } - r.providers, r.shared = nil, nil + for provider := range r.retired { + clients = append(clients, provider) + } + r.providers, r.settings, r.retired, r.shared = nil, nil, nil, nil r.detached++ if closing { r.closed = true @@ -476,7 +547,10 @@ func (a *App) buildProvider(ctx context.Context, p *project, instance buildInsta if err != nil { return nil, err } - client, err = p.buildSessions.provider(ctx, a.plugins.Backend, a.plugins.Root, p.root, rootURI, instance, settings.State, a.pluginLogDirectory) + client, retired, err := p.buildSessions.provider(ctx, a.plugins.Backend, a.plugins.Root, p.root, rootURI, instance, settings.State, a.pluginLogDirectory) + if retired != nil { + a.retireBuildProvider(ctx, p, retired) + } var shared *pluginbackend.SharedProviderError if !errors.As(err, &shared) { return client, err @@ -484,6 +558,19 @@ func (a *App) buildProvider(ctx context.Context, p *project, instance buildInsta return a.sharedBuildProvider(ctx, p, instance, shared.LanguageID) } +// retireBuildProvider closes, away from the window thread, a provider its plugin's changed +// settings replaced, after the requests it already had finished. A failure is logged under the +// user action whose request (ctx) replaced it. +func (a *App) retireBuildProvider(ctx context.Context, p *project, client *buildprovider.Client) { + a.tasks.running.Add(1) + go func() { + defer a.tasks.running.Done() + if err := p.buildSessions.retire(client); err != nil { + a.backgroundFailedIn(ctx, "build_provider_restart", err) + } + }() +} + // sharedBuildProvider attaches a build client to the language server of the // same plugin. If no server runs yet, it starts one and publishes it as the // window's language server so both build and editor requests reuse it. @@ -1655,7 +1742,7 @@ func (a *App) debugProviderTarget(p *project, index int, projectID, targetID, ru return func(a *App) { p.debug.preparing = false a.operationFailed("build_debug_prepare", err) - a.notifyError(err.Error()) + a.notifyError(a.launchFailureText(err)) } } a.saveProjectDocuments(p, func(saved bool) { @@ -2037,11 +2124,12 @@ func (a *App) finishBuildError(p *project, op *buildOperation, err error) { a.endBuildOperation(p, op, "cancelled", nil, "", a.text.Build.Cancelled) return } + message := a.launchFailureText(err) failure := "" if op.ide != nil && op.ide.State == "preparing" { - failure = err.Error() + failure = message } - if a.endBuildOperation(p, op, "failed", nil, failure, err.Error()) { + if a.endBuildOperation(p, op, "failed", nil, failure, message) { a.operationFailed("build", err) } } diff --git a/desktop/internal/workbench/build_dependencies.go b/desktop/internal/workbench/build_dependencies.go index a0f3608ab3..02963168cd 100644 --- a/desktop/internal/workbench/build_dependencies.go +++ b/desktop/internal/workbench/build_dependencies.go @@ -96,7 +96,7 @@ func (a *App) loadBuildDependencies(p *project, instance *buildInstance, project deps.loading = false if err != nil { a.operationFailed("build_dependencies", err) - deps.failed = err.Error() + deps.failed = a.launchFailureText(err) return } deps.tree = tree diff --git a/desktop/internal/workbench/build_provider_restart_test.go b/desktop/internal/workbench/build_provider_restart_test.go new file mode 100644 index 0000000000..6d26de6611 --- /dev/null +++ b/desktop/internal/workbench/build_provider_restart_test.go @@ -0,0 +1,218 @@ +package workbench + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "os" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/buildprovider" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginsettings" +) + +const restartFixtureID = "dev.lithe.test.provider-tests" + +// providerSettingsManifest is the provider fixture with one global setting that its launch passes +// in initializationOptions, so each process records the value it started with. +func providerSettingsManifest(t *testing.T) string { + t.Helper() + var manifest map[string]any + if err := json.Unmarshal([]byte(providerTestsManifest), &manifest); err != nil { + t.Fatal(err) + } + manifest["requires"].(map[string]any)["settings"] = 0 + manifest["settings"] = []any{map[string]any{ + "id": "providerHeapMB", "type": "integer", "title": "Provider memory", + "default": 1024, "minimum": 256, "maximum": 8192, + }} + system := manifest["buildSystems"].([]any)[0].(map[string]any) + system["provider"].(map[string]any)["initializationOptions"] = map[string]any{"heap": "${setting:providerHeapMB}"} + encoded, err := json.Marshal(manifest) + if err != nil { + t.Fatal(err) + } + return string(encoded) +} + +// openProviderSettingsFixture opens a workspace the settings fixture provider serves. +func openProviderSettingsFixture(t *testing.T, h *harness, markers ...string) *project { + t.Helper() + root := t.TempDir() + for _, marker := range append([]string{"fixture.marker", "initialize.marker"}, markers...) { + if err := os.WriteFile(filepath.Join(root, marker), []byte("fixture\n"), 0o600); err != nil { + t.Fatal(err) + } + } + h.open(root) + return h.app.project +} + +// settingsFixtureInstance is the build instance of the settings fixture. +func settingsFixtureInstance(h *harness, manifest string) buildInstance { + return buildInstance{ + BuildInstance: core.BuildInstance{BuildSystemID: "fixture-provider-tests", Root: "."}, + PluginID: restartFixtureID, Version: "1.0.0", + PackageDirectory: filepath.Join(h.app.plugins.Root, restartFixtureID, "1.0.0"), + Manifest: json.RawMessage(manifest), + } +} + +// requestProvider asks for the instance's provider the way a build request does, away from the +// window thread, and returns the client it got. +func requestProvider(t *testing.T, h *harness, p *project, instance buildInstance) *buildprovider.Client { + t.Helper() + var client *buildprovider.Client + var failure error + done := false + h.app.background(p, 90*time.Second, func(ctx context.Context) func(*App) { + started, err := h.app.buildProvider(ctx, p, instance) + return func(*App) { client, failure, done = started, err, true } + }) + awaitStateWithin(t, h, 90*time.Second, "the provider request", func() bool { return done }) + if failure != nil { + t.Fatalf("start the provider: %v", failure) + } + return client +} + +// saveProviderHeap saves the fixture's setting as the settings window does and applies the +// effects the save reports. +func saveProviderHeap(t *testing.T, h *harness, instance buildInstance, heap int) { + t.Helper() + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + settings := pluginsettings.New(h.app.kernel, h.store.Dir()) + snapshot, err := settings.Load(ctx, instance.Manifest, h.app.project.root) + if err != nil { + t.Fatalf("load the plugin settings: %v", err) + } + value, err := json.Marshal(heap) + if err != nil { + t.Fatal(err) + } + result, err := settings.Save(ctx, snapshot, "global", []core.PluginSettingEdit{{ID: "providerHeapMB", Value: value}}, nil) + if err != nil || !result.Committed { + t.Fatalf("save the plugin settings: committed=%v err=%v", result.Committed, err) + } + h.app.post(func(a *App) { + a.applyPluginSettingsEffects(core.PluginSettingsOwner{PluginID: instance.PluginID, Version: instance.Version}, result.Effects) + }) + h.settle() +} + +// providerStarts is what each start of the fixture provider got as initializationOptions. +func providerStarts(t *testing.T, p *project) []string { + t.Helper() + data, err := os.ReadFile(filepath.Join(p.root, "initialize.log")) + if err != nil { + t.Fatalf("read the provider starts: %v", err) + } + return strings.Split(strings.TrimSpace(string(data)), "\n") +} + +// The contract restarts a build provider on the next request after its plugin's settings changed, +// so its launch reflects the current values. The host used to keep the process it started first, +// and a run after the user chose a setting still saw the old value (#2142). +func TestBuildProviderRestartsOnTheNextRequestAfterItsSettingsChanged(t *testing.T) { + manifest := providerSettingsManifest(t) + h := providerTestsHarnessWith(t, manifest) + p := openProviderSettingsFixture(t, h) + instance := settingsFixtureInstance(h, manifest) + + first := requestProvider(t, h, p, instance) + if again := requestProvider(t, h, p, instance); again != first { + t.Fatal("a request with unchanged settings started another provider") + } + saveProviderHeap(t, h, instance, 2048) + second := requestProvider(t, h, p, instance) + if second == first { + t.Fatal("the request after the settings changed reused the provider started with the old values") + } + awaitStateWithin(t, h, 30*time.Second, "the replaced provider's exit", first.Closed) + starts := providerStarts(t, p) + if len(starts) != 2 || !strings.Contains(starts[0], "1024") || !strings.Contains(starts[1], "2048") { + t.Fatalf("provider starts = %q, want the default then the saved value", starts) + } + if again := requestProvider(t, h, p, instance); again != second { + t.Fatal("the restarted provider was replaced again without a settings change") + } +} + +// A request the replaced provider is already serving keeps running to its own answer: the host +// closes that provider only after the request finished, never by failing it. +func TestReplacedBuildProviderFinishesTheRequestItHas(t *testing.T) { + manifest := providerSettingsManifest(t) + h := providerTestsHarnessWith(t, manifest) + p := openProviderSettingsFixture(t, h, "block.marker") + instance := settingsFixtureInstance(h, manifest) + + first := requestProvider(t, h, p, instance) + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + if err := first.WaitReady(ctx); err != nil { + t.Fatalf("the provider never became ready: %v", err) + } + // block.marker makes the fixture hold a test request until the host cancels it. + operation, err := first.Execute(ctx, "lithe/build/test", json.RawMessage(`{"root":".","scope":"workspace","operationID":"blocked"}`), 60_000) + if err != nil { + t.Fatalf("send the blocked request: %v", err) + } + saveProviderHeap(t, h, instance, 2048) + second := requestProvider(t, h, p, instance) + if second == first { + t.Fatal("the request after the settings changed reused the old provider") + } + if first.Closed() { + t.Fatal("the replaced provider closed while it still served a request") + } + if err := first.Cancel(ctx, operation); err != nil { + t.Fatalf("cancel the blocked request: %v", err) + } + if _, err := operation.Wait(ctx); errors.Is(err, buildprovider.ErrClosed) { + t.Fatal("closing the replaced provider failed the request it was serving") + } + awaitStateWithin(t, h, 30*time.Second, "the replaced provider's exit after its request", first.Closed) +} + +// Closing the project closes a replaced provider at once with the others, without waiting for +// the request it still serves. +func TestClosingTheProjectClosesAReplacedProvider(t *testing.T) { + manifest := providerSettingsManifest(t) + h := providerTestsHarnessWith(t, manifest) + p := openProviderSettingsFixture(t, h, "block.marker") + instance := settingsFixtureInstance(h, manifest) + + first := requestProvider(t, h, p, instance) + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + if err := first.WaitReady(ctx); err != nil { + t.Fatalf("the provider never became ready: %v", err) + } + if _, err := first.Execute(ctx, "lithe/build/test", json.RawMessage(`{"root":".","scope":"workspace","operationID":"blocked"}`), 60_000); err != nil { + t.Fatalf("send the blocked request: %v", err) + } + saveProviderHeap(t, h, instance, 2048) + second := requestProvider(t, h, p, instance) + h.app.post(func(a *App) { a.stopBuildSessions(p, true) }) + awaitStateWithin(t, h, 30*time.Second, "both providers' exit", func() bool { return first.Closed() && second.Closed() }) +} + +// The window shows a provider's own message for a failed request, and Core's message when the +// provider sent none (#2143). +func TestLaunchFailureTextShowsTheProvidersOwnMessage(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + failure := &buildprovider.ProviderError{Code: "serverError", Message: "Language server returned an error.", Detail: "Choose the installation in the plugin's settings."} + if got := h.app.launchFailureText(fmt.Errorf("prepare: %w", failure)); got != failure.Detail { + t.Fatalf("user text = %q, want the provider's message", got) + } + plain := &buildprovider.ProviderError{Code: "timeout", Message: "The request timed out."} + if got := h.app.launchFailureText(plain); got != plain.Message { + t.Fatalf("user text without a provider message = %q", got) + } +} diff --git a/desktop/internal/workbench/command_installers.go b/desktop/internal/workbench/command_installers.go index 5438c2516c..1f41b5e4e2 100644 --- a/desktop/internal/workbench/command_installers.go +++ b/desktop/internal/workbench/command_installers.go @@ -14,6 +14,7 @@ import ( "time" "github.com/1lck/Lithe-IDEA/desktop/internal/buildprocess" + "github.com/1lck/Lithe-IDEA/desktop/internal/buildprovider" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginhost" @@ -458,12 +459,17 @@ func commandMissingMessage(language i18n.Language, err error) (string, bool) { return i18n.SharedFormat(language, "desktop.plugins.commandMissingHelp", map[string]string{"commands": strings.Join(missing.Commands, " | ")}), true } -// launchFailureText is the message of a plugin launch that failed: the missing commands when it -// found none, the error itself otherwise. +// launchFailureText is the message of a plugin launch or provider request that failed: the +// missing commands when it found none, the provider's own message when the provider answered +// with an error, the error itself otherwise. func (a *App) launchFailureText(err error) string { if message, ok := commandMissingMessage(a.language(), err); ok { return message } + var provider *buildprovider.ProviderError + if errors.As(err, &provider) { + return provider.UserMessage() + } return err.Error() } diff --git a/desktop/internal/workbench/tests_provider_test.go b/desktop/internal/workbench/tests_provider_test.go index 79780090db..1a24095883 100644 --- a/desktop/internal/workbench/tests_provider_test.go +++ b/desktop/internal/workbench/tests_provider_test.go @@ -135,6 +135,24 @@ func TestProviderTestRunner(t *testing.T) { } switch request.Method { case "initialize": + // initialize.marker selects the settings fixture (build_provider_restart_test.go): each + // start records the initializationOptions it got, one line per process. + if _, err := os.Stat("initialize.marker"); err == nil { + var params struct { + Options json.RawMessage `json:"initializationOptions"` + } + if err := json.Unmarshal(request.Params, ¶ms); err != nil { + os.Exit(12) + } + record, err := os.OpenFile("initialize.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600) + if err != nil { + os.Exit(13) + } + _, writeErr := record.Write(append(params.Options, '\n')) + if closeErr := record.Close(); writeErr != nil || closeErr != nil { + os.Exit(14) + } + } experimental := map[string]any{"litheBuild": map[string]any{"version": 0}} if entrypoints { experimental["litheBuild"] = map[string]any{"version": 1} @@ -526,4 +544,9 @@ func TestProviderRunPreparationShowsItsBuildOutput(t *testing.T) { if op.session.outcome != runFailed { t.Fatalf("a failed preparation ended as %d, want failed", op.session.outcome) } + // The provider's own message is what the run says: Core keeps a provider's JSON-RPC error + // under its generic serverError message and passes the provider's text apart (#2143). + if op.session.summary != "The build failed." { + t.Fatalf("the run summary = %q, want the provider's message", op.session.summary) + } } From dcc64a3595c3859b33d8ba37554bf1f0a000d532 Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Tue, 17 Nov 2026 23:49:57 -0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(desktop):=20=E5=8A=9F=E8=83=BD=E7=9F=A9?= =?UTF-8?q?=E9=98=B5=E8=AE=B0=E5=BD=95=E6=9E=84=E5=BB=BA=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E8=80=85=E8=AE=BE=E7=BD=AE=E9=87=8D=E5=90=AF=E4=B8=8E=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E6=98=BE=E7=A4=BA=20(#2142,=20#2143)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../features/build-system-plugins.json | 8 +++++--- .../features/declarative-plugin-settings.json | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/shared/platform-feature-matrix/features/build-system-plugins.json b/shared/platform-feature-matrix/features/build-system-plugins.json index a980b71486..86af60c275 100644 --- a/shared/platform-feature-matrix/features/build-system-plugins.json +++ b/shared/platform-feature-matrix/features/build-system-plugins.json @@ -2,7 +2,7 @@ "id": "build-system-plugins", "area": "扩展", "group": "插件与主题", - "capability": "构建系统插件(API 3 buildSystems):插件用 JSON 声明构建工具的识别、可执行文件、选项、任务、运行入口、测试和输出格式,或由插件自带、与语言服务器同类的 Provider 进程回答模型和依赖,Rust Core 统一校验、生成命令行或 Provider 请求并解码结果,宿主为每个构建系统打开一个按声明(icon、presentation、category)布局的工具窗口;通过共享 executableResolution 候选解析支持可选设置路径、优先级与相对排序,空值自动发现、显式失败不回退;buildProviders 2/3 原生任务与测试执行复用工作区后端会话,带进度、取消、结果与配置失效隔离;协议 3 可按声明发现测试并在现有构建树按精确选择器运行,源码/设置变化撤销旧清单;协议 4 可为应用目标准备启动计划,Core 校验后交给原生 Run 管理进程;Provider 应用可保存到本地 Run v2 配置并重新准备后重启;插件自有原生程序经 Provider v5 构建并准备 Debug,Build 树和保存的 Run 配置复用原生调试会话;协议 7 可选原生配置投影经通用设置页确认保存并回读(独立能力行 build-native-configuration);buildSystems 3 可声明按实例根独立保存选项;executableResolution 2 复用 Run 工具链注册表和实例本机选择;团队 Build 偏好与本机差异覆盖分开保存;buildProviders 8 支持后端随执行返回有界规范报告并保留工程身份;协议 9 支持声明命名空间的语义测试标识,旧后端不能忽略筛选条件", + "capability": "构建系统插件(API 3 buildSystems):插件用 JSON 声明构建工具的识别、可执行文件、选项、任务、运行入口、测试和输出格式,或由插件自带、与语言服务器同类的 Provider 进程回答模型和依赖,Rust Core 统一校验、生成命令行或 Provider 请求并解码结果,宿主为每个构建系统打开一个按声明(icon、presentation、category)布局的工具窗口;通过共享 executableResolution 候选解析支持可选设置路径、优先级与相对排序,空值自动发现、显式失败不回退;buildProviders 2/3 原生任务与测试执行复用工作区后端会话,带进度、取消、结果与配置失效隔离;协议 3 可按声明发现测试并在现有构建树按精确选择器运行,源码/设置变化撤销旧清单;协议 4 可为应用目标准备启动计划,Core 校验后交给原生 Run 管理进程;Provider 应用可保存到本地 Run v2 配置并重新准备后重启;插件自有原生程序经 Provider v5 构建并准备 Debug,Build 树和保存的 Run 配置复用原生调试会话;协议 7 可选原生配置投影经通用设置页确认保存并回读(独立能力行 build-native-configuration);buildSystems 3 可声明按实例根独立保存选项;executableResolution 2 复用 Run 工具链注册表和实例本机选择;团队 Build 偏好与本机差异覆盖分开保存;buildProviders 8 支持后端随执行返回有界规范报告并保留工程身份;协议 9 支持声明命名空间的语义测试标识,旧后端不能忽略筛选条件;Provider 以 JSON-RPC 错误回答时,运行、调试准备、模型和依赖失败显示 Provider 自己的说明,日志只记录 Core 的错误代码。", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -36,7 +36,8 @@ "desktop/internal/workbench/build_ignored_paths_test.go", "desktop/internal/buildprocess/batch.go", "desktop/internal/buildprocess/batch_test.go", - "desktop/internal/workbench/build_command_output_test.go" + "desktop/internal/workbench/build_command_output_test.go", + "desktop/internal/buildprovider/lifecycle_regression_test.go" ] }, "windows": { @@ -74,7 +75,8 @@ "desktop/internal/buildprocess/batch_test.go", "desktop/internal/workbench/build_command_output_test.go", "desktop/internal/buildprocess/batch_windows_test.go", - "desktop/internal/workbench/build_command_windows_test.go" + "desktop/internal/workbench/build_command_windows_test.go", + "desktop/internal/buildprovider/lifecycle_regression_test.go" ] }, "owner": "Extensions", diff --git a/shared/platform-feature-matrix/features/declarative-plugin-settings.json b/shared/platform-feature-matrix/features/declarative-plugin-settings.json index 40bba8d66f..7f78f6fb05 100644 --- a/shared/platform-feature-matrix/features/declarative-plugin-settings.json +++ b/shared/platform-feature-matrix/features/declarative-plugin-settings.json @@ -2,7 +2,7 @@ "id": "declarative-plugin-settings", "area": "插件", "group": "插件管理", - "capability": "声明式插件通过 Core 校验的设置声明提供整数、枚举、布尔、多选、文本、文件和目录设置,支持全局/项目继承、真实来源保存、通用界面、页面/动作注册及 restart/immediate/reload/nextRun 生效;实际启动与运行消费者必须读取同一来源。 声明动作经显式确认、安装/工作区身份复查与 Core 同工作区函数会话选择后调用;支持取消和完成状态,保留未保存草稿。 已启用插件动态贡献语言/构建系统页,同一应用内窗口按原生目录身份接收全局/项目保存通知,独立保留项目覆盖值与未保存草稿。 插件包可自带 l10n/<语言>.json 翻译设置文字,Core 按界面语言挑选文件并逐条回退到清单原文;切换界面语言后重读文字,但保留未保存草稿。 支持 Core 来源表单、编译器页面、有效/继承值和显式条件原子保存;读取项目工具须点击读取按钮。 来源表单支持 sourceSettings 1:模块侧栏(按父子缩进)、字段分组标签页,以及带添加/移除/排序、文件/目录/候选项三种添加方式和布尔/枚举属性列的条目列表;只读模块只显示条目。", + "capability": "声明式插件通过 Core 校验的设置声明提供整数、枚举、布尔、多选、文本、文件和目录设置,支持全局/项目继承、真实来源保存、通用界面、页面/动作注册及 restart/immediate/reload/nextRun 生效;实际启动与运行消费者必须读取同一来源。 声明动作经显式确认、安装/工作区身份复查与 Core 同工作区函数会话选择后调用;支持取消和完成状态,保留未保存草稿。 已启用插件动态贡献语言/构建系统页,同一应用内窗口按原生目录身份接收全局/项目保存通知,独立保留项目覆盖值与未保存草稿。 插件包可自带 l10n/<语言>.json 翻译设置文字,Core 按界面语言挑选文件并逐条回退到清单原文;切换界面语言后重读文字,但保留未保存草稿。 支持 Core 来源表单、编译器页面、有效/继承值和显式条件原子保存;读取项目工具须点击读取按钮。 来源表单支持 sourceSettings 1:模块侧栏(按父子缩进)、字段分组标签页,以及带添加/移除/排序、文件/目录/候选项三种添加方式和布尔/枚举属性列的条目列表;只读模块只显示条目;独立构建提供者进程记录启动时的插件设置,设置变化后下一次请求启动新进程,旧进程在已有请求结束后关闭。", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -56,7 +56,8 @@ "desktop/internal/workbench/settings_plugin_restart_test.go", "desktop/internal/workbench/debug_start.go", "desktop/internal/workbench/pluginbackends_test.go", - "desktop/internal/settingswindow/plugin_settings_visual_test.go" + "desktop/internal/settingswindow/plugin_settings_visual_test.go", + "desktop/internal/workbench/build_provider_restart_test.go" ] }, "windows": { @@ -112,7 +113,8 @@ "desktop/internal/workbench/settings_plugin_restart_test.go", "desktop/internal/workbench/debug_start.go", "desktop/internal/workbench/pluginbackends_test.go", - "desktop/internal/settingswindow/plugin_settings_visual_test.go" + "desktop/internal/settingswindow/plugin_settings_visual_test.go", + "desktop/internal/workbench/build_provider_restart_test.go" ] }, "owner": "Plugin Platform",