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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Agent 笔记:Viva 设置属性校验与窗口退出收尾

状态:已实现

## 先说结论

分段控件用各选项声明的名称提供无障碍命中,多行输入与列表行只使用组件支持的属性。窗口循环返回时,工作台直接取消仍然存在的项目并写入恢复草稿。正常关窗时的保存和确认仍在窗口循环内完成。

## 问题

[#2285](https://github.com/1lck/Lithe-IDEA/issues/2285) 在 dev 构建打开设置时触发 Viva 的属性校验。窗口循环被中断后,旧收尾还发起普通项目关闭,把文件检查结果交给已经停止的 OnWake。语言服务器因此没有收到取消,工作台一直在等它退出。

## 决策

- 外观、背景强度与通用插件分段控件以选项名称命中。调试器行只在获得 ID 的绘制阶段使用悬停样式,静态容器保持原有命中范围。运行配置多行输入移除框架忽略的等宽属性。
- 正常关闭经用户确认后进入项目资源释放。窗口循环返回后直接复用资源释放,先取消各项目及其服务器,再等待后台任务。未保存的编辑内容按现有恢复存储规则落盘。
- 退出等待给插件服务器的停止期限留出余量。超过总期限后记录已有的后台失败事件。恢复草稿写入错误在后台写入点记录,提示仍通过界面队列发送。

## 考虑过的备选方案

在窗口停止后主动处理 OnWake 队列会再次运行可能打开弹窗、改动关闭后的视图或启动新任务的回调。直接释放项目资源可以将退出限定为取消任务、写恢复草稿及释放资源。

## 后果

项目取消、恢复写入和进程收尾不需要等待下一帧。若后台工作无法在总期限内结束,日志会记录超时,应用继续退出。

## 验证

- 在严格 dev 属性校验下运行设置页及合成插件分段控件测试。
- 用合成语言服务器覆盖普通项目关闭检查尚未回到窗口线程就结束窗口循环的情况,检查服务器取消、恢复草稿写入和原文件未改动。

## 适用范围

- `desktop/internal/settingswindow/`
- `desktop/internal/pluginview/render.go`
- `desktop/internal/workbench/app.go`
- `desktop/internal/workbench/editor_recovery.go`
2 changes: 1 addition & 1 deletion desktop/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ run dev: build

test:
$(SCRIPTS)/desktop-go.sh test ./...
$(SCRIPTS)/desktop-go.sh test -tags dev ./internal/buildinfo
$(SCRIPTS)/desktop-go.sh test -tags dev ./internal/buildinfo ./internal/settingswindow ./internal/pluginview ./internal/workbench

vet:
$(SCRIPTS)/desktop-go.sh vet ./...
Expand Down
2 changes: 1 addition & 1 deletion desktop/internal/pluginview/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func (r *renderer) choice(c ui.C, n *Node) {
// the user made in this paint.
func choose[T comparable](c ui.C, n *Node, label string, value *T, values []T, name func(T) string) bool {
if n.Type == "segmented" {
return ui.Choice(c, value, values, name).Label(label).Changed()
return ui.Choice(c, value, values, name).Changed()
}
return ui.Select(c, value, values, name).MinWidth(120).MaxWidth(230).Label(label).Changed()
}
Expand Down
10 changes: 10 additions & 0 deletions desktop/internal/pluginview/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ func TestDrawSendsChangeForAToggleWithItsValue(t *testing.T) {
}
}

func TestDrawSendsChangeForASegmentedChoice(t *testing.T) {
d := drawView(t, `[{"type":"segmented","id":"mode","label":"Mode","value":"first","options":[
{"value":"first","label":"First"},{"value":"second","label":"Second"}
]}]`)
d.click("Second")
if event := d.sent(); event["event"] != "change" || event["node"] != "mode" || event["value"] != "second" {
t.Fatalf("event = %v, want change of mode to second", event)
}
}

func TestDrawSendsSelectOnceAndActivateForATreeItem(t *testing.T) {
d := drawView(t, `[{"type": "tree", "id": "modules", "label": "Modules", "items": [
{"id": "core", "label": "core", "detail": "3 files", "icon": "plugin"},
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/pluginview/view_visual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const visualView = `[
{"type":"label","id":"count","text":"3 modules · 41 classes","style":"strong"},
{"type":"button","id":"refresh","text":"Refresh","icon":"refresh"},
{"type":"button","id":"build","text":"Build all","icon":"run","tone":"primary"}]},
{"type":"segmented","id":"scope","label":"Scope","value":"all","options":[
{"value":"all","label":"All modules"},{"value":"recent","label":"Recent"}]},
{"type":"textField","id":"filter","placeholder":"Filter modules","width":"fill"},
{"type":"tree","id":"modules","items":[
{"id":"core","label":"core","icon":"plugin","detail":"18 classes","expanded":true,"children":[
Expand Down
10 changes: 7 additions & 3 deletions desktop/internal/settingswindow/stepping_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,11 @@ func (w *window) debuggerList(c ui.C, language i18n.Language) {
k := r.C
changed := w.steppingChanged(adapter)
_, stored := w.effectiveFilters(adapter)
r.Element.Height(debuggerRow).PadSides(0, 12, 0, 14).Gap(9).Items(ui.Center).Hover(ui.Look{}.Background(b.hover))
r.Element.Height(debuggerRow).PadSides(0, 12, 0, 14).Gap(9).Items(ui.Center)
// List also measures the row without a hit identity.
if !r.ID.IsZero() {
r.Element.Hover(ui.Look{}.Background(b.hover))
}
if r.Selected() {
r.Element.Background(b.sel)
}
Expand Down Expand Up @@ -483,7 +487,7 @@ func (w *window) debuggerDetail(c ui.C, language i18n.Language, adapter Stepping
ui.Column(c).FillWidth().MinWidth(0).Shrink(0).Radius(10).Border(1, b.line).Background(b.surface).Pad(6).Children(func() {
for _, feature := range steppingFeatures(language, draft) {
k := c.Part(feature.key)
ui.Row(k).FillWidth().MinHeight(34).PadX(8).PadY(3).Gap(10).Radius(7).Items(ui.Center).Hover(ui.Look{}.Background(b.hover)).Children(func() {
ui.Row(k).FillWidth().MinHeight(34).PadX(8).PadY(3).Gap(10).Radius(7).Items(ui.Center).Children(func() {
ui.Row(k).Grow(1).Shrink(1).MinWidth(0).Gap(5).Items(ui.Center).Children(func() {
ui.Text(k, feature.label).FontSize(buildFont).Color(b.text).Shrink(1).Ellipsis()
w.infoButton(k.Part("help"), feature.help)
Expand All @@ -510,7 +514,7 @@ func (w *window) patternList(c ui.C, language i18n.Language, draft *steppingDraf
remove := -1
for index, pattern := range draft.patterns {
k := c.KeyInt(index)
ui.Row(k).FillWidth().MinWidth(0).PadX(8).PadY(5).Gap(8).Items(ui.Center).Hover(ui.Look{}.Background(b.hover)).Children(func() {
ui.Row(k).FillWidth().MinWidth(0).PadX(8).PadY(5).Gap(8).Items(ui.Center).Children(func() {
ui.Text(k, pattern).FontSize(buildMono).Mono().Color(b.text).Grow(1).Shrink(1).MinWidth(0).Ellipsis()
if w.iconButton(k.Part("remove"), icons.X, i18n.Shared(language, "desktop.buildSettings.removePattern"), s.saving) {
remove = index
Expand Down
6 changes: 6 additions & 0 deletions desktop/internal/settingswindow/visual_capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func TestVisualSettings(t *testing.T) {
},
SetSteppingFilters: func(string, *core.DebugSteppingFilters) {},
}
if scenario.id == "20-settings-general" {
opts.WorkbenchBackground = func(i18n.Language) WorkbenchBackground {
return WorkbenchBackground{Set: true, Status: "fixture.png", Strength: "subtle",
Image: gfx.Bitmap{Width: 1, Height: 1, Stride: 4, ID: 1 << 62, Pix: []byte{72, 116, 158, 255}}}
}
}
opts.SetAutoUpdatePlugins = func(bool) {}
values := Values{Theme: theme, Language: language.Code(), TerminalScrollback: 2000, AutoUpdatePlugins: scenario.id == "m42-plugin-auto-update-on"}
if scenario.id == "29-marketplace-recommendations" {
Expand Down
2 changes: 1 addition & 1 deletion desktop/internal/settingswindow/window_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func (w *window) generalPage(c ui.C) {
w.cliCard(c)
w.card(c, settings.Appearance, settings.AppearanceHelp, func() {
choice := func() {
ui.Choice(c, &w.themePick, themeValues[:], w.themeLabel).Width(420).Shrink(1).MinWidth(0).Label(settings.AppearanceMode)
ui.Choice(c, &w.themePick, themeValues[:], w.themeLabel).Width(420).Shrink(1).MinWidth(0)
}
narrow := w.extent-2*contentPad-2*cardPad < 460
if narrow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (w *window) workbenchBackgroundRows(c ui.C, narrow bool) {
strength := func() {
ui.Choice(c.Part("background-strength"), &w.backgroundStrengthPick, workbenchBackgroundStrengths, func(value string) string {
return workbenchBackgroundStrengthLabel(language, value)
}).Width(420).Shrink(1).MinWidth(0).Label(visibility)
}).Width(420).Shrink(1).MinWidth(0)
}
if narrow {
ui.Column(c).FillWidth().Gap(8).PadY(6).Children(func() {
Expand Down
188 changes: 112 additions & 76 deletions desktop/internal/workbench/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,20 +1151,7 @@ func (a *App) Run() error {
})
a.stopPluginAutoUpdates()
a.windowLoopEnded(err, faulted.Load())
for _, session := range a.sessions.everyOne() {
session.unsubscribeSettings()
session.stopWatchingDiagnostics()
session.closeProject()
session.wait()
if session.pluginDownloads != nil {
session.recordPluginInstallCleanup(context.Background(), session.pluginDownloads.Close())
}
if session.plugins != nil && session.plugins.Runs != nil {
// Runs of the closed project are already stopped; this ends any the
// project close did not own and refuses new ones during shutdown.
session.plugins.Runs.StopAll()
}
}
a.shutdownSessions()
if a.kernel != nil {
// Every tab shares the kernel: this ends the remote sessions no closed project ended,
// such as one the Remote Development window had open, and refuses new ones.
Expand All @@ -1180,6 +1167,52 @@ func (a *App) Run() error {
return err
}

const (
// Give plugin shutdown calls their own deadline before abandoning the final wait.
shutdownWait = pluginServerStopTimeout + 5*time.Second
shutdownWaitOperation = "workbench_shutdown_wait"
)

// shutdownSessions runs after Viva returns, when no window can deliver a save or
// confirmation callback. The normal close requests finish those steps while the
// window is alive. Any project still present here needs resource teardown and
// recovery checkpoints for its unsaved documents.
func (a *App) shutdownSessions() {
sessions := a.sessions.everyOne()
for _, session := range sessions {
session.unsubscribeSettings()
session.stopWatchingDiagnostics()
session.closingProject = false
if p := session.project; p != nil {
session.disposeProject(p)
}
session.closePluginDownloads()
if session.plugins != nil && session.plugins.Runs != nil {
runs := session.plugins.Runs
// End runs that no project owned and refuse new ones during shutdown.
session.background(nil, 0, func(context.Context) func(*App) {
runs.StopAll()
return nil
})
}
}

done := make(chan struct{})
go func() {
defer close(done)
for _, session := range sessions {
session.wait()
}
}()
timer := time.NewTimer(shutdownWait)
defer timer.Stop()
select {
case <-done:
case <-timer.C:
a.backgroundFailed(shutdownWaitOperation, context.DeadlineExceeded)
}
}

// watchFaults has Viva hand each panic it recovers in a callback to the client's log, as
// app.runtime.panic_interrupted under the boundary viva:<where>. Viva calls the handler on the
// panicking thread, which may hold the framework's locks, so it only records and sets the
Expand Down Expand Up @@ -1235,13 +1268,12 @@ func (a *App) systemAppearanceChanged() {
})
}

// closed runs when the window has closed: the project closes, and so does the log window,
// which would otherwise keep the application running without the window it belongs to.
// closed releases auxiliary windows. Project close requests run before OnClosed,
// and shutdownSessions takes care of projects left over when the loop returns.
func (a *App) closed() {
a.unsubscribeSettings()
a.closeClone()
a.closeNewProject()
a.closeProject()
a.closeSettingsWindow()
a.stopUpdates()
}
Expand Down Expand Up @@ -1737,64 +1769,68 @@ func (a *App) finishCloseProject(p *project, after func()) {
if a.project != p {
return
}
{
a.saveEditorSession(p)
a.closePluginViews(p)
a.releaseIndexing(p)
a.closeEverywhere(p)
a.recentFiles.open = false
a.recentFiles.generation++
a.recentFiles.lastEdited = 0
a.recentFiles.list = nil
a.recentFiles.listState = ui.ListState{}
a.drafts.open, a.drafts.loading = false, false
a.drafts.generation++
a.drafts.entries = nil
a.drafts.list = ui.ListState{}
if a.navigation.open && a.navigation.project == p {
a.closeNavigation()
}
a.cancelPrompts()
a.ideAPIDisable(p)
a.closeRemoteWorkspace(p)
p.cancel()
a.closePluginPages()
a.closePreviewPages()
a.closeTree(p)
a.closeGitObservation(p)
a.releaseProjectSearch(p)
a.closeDocuments(p)
p.closeDiffs()
a.closeTerminals(p)
// A test run owns a process or provider request, so it is stopped before
// the build providers it borrowed close.
a.stopTestsForProject(p)
a.stopDebugForProject(p)
a.stopRunsForProject(p)
// Build providers and prepared applications belong to the workspace and
// are stopped before the project state is dropped.
a.stopBuild(p)
// Version control provider sessions run in the workspace too.
a.stopVcs(p)
// A language server is bound to the workspace it was started for, so it goes
// with the project rather than outliving it.
a.stopAllPluginServers()
a.clearAllPluginDiagnostics()
a.problems.reset()
a.toolchainRoot.Store(nil)
a.project = nil
a.ideAPISetProject(nil)
a.focus = focusTarget{}
a.dnd.tool.Cancel()
a.dnd.tab.Cancel()
a.drag, a.term.drag = dragState{}, tabDrag{}
a.title = titleState{}
a.branch.branchSession = branchSession{}
if after != nil {
after()
} else {
// A project closed on its own leaves its tab when the window has others.
a.sessions.leave(a)
}
a.disposeProject(p)
if after != nil {
after()
} else {
// A project closed on its own leaves its tab when the window has others.
a.sessions.leave(a)
}
}

// disposeProject releases a project after close approval or after the window
// loop has returned. It does not ask questions or switch tabs.
func (a *App) disposeProject(p *project) {
a.saveEditorSession(p)
a.closePluginViews(p)
a.releaseIndexing(p)
a.closeEverywhere(p)
a.recentFiles.open = false
a.recentFiles.generation++
a.recentFiles.lastEdited = 0
a.recentFiles.list = nil
a.recentFiles.listState = ui.ListState{}
a.drafts.open, a.drafts.loading = false, false
a.drafts.generation++
a.drafts.entries = nil
a.drafts.list = ui.ListState{}
if a.navigation.open && a.navigation.project == p {
a.closeNavigation()
}
a.cancelPrompts()
a.ideAPIDisable(p)
a.closeRemoteWorkspace(p)
p.cancel()
a.closePluginPages()
a.closePreviewPages()
a.closeTree(p)
a.closeGitObservation(p)
a.releaseProjectSearch(p)
a.closeDocuments(p)
p.closeDiffs()
a.closeTerminals(p)
// A test run owns a process or provider request, so it is stopped before
// the build providers it borrowed close.
a.stopTestsForProject(p)
a.stopDebugForProject(p)
a.stopRunsForProject(p)
// Build providers and prepared applications belong to the workspace and
// are stopped before the project state is dropped.
a.stopBuild(p)
// Version control provider sessions run in the workspace too.
a.stopVcs(p)
// A language server is bound to the workspace it was started for, so it goes
// with the project rather than outliving it.
a.stopAllPluginServers()
a.clearAllPluginDiagnostics()
a.problems.reset()
a.toolchainRoot.Store(nil)
a.project = nil
a.ideAPISetProject(nil)
a.focus = focusTarget{}
a.dnd.tool.Cancel()
a.dnd.tab.Cancel()
a.drag, a.term.drag = dragState{}, tabDrag{}
a.title = titleState{}
a.branch.branchSession = branchSession{}
}
6 changes: 4 additions & 2 deletions desktop/internal/workbench/editor_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (a *App) enqueueCheckpoint(job checkpoint) {
}
writer.running = true
writer.mu.Unlock()
a.background(nil, 0, func(context.Context) func(*App) {
a.background(nil, 0, func(ctx context.Context) func(*App) {
for {
writer.mu.Lock()
var next checkpoint
Expand Down Expand Up @@ -132,7 +132,9 @@ func (a *App) enqueueCheckpoint(job checkpoint) {
}
}
if err != nil {
a.post(func(a *App) { a.recoveryFailed(err) })
// The shutdown checkpoint may finish after the window stops draining.
a.operationFailedIn(ctx, "editor_recovery", documentLogError(err))
a.post(func(a *App) { a.notifyError(i18n.Shared(a.language(), "desktop.drafts.failed")) })
}
if next.after != nil {
a.post(next.after)
Expand Down
Loading
Loading