diff --git a/desktop/internal/core/problems.go b/desktop/internal/core/problems.go index 4461b85d19..4892751c2b 100644 --- a/desktop/internal/core/problems.go +++ b/desktop/internal/core/problems.go @@ -62,12 +62,16 @@ const ( ) // ProblemsQuery is one Problems tool-window query. The empty GroupBy and SortBy -// ask for Core's defaults: group by file, sort by severity. +// ask for Core's defaults: group by file, sort by severity. Collapsed and Selected +// are the tree state the window keeps: the keys of the group nodes the user +// closed and the selected row's key. type ProblemsQuery struct { Diagnostics []ProblemsDiagnostic `json:"diagnostics"` GroupBy string `json:"groupBy,omitempty"` SortBy string `json:"sortBy,omitempty"` Filter *ProblemsFilter `json:"filter,omitempty"` + Collapsed []string `json:"collapsed,omitempty"` + Selected string `json:"selected,omitempty"` } // ProblemsGroup is one group of a Problems query result. Indices point into the @@ -79,6 +83,10 @@ type ProblemsGroup struct { Kind string `json:"kind"` FileKey string `json:"fileKey,omitempty"` DisplayPath string `json:"displayPath,omitempty"` + // Name and Folder are a file group's DisplayPath split at its last segment; + // Folder is empty at the workspace root. + Name string `json:"name,omitempty"` + Folder string `json:"folder,omitempty"` // Severity is the group's LSP severity for a severity group; 0 is the // unknown-severity group. Severity int `json:"severity,omitempty"` @@ -96,12 +104,39 @@ type ProblemsFile struct { Counts ProblemsSeverityCounts `json:"counts"` } -// ProblemsResult is Core's filtered, ordered and grouped Problems list. +// The kinds of a Problems row. +const ( + ProblemsRowGroup = "group" + ProblemsRowDiagnostic = "diagnostic" +) + +// ProblemsRow is a row of the Problems tree that shows. +type ProblemsRow struct { + // Key stays the row's while nodes open and close, and a diagnostic's key + // stays its own when the server republishes the list in another order. + Key string `json:"key"` + Kind string `json:"kind"` + Depth int `json:"depth"` + // Expanded is whether a node's diagnostics show; nil on a diagnostic. + Expanded *bool `json:"expanded,omitempty"` + // Group is the row's group. + Group int `json:"group"` + // Shows is the diagnostic the row previews and opens: itself or a node's first. + Shows int `json:"shows"` +} + +// ProblemsResult is Core's filtered, ordered and grouped Problems list and the +// tree rows that show it. type ProblemsResult struct { Groups []ProblemsGroup `json:"groups"` Files []ProblemsFile `json:"files"` VisibleCounts ProblemsSeverityCounts `json:"visibleCounts"` TotalCounts ProblemsSeverityCounts `json:"totalCounts"` + Rows []ProblemsRow `json:"rows"` + // Selected is the selected row's key, always one of Rows, and SelectedRow its + // place; both are absent when nothing is selected. + Selected string `json:"selected,omitempty"` + SelectedRow *int `json:"selectedRow,omitempty"` } // QueryProblems asks Core to filter, order and group the displayed diagnostics. diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index d0a488c8d9..5895784881 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1210,12 +1210,24 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.problems.group.file": "By file", "desktop.problems.group.none": "No grouping", "desktop.problems.group.severity": "By severity", - "desktop.problems.groupBy": "Group: {arg1}", + "desktop.problems.groupHeading": "Group By", + "desktop.problems.noOpenFile": "No file is open.", "desktop.problems.previewEmpty": "Select a problem to preview its source.", + "desktop.problems.scope.file": "File", + "desktop.problems.scope.fileCount": "File {count}", + "desktop.problems.scope.project": "Project", + "desktop.problems.scope.projectCount": "Project {count}", + "desktop.problems.severity.error": "Errors", + "desktop.problems.severity.hint": "Hints", + "desktop.problems.severity.information": "Information", + "desktop.problems.severity.unknown": "Unknown severity", + "desktop.problems.severity.warning": "Warnings", "desktop.problems.showErrors": "Errors", + "desktop.problems.showHeading": "Show", "desktop.problems.showInfo": "Information", "desktop.problems.showPreview": "Show Editor Preview", "desktop.problems.showWarnings": "Warnings", + "desktop.problems.viewOptions": "View Options", "desktop.process.forceStop": "Force Stop", "desktop.project.empty": "Empty folder", "desktop.project.expandAllIncomplete": "Some folders were not expanded: the project has too many.", @@ -4012,12 +4024,24 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.problems.group.file": "按文件", "desktop.problems.group.none": "不分组", "desktop.problems.group.severity": "按严重级别", - "desktop.problems.groupBy": "分组:{arg1}", + "desktop.problems.groupHeading": "分组", + "desktop.problems.noOpenFile": "没有打开的文件。", "desktop.problems.previewEmpty": "选择一个问题以预览源码。", + "desktop.problems.scope.file": "文件", + "desktop.problems.scope.fileCount": "文件 {count}", + "desktop.problems.scope.project": "项目", + "desktop.problems.scope.projectCount": "项目 {count}", + "desktop.problems.severity.error": "错误", + "desktop.problems.severity.hint": "提示", + "desktop.problems.severity.information": "信息", + "desktop.problems.severity.unknown": "未知严重级别", + "desktop.problems.severity.warning": "警告", "desktop.problems.showErrors": "错误", + "desktop.problems.showHeading": "显示", "desktop.problems.showInfo": "信息", "desktop.problems.showPreview": "显示编辑器预览", "desktop.problems.showWarnings": "警告", + "desktop.problems.viewOptions": "视图选项", "desktop.process.forceStop": "强制结束", "desktop.project.empty": "文件夹为空", "desktop.project.expandAllIncomplete": "项目文件夹太多,部分文件夹没有展开。", diff --git a/desktop/internal/workbench/problems.go b/desktop/internal/workbench/problems.go index b7159f6ce2..2557e8a43e 100644 --- a/desktop/internal/workbench/problems.go +++ b/desktop/internal/workbench/problems.go @@ -2,18 +2,32 @@ package workbench import ( "context" - "sort" + "slices" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) -// problemsView is the Problems tool window's cached Core answer. +// The Problems tool window, laid out the way IntelliJ IDEA's Problems tool window lays out its +// diagnostics: the header's tabs choose the current file or the whole project, each with the +// number of problems it holds; a tree holds a node per file over its diagnostics; a column of +// actions left of the tree holds the view options, opening and closing every node, and the +// preview, a read-only source view beside the tree that shows the selected diagnostic's line. // -// The list is asked for in the background, because Core filters and sorts every -// submitted diagnostic and the window thread must not do that work. generation -// rises on every change to the published diagnostics, so an answer computed from -// an older set is dropped instead of replacing the current list. +// Core filters, orders and groups the diagnostics, lays the visible rows out under the nodes +// the user closed, moves a selection that a closed node hides or that the server withdrew, and +// says which diagnostic each row shows (lsp.problems.query). This file keeps which nodes are +// closed and which row is selected, collects the published diagnostics, and opens a +// diagnostic's file at its position. + +// problemsView is the Problems tool window's cached Core answer and the tree state it was +// asked with. +// +// The tree is asked for in the background, because Core filters and sorts every submitted +// diagnostic and the window thread must not do that work. generation rises on every change to +// the published diagnostics and to the view's options or nodes, so an answer computed from an +// older state is dropped instead of replacing the current tree. type problemsView struct { generation uint64 // queried is the generation the cached answer was computed from. @@ -26,38 +40,54 @@ type problemsView struct { // into it. diagnostics []core.ProblemsDiagnostic result core.ProblemsResult - // starts holds the flat row index of each group. Group i spans starts[i] to - // starts[i]+1+len(indices). - starts []int - rows int - // failure is a query Core refused, shown in place of the list. It is cleared + // file is the current file the cached answer was asked for, empty when no file was open. + // fileCount and projectCount are how many problems the header's tabs count: the current + // file's and the project's, under the severity options. + file string + fileCount, projectCount int + // failure is a query Core refused, shown in place of the tree. It is cleared // by the next successful answer or by a project change. failure error - // show says the Show Editor Preview option is on: a read-only source view beside the list + // project says the Project tab is chosen; the File tab, the current file's problems, is + // chosen until then, as IDEA opens the window on it. + project bool + // collapsed holds the keys of the nodes the user closed, as Core names them. + collapsed map[string]bool + // selected is the key of the selected row and selectedRow its place in the answer's rows, -1 + // for none; asked is the key sent with the query in flight, so a selection the user makes + // meanwhile is kept over the one Core answers. reveal asks the next frame to scroll the + // selection into view. + selected string + selectedRow int + asked string + reveal bool + // focus is the keyboard focus the last frame saw, so only a move of it selects a row. + focus gfx.ID + view ui.TreeState + // optionsOpen says the View Options menu is open. + optionsOpen bool + // show says the Show Editor Preview option is on: a read-only source view beside the tree // shows the selected diagnostic's line. preview is that view. show bool preview sourcePreview - // split is the width of the list beside the preview; the user drags it. + // split is the width of the tree beside the preview; the user drags it. split ui.SplitterState // hideErrors, hideWarnings and hideInfo narrow the severities shown; a query sends them // as Core's severity filter. groupBy is Core's grouping: file, severity or none. hideErrors, hideWarnings, hideInfo bool groupBy string - // list is the scrolling list of the rows, kept with the answer so a project switch - // starts it at the top. - list ui.ListState } -// reset forgets the answer of the previous project. The view options are preferences, so they -// survive the project change; the preview itself is released. +// reset forgets the answer of the previous project. The view options and the chosen tab are +// preferences, so they survive the project change; the preview itself is released. func (v *problemsView) reset() { options := problemsView{show: v.show, split: v.split, hideErrors: v.hideErrors, hideWarnings: v.hideWarnings, - hideInfo: v.hideInfo, groupBy: v.groupBy} + hideInfo: v.hideInfo, groupBy: v.groupBy, project: v.project, selectedRow: -1} v.preview.close() *v = options } -// problemsSeverityFilter is the severity filter Core receives: nil keeps every severity, which is +// severityFilter is the severity filter Core receives: nil keeps every severity, which is // also what unchecking all three options shows. Hint severities are shown with information. func (v *problemsView) severityFilter() []int { if !v.hideErrors && !v.hideWarnings && !v.hideInfo || v.hideErrors && v.hideWarnings && v.hideInfo { @@ -76,33 +106,126 @@ func (v *problemsView) severityFilter() []int { return kept } -// rowAt locates one flat row: a group header when header is true, otherwise the -// diagnostic at indices[index] of the group. -func (v *problemsView) rowAt(row int) (group, index int, header bool) { - if row < 0 || row >= v.rows || len(v.starts) == 0 { - return 0, 0, false +// grouping is the grouping the tree is asked with; Core's default, by file, until the user +// chooses another. +func (v *problemsView) grouping() string { + if v.groupBy == "" { + return core.ProblemsGroupByFile + } + return v.groupBy +} + +// key is the Tree's key of visible row i: a node is its group's place, a diagnostic follows +// every node at its place in the submitted list, so a row keeps its key while the nodes above it +// open and close. +func (v *problemsView) key(i int) int { + r := v.result.Rows[i] + if r.Kind == core.ProblemsRowGroup { + return r.Group } - group = sort.Search(len(v.starts), func(i int) bool { return v.starts[i] > row }) - 1 - if group < 0 { - return 0, 0, false + return len(v.result.Groups) + r.Shows +} + +// node describes visible row i to the Tree. +func (v *problemsView) node(i int) ui.TreeNode { + r := v.result.Rows[i] + return ui.TreeNode{ + Depth: r.Depth, + Branch: r.Kind == core.ProblemsRowGroup, + Expanded: r.Expanded != nil && *r.Expanded, + Selected: i == v.selectedRow, } - offset := row - v.starts[group] - if offset == 0 { - return group, 0, true +} + +// rowOf is the visible row with key, or -1 when it does not show. +func (v *problemsView) rowOf(key string) int { + return slices.IndexFunc(v.result.Rows, func(r core.ProblemsRow) bool { return r.Key == key }) +} + +// selectRow selects the visible row with key; it is false when that row does not show. +func (v *problemsView) selectRow(key string) bool { + i := v.rowOf(key) + if i < 0 { + return false } - return group, offset - 1, false + v.selected, v.selectedRow = key, i + return true } -// markProblemsChanged records that the published diagnostics changed and asks for -// a repaint. The next Problems frame starts a query for the new set. +// shown is the diagnostic row i previews and opens: the diagnostic itself, or a node's first. +func (v *problemsView) shown(i int) (core.ProblemsDiagnostic, bool) { + if i < 0 || i >= len(v.result.Rows) { + return core.ProblemsDiagnostic{}, false + } + shows := v.result.Rows[i].Shows + if shows < 0 || shows >= len(v.diagnostics) { + return core.ProblemsDiagnostic{}, false + } + return v.diagnostics[shows], true +} + +// toggleProblemsNode opens or closes the node with key. Core moves the selection to the node +// when it was under it. +func (a *App) toggleProblemsNode(key string) { + v := &a.problems + if v.collapsed[key] { + delete(v.collapsed, key) + } else { + if v.collapsed == nil { + v.collapsed = map[string]bool{} + } + v.collapsed[key] = true + } + a.markProblemsChanged() +} + +// expandProblems opens or closes every node of the tree. A diagnostic that was selected hands +// the selection to its node when that node closes. +func (a *App) expandProblems(expanded bool) { + v := &a.problems + v.collapsed = nil + if !expanded { + v.collapsed = make(map[string]bool, len(v.result.Groups)) + for _, g := range v.result.Groups { + v.collapsed[g.Key] = true + } + } + v.reveal = true + a.markProblemsChanged() +} + +// chooseProblemsScope shows the current file's problems, or the project's when project is +// true. The nodes the user closed and the selection are kept where they still show. +func (a *App) chooseProblemsScope(project bool) { + v := &a.problems + if v.project == project { + return + } + v.project, v.reveal = project, true + a.markProblemsChanged() +} + +// problemsCurrentFile is the file of the selected editor tab, whose problems the File tab +// shows, and empty when no file is open. +func (a *App) problemsCurrentFile() string { + if d := a.selectedEditorDocument(); d != nil { + return d.path + } + return "" +} + +// markProblemsChanged records that the published diagnostics, or the options or nodes the +// tree is asked with, changed and asks for a repaint. The next Problems frame starts a query +// for the new state. func (a *App) markProblemsChanged() { a.problems.generation++ a.invalidator.Invalidate() } -// requestProblemsQuery starts a background query when the cached answer is older -// than the published diagnostics. At most one query runs at a time; a change -// that arrives meanwhile raises generation, and the next frame asks again. +// requestProblemsQuery starts a background query when the cached answer is older than the +// published diagnostics and the tree's state, or was asked for another current file. At most +// one query runs at a time; a change that arrives meanwhile raises generation, and the next +// frame asks again. func (a *App) requestProblemsQuery(p *project) { v := &a.problems if !a.chrome.isOpen(catalogIndex[itemProblems]) { @@ -110,17 +233,20 @@ func (a *App) requestProblemsQuery(p *project) { // asking now would refill the cache that closing released. return } - if v.querying || (v.loaded && v.queried == v.generation) { + file := a.problemsCurrentFile() + if v.querying || (v.loaded && v.queried == v.generation && v.file == file) { return } sets := a.pluginDiagnosticSets() generation := v.generation - groupBy := v.groupBy - if groupBy == "" { - groupBy = core.ProblemsGroupByFile + tree := core.ProblemsQuery{GroupBy: v.grouping(), Selected: v.selected} + for key := range v.collapsed { + tree.Collapsed = append(tree.Collapsed, key) } - severityFilter := v.severityFilter() - v.querying = true + slices.Sort(tree.Collapsed) + severities := v.severityFilter() + projectScope := v.project + v.querying, v.asked = true, v.selected a.background(p, kernelCallTimeout, func(ctx context.Context) func(*App) { diagnostics := make([]core.ProblemsDiagnostic, 0, 64) for _, set := range sets { @@ -137,43 +263,89 @@ func (a *App) requestProblemsQuery(p *project) { }) } } - query := core.ProblemsQuery{Diagnostics: diagnostics, GroupBy: groupBy} - if severities := severityFilter; severities != nil { - query.Filter = &core.ProblemsFilter{Severities: severities} + answer := problemsAnswer{generation: generation, file: file, diagnostics: diagnostics} + // The project's diagnostics under the severity options give both tabs their counts; + // on the Project tab the same answer is the tree. On the File tab the tree is asked + // for once more, narrowed to the current file, and there is none while no file is open. + whole := core.ProblemsQuery{Diagnostics: diagnostics, GroupBy: core.ProblemsGroupByNone, Filter: problemsFilter(severities, "")} + if projectScope { + whole.GroupBy, whole.Collapsed, whole.Selected = tree.GroupBy, tree.Collapsed, tree.Selected + } + result, err := a.kernel.QueryProblems(ctx, whole) + answer.err = err + if err == nil { + answer.projectCount = problemsTotal(result.VisibleCounts) + if i := slices.IndexFunc(result.Files, func(f core.ProblemsFile) bool { return f.FileKey == file }); file != "" && i >= 0 { + answer.fileCount = result.Files[i].Count + } + switch { + case projectScope: + answer.result = result + case file != "": + tree.Diagnostics, tree.Filter = diagnostics, problemsFilter(severities, file) + answer.result, answer.err = a.kernel.QueryProblems(ctx, tree) + } } - result, err := a.kernel.QueryProblems(ctx, query) - return func(a *App) { a.applyProblemsQuery(p, generation, diagnostics, result, err) } + return func(a *App) { a.applyProblemsQuery(p, answer) } }) } -// applyProblemsQuery takes one answer back on the window thread. An answer for -// a superseded generation is dropped, and a new frame asks for the newer set. -func (a *App) applyProblemsQuery(p *project, generation uint64, diagnostics []core.ProblemsDiagnostic, result core.ProblemsResult, err error) { +// problemsAnswer is one background query's answer: the tree for the chosen tab and the counts +// of both, computed from diagnostics at generation for the current file. +type problemsAnswer struct { + generation uint64 + file string + diagnostics []core.ProblemsDiagnostic + result core.ProblemsResult + fileCount, projectCount int + err error +} + +// problemsFilter is Core's filter for severities, nil for all, and file, empty for the whole +// project; nil when it keeps everything. +func problemsFilter(severities []int, file string) *core.ProblemsFilter { + if severities == nil && file == "" { + return nil + } + return &core.ProblemsFilter{Severities: severities, FileKey: file} +} + +// problemsTotal is how many diagnostics counts holds over every severity. +func problemsTotal(counts core.ProblemsSeverityCounts) int { + return counts.Error + counts.Warning + counts.Information + counts.Hint + counts.Unknown +} + +// applyProblemsQuery takes one answer back on the window thread. An answer for a superseded +// generation is dropped, and a new frame asks for the newer state. +func (a *App) applyProblemsQuery(p *project, answer problemsAnswer) { v := &a.problems if a.project != p || !a.chrome.isOpen(catalogIndex[itemProblems]) { return } v.querying = false - if generation != v.generation { + if answer.generation != v.generation { return } v.loaded = true - v.queried = generation - if err != nil { - a.operationFailed("plugin_problems_query", err) - v.failure = err - v.diagnostics, v.result, v.starts, v.rows = nil, core.ProblemsResult{}, nil, 0 + v.queried = answer.generation + v.file = answer.file + if answer.err != nil { + a.operationFailed("plugin_problems_query", answer.err) + v.failure = answer.err + v.diagnostics, v.result, v.selected, v.selectedRow, v.fileCount, v.projectCount = nil, core.ProblemsResult{}, "", -1, 0, 0 a.invalidator.Invalidate() return } v.failure = nil - v.diagnostics = diagnostics - v.result = result - v.starts = v.starts[:0] - v.rows = 0 - for _, group := range result.Groups { - v.starts = append(v.starts, v.rows) - v.rows += 1 + len(group.Indices) + v.diagnostics, v.result = answer.diagnostics, answer.result + v.fileCount, v.projectCount = answer.fileCount, answer.projectCount + // A row the user selected while the query was in flight stays selected where it still + // shows; otherwise the selection is the one Core kept or moved. + if v.selected == v.asked || !v.selectRow(v.selected) { + v.selected, v.selectedRow = answer.result.Selected, -1 + if answer.result.SelectedRow != nil { + v.selectedRow = *answer.result.SelectedRow + } } a.invalidator.Invalidate() } diff --git a/desktop/internal/workbench/problems_preview.go b/desktop/internal/workbench/problems_preview.go index 6ba7b24535..a8cfb436d0 100644 --- a/desktop/internal/workbench/problems_preview.go +++ b/desktop/internal/workbench/problems_preview.go @@ -5,22 +5,14 @@ import ( "github.com/vivaui/viva/ui" ) -// The Problems list's preview is the shared read-only source view (sourcePreview): it shows the -// file of the selected diagnostic and reveals its line, never takes the keyboard focus of the -// window or writes the file, and shows an open document's text, unsaved edits included. +// The Problems tree's preview is the shared read-only source view (sourcePreview): it shows the +// file of the selected row's diagnostic and reveals its line, never takes the keyboard focus of +// the window or writes the file, and shows an open document's text, unsaved edits included. -// selectedProblemLocation is the file and zero-based line of the selected diagnostic, and false -// when no diagnostic row is selected. +// selectedProblemLocation is the file and zero-based line the selected row shows: its +// diagnostic's, or a node's first diagnostic's; false when nothing with a file is selected. func (v *problemsView) selectedProblemLocation() (string, int, bool) { - row := v.list.Selected() - if row < 0 { - return "", 0, false - } - group, index, header := v.rowAt(row) - if header { - return "", 0, false - } - item, ok := v.diagnostic(group, index) + item, ok := v.shown(v.selectedRow) if !ok || item.FileKey == "" { return "", 0, false } @@ -28,7 +20,7 @@ func (v *problemsView) selectedProblemLocation() (string, int, bool) { } // syncProblemsPreview follows the selection while the preview is on. A new file starts a load; the -// same file only moves the reveal. A selection that is not a diagnostic keeps the last preview. +// same file only moves the reveal. With nothing selected the last preview stays. func (a *App) syncProblemsPreview(p *project) { v := &a.problems if !v.show { @@ -41,7 +33,7 @@ func (a *App) syncProblemsPreview(p *project) { a.showSourcePreview(p, &v.preview, path, line+1, func(a *App) bool { return a.problems.show }) } -// problemsPreviewPane declares the preview beside the list, or the reason there is none. +// problemsPreviewPane declares the preview beside the tree, or the reason there is none. func (a *App) problemsPreviewPane(c ui.C) { a.sourcePreviewPane(c, &a.problems.preview, "problemsPreview", i18n.Shared(a.language(), "desktop.problems.previewEmpty")) } diff --git a/desktop/internal/workbench/problems_test.go b/desktop/internal/workbench/problems_test.go index 801a00cea7..3e6b210add 100644 --- a/desktop/internal/workbench/problems_test.go +++ b/desktop/internal/workbench/problems_test.go @@ -4,9 +4,11 @@ import ( "errors" "os" "path/filepath" + "strings" "testing" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/plugindiag" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" ) @@ -33,13 +35,64 @@ func problemSet(t *testing.T, records ...plugindiag.Diagnostic) *plugindiag.Set func openProblemsPanel(t *testing.T, h *harness) { t.Helper() h.click(center(h.button(itemProblems))) - awaitDocumentState(t, h, func() bool { return h.app.problems.loaded && !h.app.problems.querying }) + awaitProblems(t, h) +} + +// awaitProblems paints until the answer for the tree's current state and the current file has +// been applied, then paints it. +func awaitProblems(t *testing.T, h *harness) { + t.Helper() + v := &h.app.problems + awaitDocumentState(t, h, func() bool { + return v.loaded && !v.querying && v.queried == v.generation && v.file == h.app.problemsCurrentFile() + }) if err := h.driver.Pump(); err != nil { t.Fatal(err) } } -func TestProblemsPanelUsesCoreOrderAndOpensPosition(t *testing.T) { +// problemsRowKeys is the keys of the tree's visible rows. +func problemsRowKeys(v *problemsView) []string { + keys := make([]string, len(v.result.Rows)) + for i, r := range v.result.Rows { + keys[i] = r.Key + } + return keys +} + +// problemsRowNamed is the name of the visible row with key, which the tree's control for it +// carries. +func problemsRowNamed(t *testing.T, h *harness, key string) string { + t.Helper() + i := h.app.problems.rowOf(key) + if i < 0 { + t.Fatalf("row %q does not show; rows %v", key, problemsRowKeys(&h.app.problems)) + } + return h.app.problemsRowLabel(i) +} + +// problemsDiagnosticRow is the key of the visible row of the diagnostic with message. +func problemsDiagnosticRow(t *testing.T, h *harness, message string) string { + t.Helper() + v := &h.app.problems + for _, r := range v.result.Rows { + if r.Kind == core.ProblemsRowDiagnostic && v.diagnostics[r.Shows].Message == message { + return r.Key + } + } + t.Fatalf("no row shows %q; rows %v", message, problemsRowKeys(v)) + return "" +} + +// problemsTab is the header tab's name for a count, as the File or Project tab shows it. +func problemsTab(h *harness, project bool, count int) string { + if project { + return problemsProjectTabText(h.app.language(), count) + } + return problemsFileTabText(h.app.language(), count) +} + +func TestProblemsTabsCountTheCurrentFileAndTheProject(t *testing.T) { h := newHarness(t, &testKernel{Client: core.NewClient()}) root := t.TempDir() if err := os.MkdirAll(filepath.Join(root, "src"), 0o700); err != nil { @@ -61,30 +114,57 @@ func TestProblemsPanelUsesCoreOrderAndOpensPosition(t *testing.T) { )} h.app.markProblemsChanged() + // The window opens on the File tab, as IDEA's does; no file is open yet. openProblemsPanel(t, h) - if got := h.app.problems.result.Groups; len(got) != 2 { - t.Fatalf("groups = %+v", got) + v := &h.app.problems + lang := h.app.language() + if v.project || v.fileCount != 0 || v.projectCount != 2 || len(v.result.Rows) != 0 { + t.Fatalf("project %v, counts %d/%d, rows %v", v.project, v.fileCount, v.projectCount, problemsRowKeys(v)) + } + if !h.shows(i18n.Shared(lang, "desktop.problems.noOpenFile")) { + t.Fatal("the File tab does not say that no file is open") + } + + h.clickNamed(problemsTab(h, true, 2)) + awaitProblems(t, h) + if !v.project { + t.Fatal("the Project tab was not chosen") + } + if got := v.result.Groups; len(got) != 2 || got[0].DisplayPath != "src/File2.java" || got[0].Name != "File2.java" || got[0].Folder != "src" { + t.Fatalf("groups = %+v, want Core's natural file order with File2 first", got) } - if got := h.app.problems.result.Groups[0].DisplayPath; got != "src/File2.java" { - t.Fatalf("first group = %q, want Core's natural file order", got) + file2Node, file10Node := "file:"+file2, "file:"+file10 + if keys := problemsRowKeys(v); len(keys) != 4 || keys[0] != file2Node || keys[2] != file10Node { + t.Fatalf("rows = %v, want each file's node over its diagnostic", keys) } - if !h.shows("src/File2.java") { - t.Fatal("the panel does not show the first file header") + if n := v.node(0); n.Depth != 0 || !n.Branch || !n.Expanded { + t.Fatalf("file node = %+v", n) } - if got := h.app.problems.rows; got != 4 { - t.Fatalf("flat rows = %d, want two headers and two diagnostics", got) + if n := v.node(1); n.Depth != 1 || n.Branch { + t.Fatalf("diagnostic = %+v", n) + } + if !h.shows("File2.java") { + t.Fatal("the panel does not show the first file's node") } - // Flat row 0 is the File2 header and row 1 is its diagnostic. - h.clickNamed("type mismatch") + // With the preview off, a click on a diagnostic opens it at its position. + h.clickNamed(problemsRowNamed(t, h, v.result.Rows[1].Key)) awaitDocumentState(t, h, func() bool { return h.app.project.docs.byPath(file2) != nil }) document := h.app.project.docs.byPath(file2) - if document == nil { - t.Fatal("the clicked diagnostic did not open its document") - } if line, column := document.view.Caret(); line != 1 || column != 2 { t.Fatalf("caret = %d:%d, want the diagnostic's zero-based 1:2", line, column) } + + // The opened file is the current one now, so the File tab counts and shows its problem. + awaitProblems(t, h) + if v.fileCount != 1 || v.projectCount != 2 { + t.Fatalf("counts = %d/%d after opening File2", v.fileCount, v.projectCount) + } + h.clickNamed(problemsTab(h, false, 1)) + awaitProblems(t, h) + if keys := problemsRowKeys(v); v.project || len(keys) != 2 || keys[0] != file2Node { + t.Fatalf("File tab rows = %v", keys) + } } func TestProblemsPanelVirtualizesLongList(t *testing.T) { @@ -98,14 +178,15 @@ func TestProblemsPanelVirtualizesLongList(t *testing.T) { h.open(root) h.app.pluginDiagnostics = map[string]*plugindiag.Set{"java": problemSet(t, records...)} h.app.markProblemsChanged() + h.app.problems.project = true openProblemsPanel(t, h) - if got := h.app.problems.rows; got != len(records)+1 { - t.Fatalf("flat rows = %d, want %d", got, len(records)+1) + if got := len(h.app.problems.result.Rows); got != len(records)+1 { + t.Fatalf("rows = %d, want %d", got, len(records)+1) } declared := 0 for _, hit := range h.driver.Snapshot().Hits { - if hit.Label == "problem" && !hit.IsLabel { + if strings.HasPrefix(hit.Label, "Many.java:") && !hit.IsLabel { declared++ } } @@ -126,50 +207,136 @@ func TestProblemsViewDropsStaleAnswer(t *testing.T) { h.app.chrome.open[slotBottomLeft] = catalogIndex[itemProblems] h.app.problems.generation = 7 h.app.problems.querying = true - h.app.applyProblemsQuery(p, 6, nil, core.ProblemsResult{}, nil) + h.app.applyProblemsQuery(p, problemsAnswer{generation: 6}) if h.app.problems.loaded || h.app.problems.querying { t.Fatalf("a stale answer was applied: %+v", h.app.problems) } // The current answer is accepted and replaces any previous failure. h.app.problems.failure = errors.New("old") - h.app.applyProblemsQuery(p, 7, nil, core.ProblemsResult{ + selected := 1 + h.app.applyProblemsQuery(p, problemsAnswer{generation: 7, projectCount: 1, result: core.ProblemsResult{ Groups: []core.ProblemsGroup{{Key: "all", Kind: "all", Indices: []int{0}, Counts: core.ProblemsSeverityCounts{Error: 1}}}, - }, nil) - if !h.app.problems.loaded || h.app.problems.failure != nil { - t.Fatalf("the current answer was not applied: %+v", h.app.problems) + Rows: []core.ProblemsRow{ + {Key: "file:a", Kind: core.ProblemsRowGroup}, + {Key: "diagnostic:0:0:0:a", Kind: core.ProblemsRowDiagnostic, Depth: 1}, + }, + Selected: "diagnostic:0:0:0:a", SelectedRow: &selected, + }}) + v := &h.app.problems + if !v.loaded || v.failure != nil || v.projectCount != 1 { + t.Fatalf("the current answer was not applied: %+v", v) + } + if len(v.result.Rows) != 2 || v.selected != "diagnostic:0:0:0:a" || v.selectedRow != 1 { + t.Fatalf("rows %v, selected %q at %d; want Core's selection", problemsRowKeys(v), v.selected, v.selectedRow) } - if h.app.problems.rows != 2 { - t.Fatalf("rows = %d, want a header and one diagnostic", h.app.problems.rows) +} + +// A row the user selects while a query is in flight stays selected over the selection Core +// answers for the state that query was asked with. +func TestProblemsKeepsASelectionMadeWhileAQueryRuns(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + h.open(t.TempDir()) + p := h.app.project + h.app.chrome.open[slotBottomLeft] = catalogIndex[itemProblems] + v := &h.app.problems + v.querying, v.asked, v.selected = true, "", "diagnostic:1:0:0:a" + first := 0 + h.app.applyProblemsQuery(p, problemsAnswer{result: core.ProblemsResult{ + Rows: []core.ProblemsRow{ + {Key: "diagnostic:0:0:0:a", Kind: core.ProblemsRowDiagnostic}, + {Key: "diagnostic:1:0:0:a", Kind: core.ProblemsRowDiagnostic, Shows: 1}, + }, + Selected: "diagnostic:0:0:0:a", SelectedRow: &first, + }}) + if v.selected != "diagnostic:1:0:0:a" || v.selectedRow != 1 { + t.Fatalf("selected %q at %d, want the row the user chose", v.selected, v.selectedRow) } } -func TestProblemsRowLayout(t *testing.T) { - v := problemsView{ - result: core.ProblemsResult{Groups: []core.ProblemsGroup{ - {Indices: []int{0, 1}}, - {Indices: []int{2}}, - }}, - starts: []int{0, 3}, - rows: 5, - } - want := []struct { - group, index int - header bool - }{ - {0, 0, true}, - {0, 0, false}, - {0, 1, false}, - {1, 0, true}, - {1, 0, false}, - } - for row, expected := range want { - group, index, header := v.rowAt(row) - if group != expected.group || index != expected.index || header != expected.header { - t.Fatalf("row %d = group %d index %d header %v, want %+v", row, group, index, header, expected) +// problemsTreeFixture opens a project with two files' problems on the Project tab: a.txt has an +// error and a warning, b.txt an information. The preview is on, so a click only selects. +func problemsTreeFixture(t *testing.T) (*harness, string, string) { + t.Helper() + h := newHarness(t, &testKernel{Client: core.NewClient()}) + root := t.TempDir() + a, b := filepath.Join(root, "a.txt"), filepath.Join(root, "b.txt") + for _, file := range []string{a, b} { + if err := os.WriteFile(file, []byte("zero\none\n"), 0o600); err != nil { + t.Fatal(err) } } - if _, _, header := v.rowAt(v.rows); header { - t.Fatalf("row %d is past the end", v.rows) + h.open(root) + h.app.pluginDiagnostics = map[string]*plugindiag.Set{"demo": problemSet(t, + plugindiag.Diagnostic{FileKey: a, DisplayPath: "a.txt", Line: 0, Column: 0, Severity: plugindiag.SeverityError, Message: "broken"}, + plugindiag.Diagnostic{FileKey: a, DisplayPath: "a.txt", Line: 1, Column: 0, Severity: plugindiag.SeverityWarning, Message: "unused"}, + plugindiag.Diagnostic{FileKey: b, DisplayPath: "b.txt", Line: 1, Column: 0, Severity: plugindiag.SeverityInformation, Message: "note"}, + )} + h.app.markProblemsChanged() + h.app.problems.project, h.app.problems.show = true, true + openProblemsPanel(t, h) + return h, "file:" + a, "file:" + b +} + +func TestClosingAProblemsNodeHandsItTheSelectionOfADiagnosticUnderIt(t *testing.T) { + h, a, b := problemsTreeFixture(t) + v := &h.app.problems + if keys := problemsRowKeys(v); len(keys) != 5 || keys[0] != a || keys[3] != b { + t.Fatalf("rows = %v", keys) + } + unused := v.result.Rows[2].Key + h.clickNamed(problemsRowNamed(t, h, unused)) + if v.selected != unused || v.selectedRow != 2 { + t.Fatalf("selected %q at %d after a click", v.selected, v.selectedRow) + } + if h.app.project.docs.byPath(v.diagnostics[v.result.Rows[2].Shows].FileKey) != nil { + t.Fatal("a click with the preview on opened the file") + } + + h.app.toggleProblemsNode(a) + awaitProblems(t, h) + if keys := problemsRowKeys(v); len(keys) != 3 || v.selected != a || v.selectedRow != 0 || v.node(0).Expanded { + t.Fatalf("rows %v, selected %q at %d after closing a.txt", keys, v.selected, v.selectedRow) + } + // A node's row previews its first diagnostic. + if path, line, ok := v.selectedProblemLocation(); !ok || path != v.result.Groups[0].FileKey || line != 0 { + t.Fatalf("node shows %q:%d (%v)", path, line, ok) + } + + h.app.expandProblems(false) + awaitProblems(t, h) + if keys := problemsRowKeys(v); len(keys) != 2 || keys[0] != a || keys[1] != b { + t.Fatalf("rows after collapse all = %v", keys) + } + h.app.expandProblems(true) + awaitProblems(t, h) + if keys := problemsRowKeys(v); len(keys) != 5 || v.selected != a { + t.Fatalf("rows %v, selected %q after expand all", keys, v.selected) + } +} + +func TestProblemsViewOptionsGroupBySeverityAndHideASeverity(t *testing.T) { + h, _, _ := problemsTreeFixture(t) + v := &h.app.problems + lang := h.app.language() + h.clickNamed(i18n.Shared(lang, "desktop.problems.viewOptions")) + h.clickNamed(i18n.Shared(lang, "desktop.problems.group.severity")) + awaitProblems(t, h) + if keys := problemsRowKeys(v); v.grouping() != core.ProblemsGroupBySeverity || len(keys) != 6 || keys[0] != "severity:1" { + t.Fatalf("grouping %q, rows %v", v.grouping(), keys) + } + if !h.shows(problemsSeverityText(lang, 1)) { + t.Fatal("the severity node is not named") + } + // Under a severity node, a diagnostic names its file. + if label := h.app.problemsRowLabel(1); !strings.HasPrefix(label, "a.txt:1 ") { + t.Fatalf("diagnostic label = %q", label) + } + + h.clickNamed(i18n.Shared(lang, "desktop.problems.viewOptions")) + h.clickNamed(i18n.Shared(lang, "desktop.problems.showErrors")) + awaitProblems(t, h) + if keys := problemsRowKeys(v); !v.hideErrors || len(keys) != 4 || keys[0] != "severity:2" || v.projectCount != 2 { + t.Fatalf("hide errors %v, rows %v, project count %d", v.hideErrors, keys, v.projectCount) } } @@ -241,7 +408,7 @@ func TestProblemsCacheIsDroppedWhenThePanelCloses(t *testing.T) { t.Fatal("the panel did not load its query") } h.click(center(h.button(itemProblems))) - if h.app.problems.loaded || h.app.problems.rows != 0 || len(h.app.problems.diagnostics) != 0 { + if h.app.problems.loaded || len(h.app.problems.result.Rows) != 0 || len(h.app.problems.diagnostics) != 0 { t.Fatalf("closing the panel kept its cached answer: %+v", h.app.problems) } } @@ -262,11 +429,12 @@ func TestProblemsPreviewFollowsTheSelectedDiagnostic(t *testing.T) { plugindiag.Diagnostic{FileKey: missing, DisplayPath: "missing.txt", Line: 0, Column: 0, Severity: plugindiag.SeverityWarning, Message: "gone"}, )} h.app.markProblemsChanged() - h.app.problems.show = true + h.app.problems.show, h.app.problems.project = true, true openProblemsPanel(t, h) preview := &h.app.problems.preview - h.clickNamed("on two") + onTwo, gone := problemsDiagnosticRow(t, h, "on two"), problemsDiagnosticRow(t, h, "gone") + h.clickNamed(problemsRowNamed(t, h, onTwo)) awaitDocumentState(t, h, func() bool { return preview.view != nil && preview.path == present }) if line, _ := preview.view.Caret(); line != 2 || preview.line != 3 { t.Fatalf("preview at line %d (asked %d), want the diagnostic's zero-based 2", line, preview.line) @@ -275,7 +443,7 @@ func TestProblemsPreviewFollowsTheSelectedDiagnostic(t *testing.T) { t.Fatal("selecting a diagnostic with the preview on opened its file") } - h.clickNamed("gone") + h.clickNamed(problemsRowNamed(t, h, gone)) awaitDocumentState(t, h, func() bool { return preview.failure != nil }) if preview.path != missing || preview.view != nil { t.Fatalf("preview of an unreadable file = %q, view %v", preview.path, preview.view != nil) diff --git a/desktop/internal/workbench/problems_view.go b/desktop/internal/workbench/problems_view.go index 23b6acbda1..c9ca4e52d3 100644 --- a/desktop/internal/workbench/problems_view.go +++ b/desktop/internal/workbench/problems_view.go @@ -1,181 +1,348 @@ package workbench import ( + "path" + "path/filepath" "strconv" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/fileicons" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/1lck/Lithe-IDEA/desktop/internal/treelist" + "github.com/vivaui/viva/components" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) const ( - // problemsRowHeight is the height of a file header and of a diagnostic row. - problemsRowHeight = 22 - // problemsListWidth is the list's width beside the preview until the user drags the splitter, - // and the least each side keeps while dragging. - problemsListWidth = 320 - problemsListMin = 160 - problemsPreviewMin = 160 + // problemsTreeWidth is the tree's width beside the preview until the user drags the + // splitter; the tree and the preview keep at least their minimums while it is dragged. + problemsTreeWidth = 380 + problemsTreeMin = 180 + problemsPreviewMin = 200 ) -// problemsGroupings are the groupings the toolbar cycles through, in order. +// problemsGroupings are the groupings the View Options menu offers, in order. var problemsGroupings = []string{core.ProblemsGroupByFile, core.ProblemsGroupBySeverity, core.ProblemsGroupByNone} -// problemsToolbar declares the view options: the preview switch, the severity filters and the -// grouping. Each change is a preference that asks Core for the list again. -func (a *App) problemsToolbar(c ui.C, p *project, lang i18n.Language) { - v := &a.problems - preview := v.show - if ui.Checkbox(c.Key("problemsPreview"), &preview, i18n.Shared(lang, "desktop.problems.showPreview")).Changed() { - v.show = preview - if !v.show { - v.preview.close() - } - } - errors, warnings, info := !v.hideErrors, !v.hideWarnings, !v.hideInfo - changed := false - if ui.Checkbox(c.Key("problemsErrors"), &errors, i18n.Shared(lang, "desktop.problems.showErrors")).Changed() { - v.hideErrors, changed = !errors, true - } - if ui.Checkbox(c.Key("problemsWarnings"), &warnings, i18n.Shared(lang, "desktop.problems.showWarnings")).Changed() { - v.hideWarnings, changed = !warnings, true - } - if ui.Checkbox(c.Key("problemsInfo"), &info, i18n.Shared(lang, "desktop.problems.showInfo")).Changed() { - v.hideInfo, changed = !info, true - } - current := v.groupBy - if current == "" { - current = core.ProblemsGroupByFile - } - if ui.Button(c.Key("problemsGroup"), i18n.SharedFormat(lang, "desktop.problems.groupBy", map[string]string{"arg1": problemsGroupingText(lang, current)})).Ghost().Clicked() { - next := problemsGroupings[0] - for index, grouping := range problemsGroupings { - if grouping == current { - next = problemsGroupings[(index+1)%len(problemsGroupings)] - break - } - } - v.groupBy, changed = next, true - } - if changed { - a.markProblemsChanged() - } -} - -// problemsPanel declares the Problems tool window of an open project: the files that have -// diagnostics, each as a header over its diagnostics, in the order Core gave them. +// problemsPanel declares the Problems tool window of an open project: the column of actions, +// and the tree of the chosen tab's diagnostics with, beside it, the preview of the selected one. +// The actions stay while the tree is empty, so the options that emptied it can be undone. func (a *App) problemsPanel(c ui.C, p *project) { a.requestProblemsQuery(p) + lang := a.language() + ui.Row(c).Fill().Clip().Children(func() { + a.problemsToolbar(c, lang) + ui.Divider(c) + ui.Column(c).Grow(1).Basis(0).Shrink(1).MinWidth(0).FillHeight().MinHeight(0).Children(func() { + a.problemsContent(c, p, lang) + }) + }) +} + +// problemsContent declares the tree and the preview, or why there is no tree: Core refused the +// query, no file is open on the File tab, or the chosen tab has no problems. Nothing shows +// until the first answer arrives, so an empty message does not flash before it. +func (a *App) problemsContent(c ui.C, p *project, lang i18n.Language) { v := &a.problems switch { case v.failure != nil: a.panelMessage(c, a.text.Errors.Core(v.failure.Error()), a.theme.Danger) return - case v.rows == 0: - message := i18n.SharedFormat(a.language(), "native.noProblemsIn", map[string]string{"arg1": p.name}) - a.panelMessage(c, message, a.colors.Subtle) + case !v.loaded: + return + case !v.project && v.file == "": + a.panelMessage(c, i18n.Shared(lang, "desktop.problems.noOpenFile"), a.colors.Subtle) + return + case len(v.result.Rows) == 0: + scope := p.name + if !v.project { + scope = filepath.Base(v.file) + } + a.panelMessage(c, i18n.SharedFormat(lang, "native.noProblemsIn", map[string]string{"arg1": scope}), a.colors.Subtle) return } - if v.list.Key == nil { - v.list.Header = func(i int) bool { _, _, header := v.rowAt(i); return header } - v.list.Label = v.rowLabel + if !v.show { + a.problemsTree(c, p, lang) + return } - lang := a.language() - a.problemsToolbar(c, p, lang) a.syncProblemsPreview(p) - opened := -1 - list := func(c ui.C) { - ui.List(c, &v.list, v.rows, func(row ui.ListRow) { - group, index, header := v.rowAt(row.Index) - // With the preview on, a click only selects: the preview follows the selection and - // a double click or Enter opens the file, as the preview's contract states. - if header { - a.drawProblemsGroupHeader(row, v.result.Groups[group]) - } else if a.drawProblemsRow(row, v, group, index) && !v.show { - opened = row.Index - } - }).Scrollbars().Label(i18n.Shared(lang, "native.problems")).FillWidth().Grow(1).Basis(0).Shrink(1).MinHeight(0) + if v.split.Pos <= 0 { + v.split.Pos = problemsTreeWidth } - if v.show { - if v.split.Pos <= 0 { - v.split.Pos = problemsListWidth + ui.Row(c).Grow(1).Basis(0).Shrink(1).MinWidth(0).FillHeight().MinHeight(0).Children(func() { + ui.Column(c).Width(v.split.Pos).Shrink(0).FillHeight().MinHeight(0).Children(func() { a.problemsTree(c, p, lang) }) + ui.Splitter(c, &v.split).Mins(problemsTreeMin, problemsPreviewMin).Label(a.text.Panel.Resize) + a.problemsPreviewPane(c) + }) +} + +// problemsToolbar declares the column of actions left of the tree, as IDEA's Problems tool +// window puts them: the View Options menu (the severities shown and the grouping), opening and +// closing every node, and turning the preview on or off. Each option is a preference that asks +// Core for the tree again. +func (a *App) problemsToolbar(c ui.C, lang i18n.Language) { + v := &a.problems + ui.Column(c).FillHeight().Shrink(0).Gap(2).Pad(4).Children(func() { + eye, clicked := a.toolIconButton(c.Part("problemsOptions"), i18n.Shared(lang, "desktop.problems.viewOptions"), icons.Eye, v.optionsOpen, false) + if clicked { + v.optionsOpen = !v.optionsOpen } - ui.Row(c).FillWidth().Grow(1).Basis(0).Shrink(1).MinHeight(0).Children(func() { - ui.Column(c).Width(v.split.Pos).Shrink(0).FillHeight().MinHeight(0).Children(func() { list(c) }) - ui.Splitter(c, &v.split).Mins(problemsListMin, problemsPreviewMin).Label(a.text.Panel.Resize) - a.problemsPreviewPane(c) + ui.Menu(c.Part("problemsOptionsMenu"), eye, &v.optionsOpen, func(menu *ui.MenuItems) { + menu.WidthRange(180, 260) + menu.Label(i18n.Shared(lang, "desktop.problems.showHeading")) + if menu.Item(i18n.Shared(lang, "desktop.problems.showErrors")).Checked(!v.hideErrors).Clicked() { + c.After(func() { v.hideErrors = !v.hideErrors; a.markProblemsChanged() }) + } + if menu.Item(i18n.Shared(lang, "desktop.problems.showWarnings")).Checked(!v.hideWarnings).Clicked() { + c.After(func() { v.hideWarnings = !v.hideWarnings; a.markProblemsChanged() }) + } + if menu.Item(i18n.Shared(lang, "desktop.problems.showInfo")).Checked(!v.hideInfo).Clicked() { + c.After(func() { v.hideInfo = !v.hideInfo; a.markProblemsChanged() }) + } + menu.Separator() + menu.Label(i18n.Shared(lang, "desktop.problems.groupHeading")) + for _, grouping := range problemsGroupings { + if menu.Item(problemsGroupingText(lang, grouping)).Chosen(v.grouping() == grouping).Clicked() { + c.After(func() { + if v.grouping() != grouping { + v.groupBy, v.reveal = grouping, true + a.markProblemsChanged() + } + }) + } + } }) - } else { - list(c) - } - if row, ok := v.list.Submitted(); ok { - opened = row - } - if group, index, header := v.rowAt(opened); opened >= 0 && !header { - if item, ok := v.diagnostic(group, index); ok && item.FileKey != "" { + // The ungrouped list has no nodes to open or close. + flat := v.grouping() == core.ProblemsGroupByNone || len(v.result.Rows) == 0 + if _, clicked := a.toolIconButton(c.Part("problemsExpand"), i18n.Shared(lang, "outline.expandAll"), icons.ChevronsUpDown, false, flat); clicked { + c.After(func() { a.expandProblems(true) }) + } + if _, clicked := a.toolIconButton(c.Part("problemsCollapse"), i18n.Shared(lang, "outline.collapseAll"), icons.ChevronsDownUp, false, flat); clicked { + c.After(func() { a.expandProblems(false) }) + } + if _, clicked := a.toolIconButton(c.Part("problemsPreview"), i18n.Shared(lang, "desktop.problems.showPreview"), icons.PanelRight, v.show, false); clicked { c.After(func() { - a.performed("workspace.problems.open", surfaceButton) - a.openFileAtPosition(p, item.FileKey, item.Line, item.Column) + a.performed("workspace.problems.preview", surfaceButton) + v.show = !v.show + if !v.show { + v.preview.close() + } }) } + }) +} + +// problemsTree declares the tree of diagnostics. A click selects a row, and the preview follows +// it; a double click or Enter opens a diagnostic, or opens or closes a node. With the preview +// off, a click on a diagnostic opens it, as there is nothing else to show it. +func (a *App) problemsTree(c ui.C, p *project, lang i18n.Language) { + v := &a.problems + if v.view.Node == nil { + v.view.Node = v.node + v.view.Key = v.key + v.view.Label = a.problemsRowLabel + v.view.RowHeight = treelist.RowHeight + v.view.Indent = treelist.Indent + } + v.view.Disclosure = &components.TreeDisclosure{ + Collapsed: fileicons.TreeChevron(false, a.colors.Dark), + Expanded: fileicons.TreeChevron(true, a.colors.Dark), + Size: 16, } + a.syncProblemsSelection(c.Canvas()) + rows := v.result.Rows + ui.Tree(c, &v.view, len(rows), v.view.Label, func(i int) { + a.drawProblemsRow(c, i, lang) + }).Scrollbars().Label(i18n.Shared(lang, "native.problems")).Grow(1).FillWidth().MinHeight(0).PadY(treelist.PadY) + if i, ok := v.view.Toggled(); ok && i < len(rows) { + key := rows[i].Key + c.After(func() { a.toggleProblemsNode(key) }) + } + i, ok := v.view.Chosen() + if !ok || i >= len(rows) { + return + } + info, clicked := c.Canvas().ClickInfo() + repeated := clicked && info.Clicks >= 2 + row := rows[i] + // The row a click chose takes the keyboard, so the arrow keys go on from it. + c.Canvas().RequestFocus(v.view.RowID(i)) + c.After(func() { + if !v.selectRow(row.Key) { + return // a new answer in this frame no longer shows it + } + if clicked && !repeated && (row.Kind != core.ProblemsRowDiagnostic || v.show) { + return // a single click only selects + } + if row.Kind != core.ProblemsRowDiagnostic { + a.toggleProblemsNode(row.Key) + return + } + if item, ok := v.shown(v.selectedRow); ok && item.FileKey != "" { + a.performed("workspace.problems.open", surfaceButton) + a.openFileAtPosition(p, item.FileKey, item.Line, item.Column) + } + }) } -// diagnostic is the diagnostic at index of group, and false when either is out of range. -func (v *problemsView) diagnostic(group, index int) (core.ProblemsDiagnostic, bool) { - if group < 0 || group >= len(v.result.Groups) { - return core.ProblemsDiagnostic{}, false +// syncProblemsSelection makes the selection follow the keyboard: a row the arrow keys moved the +// focus to is selected. Only a move of the focus selects, so a selection Core moved stays while +// the focus is on another row. A selection asked to show is scrolled into view, and takes the +// keyboard when the tree has it. +func (a *App) syncProblemsSelection(canvas *gfx.Canvas) { + v := &a.problems + rows := v.result.Rows + focused := canvas.Focused() + inTree := false + if focused != v.focus || v.reveal { + for i := range rows { + if v.view.RowID(i) == focused { + inTree = true + if focused != v.focus { + v.selected, v.selectedRow = rows[i].Key, i + } + break + } + } + v.focus = focused } - indices := v.result.Groups[group].Indices - if index < 0 || index >= len(indices) || indices[index] < 0 || indices[index] >= len(v.diagnostics) { - return core.ProblemsDiagnostic{}, false + selected := v.selectedRow + if selected >= len(rows) { + selected = -1 + } + if v.reveal && selected >= 0 { + if first, last := v.view.Visible(); selected < first || selected > last { + v.view.ScrollTo(selected, ui.ListCenter) + canvas.RequestFrame() + } + if inTree { + canvas.RequestFocus(v.view.RowID(selected)) + } + v.reveal = false + } + if v.view.Selected() != selected { + v.view.Select(selected) } - return v.diagnostics[indices[index]], true } -// rowLabel names row i to the list: a file's path, or a diagnostic's message. -func (v *problemsView) rowLabel(i int) string { - group, index, header := v.rowAt(i) - if header { - return v.result.Groups[group].DisplayPath +// problemsRowLabel names row i to assistive technology: a node with its file's path or its +// severity and number of problems, or a diagnostic with its file, line and message. +func (a *App) problemsRowLabel(i int) string { + v := &a.problems + if i < 0 || i >= len(v.result.Rows) { + return "" + } + lang := a.language() + r := v.result.Rows[i] + if r.Kind == core.ProblemsRowGroup { + g, ok := v.group(r.Group) + if !ok { + return "" + } + name := g.DisplayPath + if g.Kind != core.ProblemsGroupByFile { + name = problemsSeverityText(lang, g.Severity) + } + return name + " " + a.text.Status.Problems(len(g.Indices)) } - if item, ok := v.diagnostic(group, index); ok { - return item.Message + item, ok := v.shown(i) + if !ok { + return "" } - return "" + return item.DisplayPath + ":" + strconv.Itoa(item.Line+1) + " " + item.Message } -// drawProblemsGroupHeader declares one file's heading. It is not clickable: opening a file -// happens on one of its diagnostics. The heading of the file in view stays at the top. -func (a *App) drawProblemsGroupHeader(row ui.ListRow, group core.ProblemsGroup) { - c := row.C - row.Element.FillWidth().Height(problemsRowHeight).PadX(10).Items(ui.Center).Gap(6).Background(a.colors.Panel).Children(func() { - ui.Text(c, group.DisplayPath).Grow(1).Shrink(1).FontSize(12.5).Bold().Color(a.colors.Text).Ellipsis() - ui.Text(c, a.text.Status.Problems(len(group.Indices))).Shrink(0).FontSize(11.5).Color(a.colors.Subtle) - }) +// group is the answer's group g, and false when it is out of range. +func (v *problemsView) group(g int) (core.ProblemsGroup, bool) { + if g < 0 || g >= len(v.result.Groups) { + return core.ProblemsGroup{}, false + } + return v.result.Groups[g], true } -// drawProblemsRow declares one diagnostic of a group and reports whether it was clicked. -func (a *App) drawProblemsRow(row ui.ListRow, v *problemsView, group, index int) bool { - item, ok := v.diagnostic(group, index) +// drawProblemsRow declares what row i shows after its chevron: a file's icon, name, folder and +// number of problems; a severity's mark, name and number of problems; or a diagnostic's mark, +// message, source and line, with its file's name when the nodes are not files. A diagnostic +// under a node has no chevron, so it keeps the chevron's room empty and its mark lines up +// under its node's icon. +func (a *App) drawProblemsRow(c ui.C, i int, lang i18n.Language) { + v := &a.problems + r := v.result.Rows[i] + g, ok := v.group(r.Group) if !ok { - return false + return + } + if r.Kind == core.ProblemsRowGroup { + count := a.text.Status.Problems(len(g.Indices)) + if g.Kind == core.ProblemsGroupByFile { + ui.Icon(c, fileicons.ForFile(g.Name, a.colors.Dark)).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(a.colors.Subtle) + ui.Text(c, g.Name).FontSize(treeFontSize).Color(a.colors.Text).Shrink(0) + if g.Folder != "" { + ui.Text(c, g.Folder).FontSize(treeFontSize).Color(a.colors.Subtle).Shrink(1).MinWidth(0).Ellipsis() + } + } else { + icon, tint := a.problemSeverityMark(g.Severity) + ui.Icon(c, icon).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(tint) + ui.Text(c, problemsSeverityText(lang, g.Severity)).FontSize(treeFontSize).Color(a.colors.Text).Shrink(0) + } + ui.Text(c, count).FontSize(treeFontSize).Color(a.colors.Subtle).Shrink(0) + return + } + item, ok := v.shown(i) + if !ok { + return + } + var indent float32 + if r.Depth > 0 { + indent = treeChevron + } + location := ":" + strconv.Itoa(item.Line+1) + if g.Kind != core.ProblemsGroupByFile { + location = path.Base(item.DisplayPath) + location } - c := row.C icon, tint := a.problemSeverityMark(item.Severity) - position := strconv.Itoa(item.Line+1) + ":" + strconv.Itoa(item.Column+1) - row.Element.FillWidth().Height(problemsRowHeight).PadX(10).Items(ui.Center).Gap(6). - Hover(ui.Look{}.Background(a.colors.Hover)).Children(func() { - ui.Icon(c, icon).Size(14, 14).Shrink(0).Color(tint) - ui.Text(c, item.Message).Grow(1).Shrink(1).FontSize(12.5).Color(a.colors.Text).Ellipsis() + ui.Row(c).Shrink(1).MinWidth(0).Items(ui.Center).Gap(c.Theme().Metrics.GapItem).PadLeft(indent).Children(func() { + ui.Icon(c, icon).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(tint) + ui.Text(c, item.Message).FontSize(treeFontSize).Color(a.colors.Text).Shrink(1).MinWidth(0).Ellipsis() if item.Source != "" { - ui.Text(c, item.Source).Shrink(1).FontSize(11.5).Color(a.colors.Subtle).Ellipsis().MaxWidth(80) + // The message gives way first; a source keeps its name up to a cap. + ui.Text(c, item.Source).FontSize(treeFontSize).Color(a.colors.Subtle).Shrink(0).MaxWidth(120).Ellipsis() } - ui.Text(c, position).Shrink(0).FontSize(11.5).Color(a.colors.Subtle) + ui.Text(c, location).FontSize(treeFontSize).Color(a.colors.Subtle).Shrink(0) }) - return row.Element.Clicked() +} + +// problemsScopeTabs declares the header's tabs, File and Project, each with the number of +// problems it holds under the severity options, as IDEA's Problems tool window heads its tree. +// The current file is the selected editor tab's. +func (a *App) problemsScopeTabs(c ui.C) { + v := &a.problems + lang := a.language() + labels := []string{problemsFileTabText(lang, v.fileCount), problemsProjectTabText(lang, v.projectCount)} + selected := 0 + if v.project { + selected = 1 + } + a.toolTabsWith(c, selected, labels, func(i int) { a.chooseProblemsScope(i == 1) }) +} + +// problemsFileTabText is the File tab's name, followed by its number of problems when it holds any. +func problemsFileTabText(lang i18n.Language, count int) string { + if count == 0 { + return i18n.Shared(lang, "desktop.problems.scope.file") + } + return i18n.SharedFormat(lang, "desktop.problems.scope.fileCount", map[string]string{"count": strconv.Itoa(count)}) +} + +// problemsProjectTabText is the Project tab's name, followed by its number of problems when it +// holds any. +func problemsProjectTabText(lang i18n.Language, count int) string { + if count == 0 { + return i18n.Shared(lang, "desktop.problems.scope.project") + } + return i18n.SharedFormat(lang, "desktop.problems.scope.projectCount", map[string]string{"count": strconv.Itoa(count)}) } // problemSeverityMark is the icon and tint of an LSP severity. Unknown @@ -191,7 +358,24 @@ func (a *App) problemSeverityMark(severity int) (gfx.Icon, gfx.Color) { } } -// problemsGroupingText is the name of a grouping of the problems list. +// problemsSeverityText is the name of a severity node: an LSP severity 1-4, or 0 for the +// diagnostics whose severity is missing or unknown. +func problemsSeverityText(lang i18n.Language, severity int) string { + switch severity { + case 1: + return i18n.Shared(lang, "desktop.problems.severity.error") + case 2: + return i18n.Shared(lang, "desktop.problems.severity.warning") + case 3: + return i18n.Shared(lang, "desktop.problems.severity.information") + case 4: + return i18n.Shared(lang, "desktop.problems.severity.hint") + default: + return i18n.Shared(lang, "desktop.problems.severity.unknown") + } +} + +// problemsGroupingText is the name of a grouping of the problems tree. func problemsGroupingText(lang i18n.Language, grouping string) string { switch grouping { case core.ProblemsGroupBySeverity: diff --git a/desktop/internal/workbench/problems_visual_test.go b/desktop/internal/workbench/problems_visual_test.go new file mode 100644 index 0000000000..7f52f0ad9e --- /dev/null +++ b/desktop/internal/workbench/problems_visual_test.go @@ -0,0 +1,111 @@ +//go:build vivahead && lithevisual + +package workbench + +import ( + "os" + "path/filepath" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/plugindiag" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/headless" +) + +// TestVisualProblemsToolWindow captures the Problems tool window over two files' diagnostics: +// the File tab on the open file, the Project tab with the selected diagnostic's preview, and the +// View Options menu. Dark/light x Chinese/English are independent sessions and OS-free. +func TestVisualProblemsToolWindow(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + for _, look := range []struct{ theme, language string }{ + {"dark", "zh-Hans"}, {"dark", "en"}, + {"light", "zh-Hans"}, {"light", "en"}, + } { + t.Run(look.theme+"-"+look.language, func(t *testing.T) { + prefs := store.At(t.TempDir()) + if err := prefs.Save(settingsFile, settings{ + Theme: themeChoice(look.theme), Language: look.language, + DisableAutoSave: true, + }); err != nil { + t.Fatal(err) + } + root := filepath.Join(t.TempDir(), "shop") + folder := filepath.Join(root, "src", "main", "java", "shop") + if err := os.MkdirAll(folder, 0700); err != nil { + t.Fatal(err) + } + service := filepath.Join(folder, "OrderService.java") + order := filepath.Join(folder, "Order.java") + files := map[string]string{ + service: "package shop;\n\nimport java.util.List;\n\npublic class OrderService {\n private final Inventory inventory;\n\n public OrderService(Inventory inventory) {\n this.inventory = inventory;\n }\n\n public int total(List orders) {\n int count = 0;\n int total = 0;\n for (Order order : orders) {\n total += order.price();\n }\n return total;\n }\n}\n", + order: "package shop;\n\npublic record Order(String name, int price) {\n public Order {\n if (price < 0) throw new IllegalArgumentException();\n }\n}\n", + } + for path, source := range files { + if err := os.WriteFile(path, []byte(source), 0600); err != nil { + t.Fatal(err) + } + } + var session *headless.Session + h := newHarnessWithDriver(t, Options{ + Kernel: &testKernel{Client: core.NewClient()}, + Store: prefs, Languages: []string{look.language}, + }, func(config app.Config) (*app.Driver, func(), error) { + config.Width, config.Height = 1440, 900 + var err error + session, err = headless.Open(config, nil, headless.Options{}) + if err != nil { + return nil, nil, err + } + return session.Driver(), session.Close, nil + }) + h.open(root) + p := h.app.project + servicePath, orderPath := "src/main/java/shop/OrderService.java", "src/main/java/shop/Order.java" + h.app.pluginDiagnostics = map[string]*plugindiag.Set{"java": problemSet(t, + plugindiag.Diagnostic{FileKey: service, DisplayPath: servicePath, Line: 5, Column: 18, EndLine: 5, EndColumn: 27, Severity: plugindiag.SeverityError, Message: "Inventory cannot be resolved to a type", Source: "Java"}, + plugindiag.Diagnostic{FileKey: service, DisplayPath: servicePath, Line: 12, Column: 12, EndLine: 12, EndColumn: 17, Severity: plugindiag.SeverityWarning, Message: "The value of the local variable count is not used", Source: "Java"}, + plugindiag.Diagnostic{FileKey: service, DisplayPath: servicePath, Line: 2, Column: 0, EndLine: 2, EndColumn: 22, Severity: plugindiag.SeverityInformation, Message: "Import 'List' could be on demand", Source: "Java"}, + plugindiag.Diagnostic{FileKey: order, DisplayPath: orderPath, Line: 4, Column: 24, EndLine: 4, EndColumn: 54, Severity: plugindiag.SeverityWarning, Message: "Exception has no message", Source: "Java"}, + )} + h.app.markProblemsChanged() + h.app.openFile(p, service) + h.settleChain() + + // The File tab, which the window opens on, holds the open file's problems. + openProblemsPanel(t, h) + h.settleChain() + if err := session.Screenshot(filepath.Join(out, "problems-file-"+look.theme+"-"+look.language+".png")); err != nil { + t.Fatal(err) + } + + // The Project tab with the preview of the selected diagnostic. + v := &h.app.problems + h.clickNamed(problemsProjectTabText(h.app.language(), v.projectCount)) + awaitProblems(t, h) + h.clickNamed(h.shared("desktop.problems.showPreview")) + h.settleChain() + h.clickNamed(problemsRowNamed(t, h, problemsDiagnosticRow(t, h, "The value of the local variable count is not used"))) + h.await("the diagnostic's preview", func() bool { return v.preview.view != nil && v.preview.path == service }) + h.settleChain() + if err := session.Screenshot(filepath.Join(out, "problems-project-"+look.theme+"-"+look.language+".png")); err != nil { + t.Fatal(err) + } + + // The View Options menu: which severities show and how the tree groups them. + h.clickNamed(h.shared("desktop.problems.viewOptions")) + h.settleChain() + h.popupHit(h.shared("desktop.problems.group.severity")) + if err := session.Screenshot(filepath.Join(out, "problems-options-"+look.theme+"-"+look.language+".png")); err != nil { + t.Fatal(err) + } + }) + } +} diff --git a/desktop/internal/workbench/shell_view.go b/desktop/internal/workbench/shell_view.go index f15c9869db..c2ae097712 100644 --- a/desktop/internal/workbench/shell_view.go +++ b/desktop/internal/workbench/shell_view.go @@ -86,7 +86,7 @@ func (a *App) shellPanel(c ui.C, s slot, index int, hidden *slot) ui.Box { p := a.project tabbed := tool.id == itemGit header := float32(toolTitleHeight) - if tabbed || tool.id == itemTerminal || tool.id == itemCommit || tool.id == itemRun || tool.id == itemReferences { + if tabbed || tool.id == itemTerminal || tool.id == itemCommit || tool.id == itemRun || tool.id == itemReferences || tool.id == itemProblems { header = panelHeaderHeight } if tool.id == itemFind && p != nil { @@ -120,6 +120,10 @@ func (a *App) shellPanel(c ui.C, s slot, index int, hidden *slot) ui.Box { case tool.id == itemReferences && p != nil: // And the tab of the usages the References window shows. a.referencesSearchTab(c, p) + case tool.id == itemProblems && p != nil: + // The Problems window's File and Project tabs come before the spacer. + a.problemsScopeTabs(c) + ui.Spacer(c) default: ui.Spacer(c) } diff --git a/docs/assets/problems-tree/after/problems-file-dark-zh-Hans.png b/docs/assets/problems-tree/after/problems-file-dark-zh-Hans.png new file mode 100644 index 0000000000..7b2236005e Binary files /dev/null and b/docs/assets/problems-tree/after/problems-file-dark-zh-Hans.png differ diff --git a/docs/assets/problems-tree/after/problems-file-light-en.png b/docs/assets/problems-tree/after/problems-file-light-en.png new file mode 100644 index 0000000000..d6ce20b079 Binary files /dev/null and b/docs/assets/problems-tree/after/problems-file-light-en.png differ diff --git a/docs/assets/problems-tree/after/problems-options-dark-zh-Hans.png b/docs/assets/problems-tree/after/problems-options-dark-zh-Hans.png new file mode 100644 index 0000000000..890d4e4464 Binary files /dev/null and b/docs/assets/problems-tree/after/problems-options-dark-zh-Hans.png differ diff --git a/docs/assets/problems-tree/after/problems-options-light-en.png b/docs/assets/problems-tree/after/problems-options-light-en.png new file mode 100644 index 0000000000..28cf0e7de8 Binary files /dev/null and b/docs/assets/problems-tree/after/problems-options-light-en.png differ diff --git a/docs/assets/problems-tree/after/problems-project-dark-zh-Hans.png b/docs/assets/problems-tree/after/problems-project-dark-zh-Hans.png new file mode 100644 index 0000000000..7c370ecda0 Binary files /dev/null and b/docs/assets/problems-tree/after/problems-project-dark-zh-Hans.png differ diff --git a/docs/assets/problems-tree/after/problems-project-light-en.png b/docs/assets/problems-tree/after/problems-project-light-en.png new file mode 100644 index 0000000000..a2e9a8531a Binary files /dev/null and b/docs/assets/problems-tree/after/problems-project-light-en.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index dae9936367..1601377545 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -27,12 +27,16 @@ native_path() { fi } -# Lithe-core-rust fix/process-memory-min-interval at 8dd6c70, the branch of the draft on top of -# main 5202d3b: processMemory.summarize never compares two tables less than a second apart, so +# Lithe-core-rust main at cf2f260, #82 squash-merged (the same tree as its branch at 4d0dc1c, on +# top of 18a370d): lsp.problems.query also lays out the Problems tool window's tree (the rows +# visible under the group nodes the desktop closes, the diagnostic each row previews and opens, a +# selection behind a closed node moved to that node and one of a gone diagnostic to its file's +# node) and names each file group's file and folder (#2105). +# Lithe-core-rust main at 18a370d, #81 squash-merged (the same tree as its branch at 8dd6c70, on +# top of 5202d3b): processMemory.summarize never compares two tables less than a second apart, so # the memory details no longer show the burst of their own opening as CPU and GPU use; a table # read sooner is measured from the counters the baseline was itself measured from, which the -# baseline now carries as earlier, and the baseline comes back unchanged. The pin moves to the -# squash merge once the draft is in main. +# baseline now carries as earlier, and the baseline comes back unchanged. # Lithe-core-rust main at 5202d3b, #80 squash-merged (the same tree as its branch at 81a6ecf, on # top of 788e61e, #79 and #78): # lsp.references.query lays out the References tool window (usages grouped in natural file @@ -191,7 +195,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # the contract, plugin guides, reference and SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), # #15 (git.write cherryPick, revert and reset fields), #14 (word-level changed ranges of diff # rows), #13, #8, #7, #6 and #4. -PINNED_CORE_REVISION="8dd6c70c87ce948f606d579957478bf19e8979b0" +PINNED_CORE_REVISION="cf2f26095bb352f69d248f840dd7d6126747482e" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index ffa4e3293b..0fecb4c2cb 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -10871,7 +10871,19 @@ "desktop.problems.group.file": "By file", "desktop.problems.group.severity": "By severity", "desktop.problems.group.none": "No grouping", - "desktop.problems.groupBy": "Group: {arg1}", + "desktop.problems.groupHeading": "Group By", + "desktop.problems.noOpenFile": "No file is open.", + "desktop.problems.scope.file": "File", + "desktop.problems.scope.fileCount": "File {count}", + "desktop.problems.scope.project": "Project", + "desktop.problems.scope.projectCount": "Project {count}", + "desktop.problems.severity.error": "Errors", + "desktop.problems.severity.hint": "Hints", + "desktop.problems.severity.information": "Information", + "desktop.problems.severity.unknown": "Unknown severity", + "desktop.problems.severity.warning": "Warnings", + "desktop.problems.showHeading": "Show", + "desktop.problems.viewOptions": "View Options", "desktop.runConfig.runtimeArguments": "Runtime arguments", "desktop.runConfig.runtimeArgumentsPlaceholder": "One argument per line", "desktop.runConfig.entrypoint": "Entrypoint", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 1faed6aa27..c35d934b35 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -10871,7 +10871,19 @@ "desktop.problems.group.file": "按文件", "desktop.problems.group.severity": "按严重级别", "desktop.problems.group.none": "不分组", - "desktop.problems.groupBy": "分组:{arg1}", + "desktop.problems.groupHeading": "分组", + "desktop.problems.noOpenFile": "没有打开的文件。", + "desktop.problems.scope.file": "文件", + "desktop.problems.scope.fileCount": "文件 {count}", + "desktop.problems.scope.project": "项目", + "desktop.problems.scope.projectCount": "项目 {count}", + "desktop.problems.severity.error": "错误", + "desktop.problems.severity.hint": "提示", + "desktop.problems.severity.information": "信息", + "desktop.problems.severity.unknown": "未知严重级别", + "desktop.problems.severity.warning": "警告", + "desktop.problems.showHeading": "显示", + "desktop.problems.viewOptions": "视图选项", "desktop.runConfig.runtimeArguments": "运行时参数", "desktop.runConfig.runtimeArgumentsPlaceholder": "每行一个参数", "desktop.runConfig.entrypoint": "入口", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index f094fd0152..7ccff90a37 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -14422,46 +14422,133 @@ ] }, { - "id": "desktop.problems.groupBy", - "description": "Toolbar button that cycles the Problems grouping; {arg1} is the current grouping's name", + "id": "desktop.problems.groupHeading", + "description": "Heading over the grouping choices in the Problems View Options menu", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.noOpenFile", + "description": "Message in the Problems tool window's File tab while no file is open in the editor", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.previewEmpty", + "description": "Message in the Problems preview pane before a diagnostic with a file is selected", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.scope.file", + "description": "Problems tool window header tab that shows the current file's problems, while it has none", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.scope.fileCount", + "description": "Problems tool window header tab that shows the current file's problems; {count} is how many it has", "platforms": [ "desktop" ], "parameters": { - "arg1": "string" + "count": "integer" } }, { - "id": "desktop.problems.previewEmpty", - "description": "Message in the Problems preview pane before a diagnostic with a file is selected", + "id": "desktop.problems.scope.project", + "description": "Problems tool window header tab that shows the whole project's problems, while it has none", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.scope.projectCount", + "description": "Problems tool window header tab that shows the whole project's problems; {count} is how many it has", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "integer" + } + }, + { + "id": "desktop.problems.severity.error", + "description": "Problems tree node over the error diagnostics when grouped by severity", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.severity.hint", + "description": "Problems tree node over the hint diagnostics when grouped by severity", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.severity.information", + "description": "Problems tree node over the information diagnostics when grouped by severity", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.severity.unknown", + "description": "Problems tree node over the diagnostics with a missing or unknown severity when grouped by severity", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.severity.warning", + "description": "Problems tree node over the warning diagnostics when grouped by severity", "platforms": [ "desktop" ] }, { "id": "desktop.problems.showErrors", - "description": "Checkbox in the Problems toolbar that shows error diagnostics", + "description": "Checked item in the Problems View Options menu that shows error diagnostics", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.showHeading", + "description": "Heading over the severity checkboxes in the Problems View Options menu", "platforms": [ "desktop" ] }, { "id": "desktop.problems.showInfo", - "description": "Checkbox in the Problems toolbar that shows information and hint diagnostics", + "description": "Checked item in the Problems View Options menu that shows information and hint diagnostics", "platforms": [ "desktop" ] }, { "id": "desktop.problems.showPreview", - "description": "Checkbox above the Problems list that shows a read-only source preview of the selected diagnostic beside the list", + "description": "Toggle button in the Problems tool window's action column that shows a read-only source preview of the selected diagnostic beside the tree", "platforms": [ "desktop" ] }, { "id": "desktop.problems.showWarnings", - "description": "Checkbox in the Problems toolbar that shows warning diagnostics", + "description": "Checked item in the Problems View Options menu that shows warning diagnostics", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.problems.viewOptions", + "description": "Button in the Problems tool window's action column that opens the menu of severities shown and grouping", "platforms": [ "desktop" ] diff --git a/shared/platform-feature-matrix/features/diagnostics-workspace.json b/shared/platform-feature-matrix/features/diagnostics-workspace.json index 6dc6343a70..d4cd06eed1 100644 --- a/shared/platform-feature-matrix/features/diagnostics-workspace.json +++ b/shared/platform-feature-matrix/features/diagnostics-workspace.json @@ -7,20 +7,30 @@ "implementationStatus": "partial", "verificationStatus": "pending", "evidence": [ + "desktop/internal/core/problems.go", "desktop/internal/workbench/problems.go", - "desktop/internal/workbench/problems_view.go" + "desktop/internal/workbench/problems_view.go", + "desktop/internal/workbench/problems_preview.go", + "desktop/internal/workbench/shell_view.go", + "desktop/internal/workbench/problems_test.go", + "desktop/internal/workbench/problems_visual_test.go" ] }, "windows": { "implementationStatus": "partial", "verificationStatus": "pending", "evidence": [ + "desktop/internal/core/problems.go", "desktop/internal/workbench/problems.go", - "desktop/internal/workbench/problems_view.go" + "desktop/internal/workbench/problems_view.go", + "desktop/internal/workbench/problems_preview.go", + "desktop/internal/workbench/shell_view.go", + "desktop/internal/workbench/problems_test.go", + "desktop/internal/workbench/problems_visual_test.go" ] }, "owner": "Diagnostics", - "verification": "制造多个来源、多个文件的错误和警告,验证 Problems 的 File 随编辑器切换、关闭而更新,非文本编辑器显示打开文件提示,Project Errors 保留全部文件问题;检查无问题与严重程度过滤空状态,并按文件显示名称、路径和数量,紧凑问题行保留描述、行列和完整提示;在深浅主题及窄面板中检查标题、图标和悬停,并验证筛选、排序、定位和清除。检查左侧 View Options 与 Show Editor Preview;开启后单击及方向键更新右侧只读源码,双击和 Enter 定位主编辑器;拖动分栏、关闭再打开、切换文件和清空诊断,确认不抢焦点、不移动主编辑器 WebView、不接管保存屏障且会话随预览关闭释放。 在系统语言与应用语言不同时切换 English / 简体中文,检查 File、Project Errors、带文件名的空状态、过滤提示和预览失败文案跟随应用语言。 使用 Debug 的 --problems-demo,确认默认 File 显示 Main.java 的 8 条问题,切换 Project Errors 显示两个文件共 10 条问题;检查全部五种诊断级别、废弃与未使用标签、关联信息、长多行文案及 Unicode;点击后用上下键切换,确认只有行选择样式且没有列表外围蓝色焦点框,右侧不出现空查找浮层。退出后检查演示临时目录、进程清理,并比较 bundle 文件哈希不变。 检查 File 与 Project Errors 的全部级别图标使用 IDEA Community SVG,提示使用 intentionBulbGrey,未知级别使用 questionMark;在明暗主题核对对应变体。 文件分组复用 JavaFileIconResolver 显示类或接口图标;问题行的错误和警告使用 inspections 16×16 原始画布与内部留白,右上角统计继续使用 status 图标。 检查已有 Java 启动配置 sourcePath/mainClass 对应的文件显示原始 runnableMark 角标,普通类不显示;演示 Main.java 显示该角标。YAML 与 Java 类图标按主题加载上游明暗变体,application.yml 使用 YAMLFileType 的通用图标。 关闭源码预览后行选择背景仍保留,方向键选择离屏问题时列表自动滚动。 在文本文件、Agent Conversation 编辑器标签与原文本文件之间切换,确认 File 问题先清空再恢复;预览中不出现 Run/Debug 角标和动作,旧动作引用及原生 javaRunMarkerAction 不能启动进程。 #1662 LSP-17:两端的过滤、排序、分组和计数统一由 Core 的 lsp.problems.query 决定。默认按文件分组、文件内先按严重程度再按行列;文件按工作区相对路径的自然顺序排列(File2 在 File10 之前,大小写不敏感),未知严重程度排在最后。macOS 不再在文件内只按行列排序,Windows 不再用 localeCompare 比较绝对路径。在两端制造同名数字文件和多种严重程度的问题,确认顺序、计数、严重程度过滤、仅当前文件和搜索结果一致。", + "verification": "制造多个来源、多个文件的错误和警告,验证 Problems 的 File 随编辑器切换、关闭而更新,非文本编辑器显示打开文件提示,Project Errors 保留全部文件问题;检查无问题与严重程度过滤空状态,并按文件显示名称、路径和数量,紧凑问题行保留描述、行列和完整提示;在深浅主题及窄面板中检查标题、图标和悬停,并验证筛选、排序、定位和清除。检查左侧 View Options 与 Show Editor Preview;开启后单击及方向键更新右侧只读源码,双击和 Enter 定位主编辑器;拖动分栏、关闭再打开、切换文件和清空诊断,确认不抢焦点、不移动主编辑器 WebView、不接管保存屏障且会话随预览关闭释放。 在系统语言与应用语言不同时切换 English / 简体中文,检查 File、Project Errors、带文件名的空状态、过滤提示和预览失败文案跟随应用语言。 使用 Debug 的 --problems-demo,确认默认 File 显示 Main.java 的 8 条问题,切换 Project Errors 显示两个文件共 10 条问题;检查全部五种诊断级别、废弃与未使用标签、关联信息、长多行文案及 Unicode;点击后用上下键切换,确认只有行选择样式且没有列表外围蓝色焦点框,右侧不出现空查找浮层。退出后检查演示临时目录、进程清理,并比较 bundle 文件哈希不变。 检查 File 与 Project Errors 的全部级别图标使用 IDEA Community SVG,提示使用 intentionBulbGrey,未知级别使用 questionMark;在明暗主题核对对应变体。 文件分组复用 JavaFileIconResolver 显示类或接口图标;问题行的错误和警告使用 inspections 16×16 原始画布与内部留白,右上角统计继续使用 status 图标。 检查已有 Java 启动配置 sourcePath/mainClass 对应的文件显示原始 runnableMark 角标,普通类不显示;演示 Main.java 显示该角标。YAML 与 Java 类图标按主题加载上游明暗变体,application.yml 使用 YAMLFileType 的通用图标。 关闭源码预览后行选择背景仍保留,方向键选择离屏问题时列表自动滚动。 在文本文件、Agent Conversation 编辑器标签与原文本文件之间切换,确认 File 问题先清空再恢复;预览中不出现 Run/Debug 角标和动作,旧动作引用及原生 javaRunMarkerAction 不能启动进程。 #1662 LSP-17:两端的过滤、排序、分组和计数统一由 Core 的 lsp.problems.query 决定。默认按文件分组、文件内先按严重程度再按行列;文件按工作区相对路径的自然顺序排列(File2 在 File10 之前,大小写不敏感),未知严重程度排在最后。macOS 不再在文件内只按行列排序,Windows 不再用 localeCompare 比较绝对路径。在两端制造同名数字文件和多种严重程度的问题,确认顺序、计数、严重程度过滤、仅当前文件和搜索结果一致。 Viva:工具窗口标题栏显示“文件 N”和“项目 N”两个标签,默认打开文件标签;N 按显示选项统计当前编辑器文件和整个项目的问题,没有问题时只显示标签名,没有打开的文件时文件标签显示提示。左侧操作列依次为视图选项(显示错误、警告、信息与分组方式的菜单)、全部展开、全部收起和编辑器预览开关;树中文件节点显示文件图标、文件名、灰色目录和问题数,问题行显示严重程度图标、描述、来源和行号。折叠选中问题所在的文件节点后选中移到该节点,诊断消失后选中移到所在文件;树行、展开状态和选中移动全部由 Core 的 lsp.problems.query 计算。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -52,5 +62,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:问题面板(problems_view.go)按来源分组显示诊断,点击行经 openFileAtPosition 定位,列表过滤与排序由 Core 完成(problems.go);未找到编辑器预览(Show Editor Preview)及右侧只读源码联动,两者在 problems 相关文件中均无匹配。" + "notes": "Viva:问题工具窗口按 IDEA 的 Problems 窗口改为树形:标题栏“文件 / 项目”标签带问题数,左侧操作列含视图选项菜单、全部展开、全部收起和编辑器预览开关;文件或严重程度节点可展开收起,开启预览时单击只选中并在右侧只读源码显示所在行,双击或 Enter 定位主编辑器。树的可见行、节点展开状态、选中保持和移动由 Core lsp.problems.query 的 rows / selected 返回,宿主只绘制。尚未实现快速修复灯泡和“更多”菜单;macOS 原生整机和 Windows 实机均未验收。" }