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
Expand Up @@ -4,29 +4,40 @@

## 先说结论

分段控件用各选项声明的名称提供无障碍命中,多行输入与列表行只使用组件支持的属性。窗口循环返回时,工作台直接取消仍然存在的项目并写入恢复草稿。正常关窗时的保存和确认仍在窗口循环内完成。
分段控件用各选项声明的名称提供无障碍命中,多行输入与列表行只使用组件支持的属性。控件的名字必须交给实际创建身份的容器或控件;右键菜单沿用目标身份,普通文字、图标和留白不接收名字。窗口循环返回时,工作台直接取消仍然存在的项目并写入恢复草稿。正常关窗时的保存和确认仍在窗口循环内完成。

## 问题

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

2026-11-23 的严格校验还暴露了另一类旧调用:工作台活动栏在声明右键菜单时传入 `c.Part("menu").KeyInt(i)`,菜单没有使用这个待处理的名字,后面的留白 `Spacer` 因而报错。可选组件提前返回、给文字和图标命名也会留下同样的问题。固定版本的 Viva 文本视图内部也曾给关闭的菜单命名,组织 fork 的同步 PR [#58](https://github.com/Lithe-IDEA/Lithe-viva/pull/58) 已采用上游修复,桌面端固定到包含该修复的 fork `main` 提交。

## 决策

- 外观、背景强度与通用插件分段控件以选项名称命中。调试器行只在获得 ID 的绘制阶段使用悬停样式,静态容器保持原有命中范围。运行配置多行输入移除框架忽略的等宽属性。
- 外观、背景强度与通用插件分段控件以选项名称命中。运行配置多行输入继续使用框架支持的属性;原来的 `Mono` 没有参与多行输入的排版,删除它不等于实现了等宽编辑。
- 调试器列表行只在获得身份标识(ID)的绘制阶段使用悬停样式。过滤模式行与功能开关行通过 `HitWith` 声明不获取键盘焦点的分组命中,再声明悬停样式;行内按钮、开关和帮助仍各自命中,不增加 Tab 停靠点。
- `Key`、`KeyInt` 和 `Part` 设置的是下一个元素待使用的名字,共用的 `ui.C` 不会因此创建子作用域。名字放在真实容器或控件上;只有容器的 `Children` 才建立其中元素的作用域。先判断可选组件是否可见,再给其真实元素命名,避免提前返回后把名字交给下一个兄弟元素。
- `ContextMenu` 沿用目标身份,不消费新的名字;`Menu`、`MenuAt`、`ContextMenuAt`、`ModalWith` 和 `PopoverWith` 则仅在打开时创建绑定作用域并消费名字,关闭时会直接返回。调用这些可关闭的组件时,先判断打开状态,再按需命名。`Effect` 使用自己的状态与键,不消费 UI 名字。无身份的 `Text`、`Icon`、`Spacer` 等叶子直接使用当前上下文。例如 `ui.ContextMenu(c, button, items)` 是正确写法;不要写成 `ui.ContextMenu(c.Part("menu"), button, items)`,也不要给后面的留白加容器掩盖遗留名字。
- 通用插件视图用 `NodeKey` 值保存声明节点的 ID 或位置,不预先修改 UI 上下文。宿主确认 setting/tool 行可绘制、输入或选择绑定类型匹配后,才把名字交给实际行;label 无身份。这样缺失行或不可用绑定可以直接跳过,不会把自己的名字留给下一个节点。
- 远程主机详情等可选内容先判断非空,再创建具名容器;跳板路由的图标和文本保持匿名。表格的分隔线与数据行分开声明,数据行不因先绘制分隔线而丢失自己的名字。
- 正常关闭经用户确认后进入项目资源释放。窗口循环返回后直接复用资源释放,先取消各项目及其服务器,再等待后台任务。未保存的编辑内容按现有恢复存储规则落盘。
- 退出等待给插件服务器的停止期限留出余量。超过总期限后记录已有的后台失败事件。恢复草稿写入错误在后台写入点记录,提示仍通过界面队列发送。

## 考虑过的备选方案

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

把 `VIVA_ATTR_CHECK` 设为 `warn`、给空白额外套容器、在应用侧清除待处理名字,都只会隐藏错误调用。因此保持 dev 严格校验并修改声明位置;框架内部的同类问题使用上游已经合入 fork 的修复。

## 后果

项目取消、恢复写入和进程收尾不需要等待下一帧。若后台工作无法在总期限内结束,日志会记录超时,应用继续退出。
项目取消、恢复写入和进程收尾不需要等待下一帧。若后台工作无法在总期限内结束,日志会记录超时,应用继续退出。界面迁移保留原有布局、文字和动作;少量被动分组命中用于恢复原本想表达的行悬停,需要验证其不会接管行内控件。

## 验证

- 在严格 dev 属性校验下运行设置页及合成插件分段控件测试。
- 在严格 dev 属性校验下运行工作台、设置页及合成插件界面测试。`TestWorkbenchContextMenusKeepButtonIdentityAcrossRepaints` 用真实 Core 与隔离存储检查菜单打开、关闭、窗口缩放后的按钮身份稳定;覆盖深色中文和浅色英文。
- `TestDebuggersPageAppliesAndRestoresAnAdaptersFilters` 检查行悬停绘制、不进入键盘焦点顺序,以及应用、恢复默认和删除模式。视觉用例 `TestVisualWorkbenchStripeContextMenu` 与 `TestVisualSettings` 的调试器悬停场景生成当前实现的截图;调试器场景的数据明确是合成组件输入,不代表已安装插件验收。
- `TestRegionViewSkipsUnavailableNodesWithoutRenamingTheirNeighbors` 用内联合成设置验证缺失行和不匹配绑定,修复前严格校验在后续文本上报告 `Key 0`;`TestRemoteProbeWithoutDetailsKeepsFollowingTextAnonymous` 在空主机详情下复现遗留 `Part "tags"`;`TestRemoteJumpRouteRepaintsWithMultipleHosts` 在多跳路由下复现图标收到 `Key 0`。三者均在修复后通过,并覆盖重绘或后续兄弟元素。运行配置表单的未知控件与多个错误回归由 `TestRunConfigFormOptionalErrorsKeepTheirOwnIdentity` 覆盖。
- 用合成语言服务器覆盖普通项目关闭检查尚未回到窗口线程就结束窗口循环的情况,检查服务器取消、恢复草稿写入和原文件未改动。

## 适用范围
Expand All @@ -35,3 +46,9 @@
- `desktop/internal/pluginview/render.go`
- `desktop/internal/workbench/app.go`
- `desktop/internal/workbench/editor_recovery.go`
- `desktop/internal/workbench/chrome_view.go`
- `desktop/internal/workbench/runconfig_dialog_view.go`
- `desktop/internal/workbench/remote_detail_view.go`
- `desktop/internal/workbench/remote_list.go`
- `desktop/internal/workbench/remote_import.go`
- `desktop/go.mod`
69 changes: 41 additions & 28 deletions desktop/internal/pluginview/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ type Host struct {
type SettingsHost interface {
// Row draws the page's own row for a declared setting, exactly as the page draws it.
// It reports false when the page has no such row.
Row(c ui.C, setting string) bool
Row(c ui.C, setting string, key NodeKey) bool
// Tool draws the toolchain pages' row for a tool the plugin defines or requires; with
// choose the row is also the tool's picker, whose choice edits the page's toolchain
// draft. It reports false when the host has no row for it.
Tool(c ui.C, tool string, choose bool) bool
Tool(c ui.C, tool string, choose bool, key NodeKey) bool
// Binding is the draft of a declared setting for a control bound to it.
Binding(setting string) (Binding, bool)
// Action runs a setting action through the page's confirmation flow. It runs
Expand Down Expand Up @@ -64,6 +64,22 @@ type Binding struct {
Edited func()
}

// NodeKey names a view node by ID or position without changing the current UI
// context. A host applies it only after it knows the node has a row to draw.
type NodeKey struct {
id string
index int
}

// Apply names the container or control declared next. Do not call it on a path
// that can return without drawing that element.
func (k NodeKey) Apply(c ui.C) ui.C {
if k.id != "" {
return c.Key("#" + k.id)
}
return c.KeyInt(k.index)
}

// Draw declares a view in the space its parent gives it. In a tool window the view fills
// the body (fill), and a tree among its top-level nodes takes the height the others leave;
// a tree in a row or a section takes the height of its rows, up to treeRows. In a settings
Expand Down Expand Up @@ -194,20 +210,17 @@ func (r *renderer) failure(err error) (message, detail string) {
return i18n.Shared(language, "desktop.pluginView.failed"), err.Error()
}

// nodes declares nodes in order, each keyed by its ID or its place.
// nodes declares nodes in order. Containers and controls are keyed by ID or place;
// labels are leaves without identity.
func (r *renderer) nodes(c ui.C, nodes []Node) {
for i := range nodes {
n := &nodes[i]
key := c.KeyInt(i)
if n.ID != "" {
key = c.Key("#" + n.ID)
}
r.node(key, n)
r.node(c, n, NodeKey{id: n.ID, index: i})
}
}

// node declares one node.
func (r *renderer) node(c ui.C, n *Node) {
func (r *renderer) node(c ui.C, n *Node, key NodeKey) {
p := &r.host.Palette
switch n.Type {
case "row", "section":
Expand All @@ -219,9 +232,9 @@ func (r *renderer) node(c ui.C, n *Node) {
}
switch n.Type {
case "row":
ui.Flow(c).FillWidth().Items(ui.Center).Gap(8).LineGap(6).Children(func() { r.nodes(c, n.Children) })
ui.Flow(key.Apply(c)).FillWidth().Items(ui.Center).Gap(8).LineGap(6).Children(func() { r.nodes(c, n.Children) })
case "section":
ui.Column(c).FillWidth().Gap(6).Children(func() {
ui.Column(key.Apply(c)).FillWidth().Gap(6).Children(func() {
if n.Title != "" {
ui.Row(c).FillWidth().MinHeight(28).Items(ui.Center).Gap(8).Children(func() {
ui.Text(c, n.Title).FontSize(13).Weight(gfx.WeightSemibold).Color(p.Text).Shrink(1).MinWidth(0).Ellipsis()
Expand All @@ -233,34 +246,34 @@ func (r *renderer) node(c ui.C, n *Node) {
case "label":
r.label(c, n)
case "textField":
r.textField(c, n)
r.textField(c, n, key)
case "select", "segmented":
r.choice(c, n)
r.choice(c, n, key)
case "toggle":
r.toggle(c, n)
r.toggle(c, n, key)
case "button":
r.button(c, n)
r.button(key.Apply(c), n)
case "keyValue":
r.keyValue(c, n)
r.keyValue(key.Apply(c), n)
case "table":
r.table(c, n)
r.table(key.Apply(c), n)
case "banner":
tone := p.Tone(n.Tone, p.Accent)
ui.Row(c).FillWidth().PadX(10).PadY(8).Radius(6).Background(tone.WithAlpha(0.10)).Border(1, tone.WithAlpha(0.35)).Children(func() {
ui.Row(key.Apply(c)).FillWidth().PadX(10).PadY(8).Radius(6).Background(tone.WithAlpha(0.10)).Border(1, tone.WithAlpha(0.35)).Children(func() {
ui.Wrap(c, n.Text).FontSize(12).Color(p.Text).Grow(1).MinWidth(0)
})
case "setting":
if r.host.Settings != nil {
r.host.Settings.Row(c, n.Setting)
r.host.Settings.Row(c, n.Setting, key)
}
case "tool":
if r.host.Settings != nil {
r.host.Settings.Tool(c, n.Tool, n.Choose)
r.host.Settings.Tool(c, n.Tool, n.Choose, key)
}
case "tree":
r.tree(c, n)
r.tree(key.Apply(c), n)
case "canvas":
r.canvas(c, n)
r.canvas(key.Apply(c), n)
}
}

Expand Down Expand Up @@ -357,7 +370,7 @@ func (r *renderer) changed(n *Node, binding Binding, bound bool, value any) {

// textField declares a text field. It commits on Enter or when it loses the focus with
// text that differs from what it last sent, never per keystroke.
func (r *renderer) textField(c ui.C, n *Node) {
func (r *renderer) textField(c ui.C, n *Node, key NodeKey) {
binding, bound := r.binding(n)
if n.Setting != "" && (!bound || binding.Text == nil) {
return
Expand All @@ -379,7 +392,7 @@ func (r *renderer) textField(c ui.C, n *Node) {
}
enabled := n.enabled() && (!bound || binding.Editable)
count, fillWidth := n.characters()
row := ui.Row(c).Items(ui.Center).Gap(8).MinWidth(0)
row := ui.Row(key.Apply(c)).Items(ui.Center).Gap(8).MinWidth(0)
if fillWidth || count == 0 {
row = row.Grow(1).Basis(0)
}
Expand Down Expand Up @@ -433,7 +446,7 @@ func (r *renderer) readOnly(c ui.C, label, value string, count int, fillWidth, m
// choice declares a select or segmented control, over its own options or a bound enum's.
// A control that takes no input is the read-only frame the settings pages draw, since
// Disabled does not reach a Select or Choice in pinned Viva.
func (r *renderer) choice(c ui.C, n *Node) {
func (r *renderer) choice(c ui.C, n *Node, key NodeKey) {
binding, bound := r.binding(n)
if n.Setting != "" && (!bound || binding.Selected == nil) {
return
Expand All @@ -443,7 +456,7 @@ func (r *renderer) choice(c ui.C, n *Node) {
if bound && label == "" {
label = binding.Title
}
ui.Row(c).Items(ui.Center).Gap(8).MinWidth(0).Children(func() {
ui.Row(key.Apply(c)).Items(ui.Center).Gap(8).MinWidth(0).Children(func() {
r.caption(c, n.Label, n.Info)
if bound {
if !enabled {
Expand Down Expand Up @@ -492,7 +505,7 @@ func optionsOf(options []Option) ([]string, map[string]string) {
}

// toggle declares a switch with its label on the leading side.
func (r *renderer) toggle(c ui.C, n *Node) {
func (r *renderer) toggle(c ui.C, n *Node, key NodeKey) {
binding, bound := r.binding(n)
if n.Setting != "" && (!bound || binding.On == nil) {
return
Expand All @@ -502,7 +515,7 @@ func (r *renderer) toggle(c ui.C, n *Node) {
if bound && label == "" {
label = binding.Title
}
ui.Row(c).Items(ui.Center).Gap(8).MinWidth(0).Children(func() {
ui.Row(key.Apply(c)).Items(ui.Center).Gap(8).MinWidth(0).Children(func() {
r.caption(c, n.Label, n.Info)
on := binding.On
if !bound {
Expand Down
2 changes: 1 addition & 1 deletion desktop/internal/settingswindow/command_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (w *window) commandMissingStatus(c ui.C, language i18n.Language, fact Plugi
// commandMissingBanner shows, above the cards, the missing launches no card shows.
func (w *window) commandMissingBanner(c ui.C, language i18n.Language, fact PluginFacts, missing []MissingCommand) {
for index, entry := range missing {
k := c.KeyInt(index)
k := c.Key("command-missing:" + strconv.Itoa(index))
ui.Row(k).FillWidth().Gap(8).Pad(10).Radius(8).Items(ui.Center).Stroke(1, w.pal.line).Background(w.pal.card).Children(func() {
ui.Wrap(c, i18n.SharedFormat(language, "desktop.plugins.commandMissingBanner", map[string]string{"commands": commandList(entry.Commands)})).
FontSize(12).Color(w.pal.warning).Grow(1).Shrink(1).MinWidth(0)
Expand Down
2 changes: 1 addition & 1 deletion desktop/internal/settingswindow/installed_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ func (w *window) installedFeatures(c ui.C, language i18n.Language, fact PluginFa
var missing []MissingCommand
if enabled {
missing = w.commands.want(fact.ID)
w.commandMissingBanner(c.Part("command-missing"), language, fact, unmatchedMissing(missing, fact.Capabilities))
w.commandMissingBanner(c, language, fact, unmatchedMissing(missing, fact.Capabilities))
}
ui.Grid(c, 220).FillWidth().Gap(10).Children(func() {
for index, capability := range fact.Capabilities {
Expand Down
8 changes: 4 additions & 4 deletions desktop/internal/settingswindow/plugin_region_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ func (s regionSettings) row(setting string) int {
return -1
}

func (s regionSettings) Row(c ui.C, setting string) bool {
func (s regionSettings) Row(c ui.C, setting string, key pluginview.NodeKey) bool {
index := s.row(setting)
if index < 0 {
return false
}
s.w.pluginSettingRow(c, index, s.hasSource)
s.w.pluginSettingRow(key.Apply(c), index, s.hasSource)
return true
}

Expand All @@ -227,7 +227,7 @@ func (s regionSettings) toolScope(t *toolchainState) *toolchainScope {
// Tool draws the toolchains list's row for the tool, in the toolchain scope beside the scope
// the page shows. Pressing it opens the Toolchains page in that scope with the tool chosen;
// with choose, a tool the user may pin opens its picker instead (toolPicker).
func (s regionSettings) Tool(c ui.C, tool string, choose bool) bool {
func (s regionSettings) Tool(c ui.C, tool string, choose bool, key pluginview.NodeKey) bool {
w := s.w
t := w.toolchains
if t == nil || !t.available() {
Expand All @@ -250,7 +250,7 @@ func (s regionSettings) Tool(c ui.C, tool string, choose bool) bool {
fresh := scope.tool(tool)
picks := choose && v != nil && fresh != nil && !fresh.ManagedOnly
open := picks && v.picker == tool
row := ui.ButtonBase(c, entry.tool.DisplayName).FillWidth().Height(toolchainToolRow).PadSides(0, 12, 0, 14).
row := ui.ButtonBase(key.Apply(c), entry.tool.DisplayName).FillWidth().Height(toolchainToolRow).PadSides(0, 12, 0, 14).
Gap(9).Items(ui.Center).Radius(6).Border(1, b.line).Hover(ui.Look{}.Background(b.hover))
if open {
row = row.Border(1, b.accent)
Expand Down
51 changes: 51 additions & 0 deletions desktop/internal/settingswindow/plugin_region_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,57 @@ func regionSettingsParam(t *testing.T, call regionCall) (effective, draft map[st
return effective, draft
}

// A region can refer to a setting or tool the current page cannot draw. These
// synthetic nodes exercise the real settings host, including missing bindings
// and bindings of the wrong kind; the following label must keep drawing.
func TestRegionViewSkipsUnavailableNodesWithoutRenamingTheirNeighbors(t *testing.T) {
for _, node := range []string{
`{"type":"setting","setting":"missing"}`,
`{"type":"tool","tool":"missing"}`,
`{"type":"textField","id":"missing","setting":"missing"}`,
`{"type":"select","id":"missing","setting":"name"}`,
`{"type":"segmented","id":"missing","setting":"name"}`,
`{"type":"toggle","id":"missing","setting":"name"}`,
} {
var kind struct{ Type string }
if err := json.Unmarshal([]byte(node), &kind); err != nil {
t.Fatal(err)
}
t.Run(kind.Type, func(t *testing.T) {
source := &regionSource{calls: make(chan regionCall, 32), view: json.RawMessage(`[` + node + `,
{"type":"label","text":"Region is available"},
{"type":"label","text":"Available controls follow"},
{"type":"button","id":"probe","text":"Probe"}]`)}
fetch := func(context.Context) (marketplace.Snapshot, error) {
return marketplace.Snapshot{Index: core.MarketplaceIndex{Plugins: []core.MarketplacePlugin{{ID: regionPlugin, Name: "Region Fixture", LatestVersion: "1.0.0"}}}}, nil
}
w := newWindow(NewController(Options{
Text: func() *i18n.Messages { return i18n.For(i18n.English) },
Marketplace: fetch, MarketplaceInstalled: fetch, PluginSettings: source,
PluginState: func(string) PluginState { return PluginState{Installed: true, Enabled: true, Version: "1.0.0"} },
InstalledPlugins: func() []PluginFacts {
return []PluginFacts{{ID: regionPlugin, Name: "Region Fixture", Version: "1.0.0", Settings: len(regionEditor().Snapshot.State.Rows)}}
},
}), Values{Theme: "dark"})
w.sess.page = pagePlugins
w.installed.tab = installedSettings
d := openWindow(t, w)
d.until("the region after its unavailable node", func() bool { return d.text("Region is available") && d.has("Probe") })
probe := d.hit("Probe").ID
if event := source.next(t); event.params["event"] != "open" {
t.Fatalf("the region opened with %v", event.params)
}
d.click("Probe")
if got := d.hit("Probe").ID; got != probe {
t.Fatalf("the neighboring button changed identity: %v -> %v", probe, got)
}
if event := source.next(t); event.params["event"] != "click" || event.params["node"] != "probe" {
t.Fatalf("the neighboring button sent %v, want its click", event.params)
}
})
}
}

// A region opens with the plugin's own Settings tab and carries the page's settings, a
// changed draft rides on the next event, and the view closes when the tab is left or the
// language changes, opening anew when it shows again.
Expand Down
Loading
Loading