diff --git a/desktop/internal/workbench/catalog.go b/desktop/internal/workbench/catalog.go index 59dfd24cd9..36fb56d9fd 100644 --- a/desktop/internal/workbench/catalog.go +++ b/desktop/internal/workbench/catalog.go @@ -575,7 +575,7 @@ func (a *App) reduceChrome(action core.ChromeAction) { // The Problems list copies the diagnostics it submits to Core. Drop that copy // when the tool window closes; opening it again asks Core for a fresh answer. if !a.chrome.isOpen(catalogIndex[itemProblems]) { - a.problems.reset() + a.resetProblems() } if !changed { return diff --git a/desktop/internal/workbench/difftab.go b/desktop/internal/workbench/difftab.go index 07c3b97641..fd26643f67 100644 --- a/desktop/internal/workbench/difftab.go +++ b/desktop/internal/workbench/difftab.go @@ -51,8 +51,10 @@ type diffSet struct { // ignoreSpace reads the diffs ignoring whitespace, for the tabs opened after it is set. ignoreSpace bool // mirroring counts the edits the Diff tabs and the documents are mirroring into each other - // (difftab_edit.go); a mirrored edit is not mirrored back. + // (difftab_edit.go); a mirrored edit is not mirrored back. origin is the second view whose + // edit a document is taking, so the document's mirror passes over the view it came from. mirroring int + origin *editorview.View } // find is the tab with id, nil when there is none. diff --git a/desktop/internal/workbench/difftab_edit.go b/desktop/internal/workbench/difftab_edit.go index 34586c06af..8447375613 100644 --- a/desktop/internal/workbench/difftab_edit.go +++ b/desktop/internal/workbench/difftab_edit.go @@ -3,6 +3,7 @@ package workbench import ( "path/filepath" "runtime" + "strings" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/editorview" @@ -52,23 +53,31 @@ func (a *App) diffEdited(t *diffTab, edit editorview.Edit) { if d == nil { return } - p.diffs.mirroring++ - ok := d.view.ApplyEdit(edit, true) - p.diffs.mirroring-- - if !ok { + if !a.editDocumentFrom(p, d, t.after.view, edit) { // The document and the side disagree on the text; the side shows the document again. a.rebuildDiff(t) } } -// mirrorDocumentEdit mirrors an edit of document d into the right side of every Diff tab that -// shows its file. The document's own undo already holds the edit, so the side does not record it. +// editDocumentFrom applies an edit the user made in from, a second view of document d (a Diff +// tab's side or the Problems preview), to the document as one undo step of its own. The +// document then mirrors it into its other second views, but not back into from. It reports +// false when the two disagree on the text, and the caller shows the document again. +func (a *App) editDocumentFrom(p *project, d *document, from *editorview.View, edit editorview.Edit) bool { + origin := p.diffs.origin + p.diffs.origin = from + ok := d.view.ApplyEdit(edit, true) + p.diffs.origin = origin + return ok +} + +// mirrorDocumentEdit mirrors an edit of document d into its second views: the right side of every +// Diff tab that shows its file and the editable preview that shows it, except the view the edit +// came from. The document's own undo already holds the edit, so a second view does not record it, +// and the report each view makes of the mirrored edit is not mirrored back. func (a *App) mirrorDocumentEdit(p *project, d *document, edit editorview.Edit) { - if p.diffs.mirroring > 0 { - return - } for _, t := range p.diffs.list { - if t.after == nil || !diffWritable(t) || diffTabPath(t) != d.path { + if t.after == nil || t.after.view == p.diffs.origin || !diffWritable(t) || diffTabPath(t) != d.path { continue } p.diffs.mirroring++ @@ -78,6 +87,7 @@ func (a *App) mirrorDocumentEdit(p *project, d *document, edit editorview.Edit) a.rebuildDiff(t) } } + a.mirrorPreviewEdit(p, d, edit) } // diffUndoChord takes the undo and redo chords of an editable side for its document, which owns @@ -87,21 +97,27 @@ func (a *App) diffUndoChord(t *diffTab, event gfx.KeyEvent) bool { if event.Release || event.Key != gfx.KeyUnknown { return false } - d := a.diffDocument(t) - if d == nil { - return false - } - modifier := gfx.ModifierControl - if runtime.GOOS == "darwin" { - modifier = gfx.ModifierMeta - } - if event.Modifiers&^gfx.ModifierShift != modifier || event.Text != "z" && event.Text != "Z" { + return documentUndoChord(a.diffDocument(t), event) +} + +// documentUndoChord takes back or does again in document d the edit an undo or redo chord pressed +// in a second view of it asks for, as the document holds the undo of every edit made in its views: +// Command+Z and Shift+Command+Z on macOS, Control+Z, Shift+Control+Z and Control+Y elsewhere. It +// reports false for any other key. +func documentUndoChord(d *document, event gfx.KeyEvent) bool { + if d == nil || event.Release || event.Key != gfx.KeyUnknown || event.Modifiers&^gfx.ModifierShift != primaryModifier() { return false } - if event.Modifiers&gfx.ModifierShift != 0 { + shift := event.Modifiers&gfx.ModifierShift != 0 + switch { + case strings.EqualFold(event.Text, "z") && shift: d.view.Redo() - } else { + case strings.EqualFold(event.Text, "z"): d.view.Undo() + case runtime.GOOS != "darwin" && strings.EqualFold(event.Text, "y") && !shift: + d.view.Redo() + default: + return false } return true } diff --git a/desktop/internal/workbench/documents.go b/desktop/internal/workbench/documents.go index b4878804a9..67a99c3b46 100644 --- a/desktop/internal/workbench/documents.go +++ b/desktop/internal/workbench/documents.go @@ -72,6 +72,11 @@ type document struct { path, name string languageID string view *editorview.View + // lens is a second view of the text that the user last typed or clicked in: the editable + // preview of the Problems tool window (source_preview.go). The language features follow its + // caret while it is set, so completion, hover and the rest work there as in the editor; nil + // when the document's own editor was the last to take a key or a press. + lens *editorview.View // conflict is the notice shown while the file changed on disk under unsaved edits. conflict conflictBanner // sync is the document's state in its language-server session. @@ -828,6 +833,7 @@ func (a *App) closeDocument(p *project, id int) { // removeDocument takes a tab away without asking about its text. The caller has saved it or // decided that it is going away: deleting its file, for one. func (a *App) removeDocument(p *project, d *document) { + a.closePreviewsOfDocument(d) d.find.dispose() d.cancelAutoSave() a.flushCheckpoint(p, d, false) @@ -839,6 +845,8 @@ func (a *App) removeDocument(p *project, d *document) { a.semanticTokensDropped(d) d.closeEditorView() p.docs.list = slices.DeleteFunc(p.docs.list, func(x *document) bool { return x.id == d.id }) + // The preview's language features may have opened it in a server. + a.closeDocumentInSession(p, d) } return } @@ -1017,6 +1025,16 @@ func (a *App) focusedDocument(id gfx.ID) *editorview.View { return nil } +// caretView is the view whose caret, selection and geometry the language features follow: the +// preview the user last worked in, or the document's own editor. Both show the same text, so a +// position or an offset is the same in either; the document's own view keeps the revision. +func (d *document) caretView() *editorview.View { + if d.lens != nil { + return d.lens + } + return d.view +} + func (d *document) closeEditorView() { if d.markerCancel != nil { d.markerCancel() diff --git a/desktop/internal/workbench/documents_tabless.go b/desktop/internal/workbench/documents_tabless.go index 51cc006acf..26b93af5dc 100644 --- a/desktop/internal/workbench/documents_tabless.go +++ b/desktop/internal/workbench/documents_tabless.go @@ -9,11 +9,11 @@ import ( ) // This file keeps the documents that have no tab (matrix id git-diff-review). The right side of a -// working-copy Diff tab edits the file's text, and an unopened file has no document to edit. Such a -// document is read in the background and joins the project's documents: it is saved, autosaved and -// checked on close like any other, but no group holds it and it takes no focus. The editor attaches a -// tab to it when the file is opened (selectDocument), and it is released when no Diff tab shows it -// and it is saved (releaseIdleTablessDocument). +// working-copy Diff tab and the Problems preview edit the file's text, and an unopened file has no +// document to edit. Such a document is read in the background and joins the project's documents: it +// is saved, autosaved and checked on close like any other, but no group holds it and it takes no +// focus. The editor attaches a tab to it when the file is opened (selectDocument), and it is released +// when no Diff tab and no editable preview shows it and it is saved (releaseIdleTablessDocument). // ensureTablessDocument makes sure the working-copy file of tab t has a document, opening it in the // background when none is open, and lays the tab out again when it has one. @@ -40,40 +40,60 @@ func (a *App) openTablessDocument(p *project, path string) { } p.docs.opening[path] = true registry := a.syntaxRegistry() - name := filepath.Base(path) kernel, _ := a.kernel.(editorKernel) a.background(p, 0, func(ctx context.Context) func(*App) { - read, err := readDocumentEncoded(ctx, kernel, path) - var content editorview.Content - var grammar *syntax.Syntax - languageID := "" - if err == nil { - content = editorview.Prepare(read.text) - grammar = registry.SyntaxForPath(path) - if language, ok := registry.ForPath(path); ok { - languageID = language.ID - } - } + file := readTablessFile(ctx, kernel, registry, path) return func(a *App) { delete(p.docs.opening, path) // A file that is not text, or that cannot be read, has no document; its Diff stays read only. - if err != nil || a.project != p || p.docs.byPath(path) != nil { + if file.err != nil || a.project != p || p.docs.byPath(path) != nil { return } - p.docs.next++ - d := a.newTablessDocument(p, p.docs.next, path, name, content, grammar, languageID) - d.encoding, d.hasBOM, d.diskBytes = read.encoding, read.hasBOM, read.disk - d.tabless = true - p.docs.list = append(p.docs.list, d) - for _, t := range p.diffs.list { - if diffWritable(t) && diffTabPath(t) == path { - a.rebuildDiff(t) - } - } + a.addTablessDocument(p, path, file) } }) } +// tablessFile is what a worker read of a file that becomes a document without a tab. +type tablessFile struct { + read documentRead + content editorview.Content + grammar *syntax.Syntax + languageID string + err error +} + +// readTablessFile reads path and prepares its text and grammar; it runs on a worker. +func readTablessFile(ctx context.Context, kernel editorKernel, registry *syntax.Registry, path string) tablessFile { + read, err := readDocumentEncoded(ctx, kernel, path) + file := tablessFile{read: read, err: err} + if err != nil { + return file + } + file.content = editorview.Prepare(read.text) + file.grammar = registry.SyntaxForPath(path) + if language, ok := registry.ForPath(path); ok { + file.languageID = language.ID + } + return file +} + +// addTablessDocument makes file the document of path without a tab and lays the Diff tabs of the +// file out again, so their right sides become editable. +func (a *App) addTablessDocument(p *project, path string, file tablessFile) *document { + p.docs.next++ + d := a.newTablessDocument(p, p.docs.next, path, filepath.Base(path), file.content, file.grammar, file.languageID) + d.encoding, d.hasBOM, d.diskBytes = file.read.encoding, file.read.hasBOM, file.read.disk + d.tabless = true + p.docs.list = append(p.docs.list, d) + for _, t := range p.diffs.list { + if diffWritable(t) && diffTabPath(t) == path { + a.rebuildDiff(t) + } + } + return d +} + // newTablessDocument makes the document of path with its editor, wired the way a tab's document is, // except for its tab, its input and its watch, which attachDocumentTab adds. func (a *App) newTablessDocument(p *project, id int, path, name string, content editorview.Content, grammar *syntax.Syntax, languageID string) *document { @@ -114,11 +134,11 @@ func (a *App) attachDocumentTab(p *project, d *document) bool { return true } -// releaseIdleTablessDocument releases the tabless document of path once no Diff tab shows the file -// and the document has nothing unsaved. +// releaseIdleTablessDocument releases the tabless document of path once no Diff tab and no editable +// preview shows the file and the document has nothing unsaved. func (a *App) releaseIdleTablessDocument(p *project, path string) { d := p.docs.byPath(path) - if d == nil || !d.tabless { + if d == nil || !d.tabless || a.previewShowsDocument(d) { return } for _, t := range p.diffs.list { diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index 02e19f077f..5cd13e7a5c 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -5,6 +5,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/editorview" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/vivaui/viva/app" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) @@ -203,7 +204,11 @@ func (a *App) documentInput(p *project, d *document) { result, _ := d.view.Scroll(event) return result }, - Text: d.view.TextInput, + // Typing in the document's own editor points the language features back at it. + Text: func(ctx app.TextInputContext) *app.TextInput { + d.lens = nil + return d.view.TextInput(ctx) + }, } d.draw = func(dc *ui.DrawContext) { v := d.view @@ -240,6 +245,13 @@ func (a *App) documentInput(p *project, d *document) { // documentKey gives a key pressed while the file's control has the keyboard to the language // popups, the language shortcuts and the editor. func (a *App) documentKey(p *project, d *document, event gfx.KeyEvent) gfx.EventResult { + d.lens = nil + return a.documentViewKey(p, d, d.view, event) +} + +// documentViewKey gives a key pressed in view, the document's own editor or its editable +// preview, to the language popups, the language shortcuts and view. +func (a *App) documentViewKey(p *project, d *document, view *editorview.View, event gfx.KeyEvent) gfx.EventResult { // A semantic request belongs to the caret it was placed at. Every key path ends here, so // one sync covers arrows, edits and commands. defer a.pluginSemanticsCaretSync() @@ -252,7 +264,7 @@ func (a *App) documentKey(p *project, d *document, event gfx.KeyEvent) gfx.Event if result, handled := a.lineEditKey(p, d, event); handled { return result } - if result, handled := d.view.Key(event); handled { + if result, handled := view.Key(event); handled { return result } return gfx.EventResult{} @@ -262,6 +274,11 @@ func (a *App) documentKey(p *project, d *document, event gfx.KeyEvent) gfx.Event // editor: the press on a text and the moves and the release of the selection it starts, // wherever they go. func (a *App) documentPointer(p *project, d *document, event gfx.PointerEvent) gfx.EventResult { + // A press puts the caret in the document's own editor; a move over it leaves the language + // features where the user works, so a list opened in the preview stays open. + if event.Kind == gfx.PointerDown { + d.lens = nil + } if event.Kind == gfx.PointerDown && event.Button == gfx.PointerButtonSecondary { if line, column, ok := d.view.PositionAt(event.X, event.Y); ok { a.editor.copyReference.click = &referenceClick{documentID: d.id, line: line, column: column} @@ -273,7 +290,7 @@ func (a *App) documentPointer(p *project, d *document, event gfx.PointerEvent) g if result, handled := a.documentLinkPointer(event, d); handled { return result } - if result, handled := a.pluginSemanticsPointer(event, p, d); handled { + if result, handled := a.pluginSemanticsPointer(event, p, d, d.view); handled { return result } result, _ := d.view.Pointer(event) @@ -396,6 +413,7 @@ func (a *App) terminalToolBody(c ui.C, p *project) { // (see windowShortcuts). func (a *App) onShortcut(event gfx.KeyEvent) gfx.EventResult { if !event.Release { + a.followKeyboardView(event.Target) if result := a.pluginSemanticsShortcut(event); result.Handled { return result } @@ -411,6 +429,9 @@ func (a *App) onShortcut(event gfx.KeyEvent) gfx.EventResult { if result := a.lineEditShortcut(event); result.Handled { return result } + if result, handled := a.sourcePreviewShortcut(event); handled { + return result + } if v := a.focusedDocument(event.Target); v != nil { if result, handled := v.Shortcut(event); handled { return result diff --git a/desktop/internal/workbench/lineedit.go b/desktop/internal/workbench/lineedit.go index 411f3f112f..28cd9a19d1 100644 --- a/desktop/internal/workbench/lineedit.go +++ b/desktop/internal/workbench/lineedit.go @@ -66,7 +66,7 @@ func lineOperationFor(event gfx.KeyEvent, primary gfx.Modifiers) (core.LineEditO // lineEditKey handles a line-operation key of the focused document, or reports it unhandled. func (a *App) lineEditKey(p *project, d *document, event gfx.KeyEvent) (gfx.EventResult, bool) { - if event.Target != d.hit { + if event.Target != d.hit && (d.lens == nil || !d.lens.Owns(event.Target)) { return gfx.EventResult{}, false } if result := a.navigationHistoryShortcut(event); result.Handled { @@ -97,10 +97,14 @@ func (a *App) lineEditShortcut(event gfx.KeyEvent) gfx.EventResult { // runLineOperation applies op to the document's selected lines. func (a *App) runLineOperation(p *project, d *document, op core.LineEditOperation) { kernel, ok := a.kernel.(editorKernel) - if !ok || p == nil || d == nil || d.virtual || d.view.ReadOnly() { + if !ok || p == nil || d == nil || d.virtual { return } - in, ok := d.view.LineEditInput() + view := d.caretView() + if view.ReadOnly() { + return + } + in, ok := view.LineEditInput() if !ok { return } @@ -134,8 +138,11 @@ func (a *App) runLineOperation(p *project, d *document, op core.LineEditOperatio if current == nil || a.project != p { return } - // A document that changed while Core worked keeps its newer text. - current.view.ApplyLineEdit(in, outcome.ReplacedStart, outcome.ReplacedLength, outcome.Text, outcome.SelectionStart, outcome.SelectionLength) + // A document that changed while Core worked keeps its newer text, and a view that went + // away takes nothing. + if view == current.view || view == current.lens { + view.ApplyLineEdit(in, outcome.ReplacedStart, outcome.ReplacedLength, outcome.Text, outcome.SelectionStart, outcome.SelectionLength) + } } }) } diff --git a/desktop/internal/workbench/plugindiagnostics.go b/desktop/internal/workbench/plugindiagnostics.go index b20e3e3d9f..ba868fca1d 100644 --- a/desktop/internal/workbench/plugindiagnostics.go +++ b/desktop/internal/workbench/plugindiagnostics.go @@ -265,8 +265,17 @@ func (a *App) projectDocumentMarkers(document *document) { document.markerGeneration++ generation, revision := document.markerGeneration, document.view.Revision() text, markers := document.view.TextSnapshot(), a.documentMarkers(document.path) + // The editable preview of the document shows the same text, so the markers' geometry is its + // too; its revision is its own. + preview, previewRevision := a.documentPreviewView(document), 0 + if preview != nil { + previewRevision = preview.Revision() + } if len(markers) == 0 { document.view.SetMarkers(nil) + if preview != nil { + preview.SetMarkers(nil) + } return } parent, cancel := context.WithCancel(a.project.ctx) @@ -289,6 +298,9 @@ func (a *App) projectDocumentMarkers(document *document) { return } document.view.SetProjectedMarkers(projected, revision) + if preview != nil && a.documentPreviewView(document) == preview { + preview.SetProjectedMarkers(projected, previewRevision) + } } }) } diff --git a/desktop/internal/workbench/pluginedits.go b/desktop/internal/workbench/pluginedits.go index 02f6b97225..9b86929065 100644 --- a/desktop/internal/workbench/pluginedits.go +++ b/desktop/internal/workbench/pluginedits.go @@ -43,7 +43,7 @@ func (a *App) pluginEditShortcut(event gfx.KeyEvent) gfx.EventResult { return gfx.EventResult{} } p, d := a.pluginSemanticHit(event.Target) - if d == nil || d.view.IsComposing() { + if d == nil || d.caretView().IsComposing() { return gfx.EventResult{} } a.startPluginFormattingAtSelection(p, d) @@ -60,7 +60,7 @@ func (a *App) startPluginEdit(kind semanticKind, p *project, d *document, positi // startPluginEditRequest is startPluginEdit with the request body prepared by the caller // except for the operation and URI, which are filled in here. func (a *App) startPluginEditRequest(kind semanticKind, p *project, d *document, body core.PluginSemanticRequest) { - if a.plugins == nil || p == nil || d == nil || a.project != p || d.view.IsComposing() { + if a.plugins == nil || p == nil || d == nil || a.project != p || d.caretView().IsComposing() { return } a.closeSemanticHover() @@ -117,7 +117,7 @@ func (a *App) startPluginFormatting(p *project, d *document) { // startPluginFormattingAtSelection formats the selected range, or the whole document // when nothing is selected. func (a *App) startPluginFormattingAtSelection(p *project, d *document) { - startLine, startColumn, endLine, endColumn, ok := d.view.SelectionUTF16() + startLine, startColumn, endLine, endColumn, ok := d.caretView().SelectionUTF16() if !ok { a.startPluginFormatting(p, d) return @@ -168,7 +168,7 @@ func (a *App) applySemanticFormatting(pending *semanticPending, event core.Backe func (a *App) applyEditsToDocument(p *project, d *document, edits []core.PluginTextEdit, operation string) { documentID, revision := d.id, d.view.Revision() snapshot := d.view.TextSnapshot() - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() caret, _ := d.view.ByteOffset(line, column) a.background(p, semanticApplyTimeout, func(ctx context.Context) func(*App) { applied, err := a.kernel.ApplyPluginTextEdits(ctx, snapshot.String(), edits) @@ -186,7 +186,7 @@ func (a *App) applyEditsToDocument(p *project, d *document, edits []core.PluginT if current != p || document == nil || a.project != p || document.view.Revision() != revision { return } - document.view.ApplyTextChange(change) + document.caretView().ApplyTextChange(change) } }) } diff --git a/desktop/internal/workbench/pluginrename.go b/desktop/internal/workbench/pluginrename.go index 59f3569633..0d533a6b66 100644 --- a/desktop/internal/workbench/pluginrename.go +++ b/desktop/internal/workbench/pluginrename.go @@ -65,7 +65,7 @@ type renameDocumentUpdate struct { // openPluginRename opens the rename dialog for the symbol at the caret. func (a *App) openPluginRename(p *project, d *document) { - if a.plugins == nil || p == nil || d == nil || a.project != p || d.view.IsComposing() { + if a.plugins == nil || p == nil || d == nil || a.project != p || d.caretView().IsComposing() { return } if _, ok := a.semanticServer(d); !ok { @@ -73,7 +73,7 @@ func (a *App) openPluginRename(p *project, d *document) { return } a.closePluginSemantics() - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() initial := identifierAt(d.view.TextSnapshot(), d.view, line, column) state := &a.semantics.rename *state = renameState{open: true, documentID: d.id, revision: d.view.Revision(), line: line, column: column, initial: initial} diff --git a/desktop/internal/workbench/pluginsemantics.go b/desktop/internal/workbench/pluginsemantics.go index 04a1f7753e..6ca2d7f1ad 100644 --- a/desktop/internal/workbench/pluginsemantics.go +++ b/desktop/internal/workbench/pluginsemantics.go @@ -245,7 +245,7 @@ type pluginSemantics struct { autoGeneration uint64 } -// pluginSemanticHit is the open document whose text is id. +// pluginSemanticHit is the open document whose text, or editable preview, is id. func (a *App) pluginSemanticHit(id gfx.ID) (*project, *document) { p := a.project if p == nil || id.IsZero() { @@ -256,7 +256,7 @@ func (a *App) pluginSemanticHit(id gfx.ID) (*project, *document) { return p, d } } - return nil, nil + return a.previewDocumentHit(id) } // currentSemanticDocument is the document a popup belongs to, and nil when the @@ -371,13 +371,13 @@ func (a *App) pluginSemanticsTrigger(event gfx.KeyEvent, p *project, d *document if event.Release || (event.Modifiers != 0 && event.Modifiers != gfx.ModifierShift) { return gfx.EventResult{}, false } - if d == nil || d.view.IsComposing() { + if d == nil || d.caretView().IsComposing() { return gfx.EventResult{}, false } if event.Modifiers == gfx.ModifierShift { switch event.Key { case gfx.KeyF12: - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() a.startPluginReferences(p, d, line, column) return gfx.EventResult{Handled: true, Repaint: true}, true case gfx.KeyF6: @@ -388,15 +388,15 @@ func (a *App) pluginSemanticsTrigger(event gfx.KeyEvent, p *project, d *document } switch event.Key { case gfx.KeyF12: - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() a.startPluginDefinition(p, d, line, column, true) return gfx.EventResult{Handled: true, Repaint: true}, true case gfx.KeyF2: a.openPluginRename(p, d) return gfx.EventResult{Handled: true, Repaint: true}, true case gfx.KeyF1: - line, column := d.view.CaretUTF16() - rect, _ := d.view.CaretRect() + line, column := d.caretView().CaretUTF16() + rect, _ := d.caretView().CaretRect() a.startPluginHover(p, d, line, column, rect, false, true) return gfx.EventResult{Handled: true, Repaint: true}, true } @@ -420,10 +420,10 @@ func (a *App) pluginSemanticsShortcut(event gfx.KeyEvent) gfx.EventResult { return gfx.EventResult{} } p, d := a.pluginSemanticHit(event.Target) - if d == nil || d.view.IsComposing() { + if d == nil || d.caretView().IsComposing() { return gfx.EventResult{} } - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() a.startPluginCompletion(p, d, line, column) return gfx.EventResult{Handled: true, Repaint: true} } @@ -436,17 +436,17 @@ func (a *App) declarationShortcut(event gfx.KeyEvent) gfx.EventResult { return gfx.EventResult{} } p, d := a.pluginSemanticHit(event.Target) - if d == nil || d.view.IsComposing() { + if d == nil || d.caretView().IsComposing() { return gfx.EventResult{} } - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() a.startPluginDefinition(p, d, line, column, true) return gfx.EventResult{Handled: true, Repaint: true} } -// pluginSemanticsPointer handles modifier-click definition and pointer hover. -// It runs before the editor's own pointer handling. -func (a *App) pluginSemanticsPointer(event gfx.PointerEvent, p *project, d *document) (gfx.EventResult, bool) { +// pluginSemanticsPointer handles modifier-click definition and pointer hover over view, the +// document's own editor or its editable preview. It runs before the view's own pointer handling. +func (a *App) pluginSemanticsPointer(event gfx.PointerEvent, p *project, d *document, view *editorview.View) (gfx.EventResult, bool) { switch event.Kind { case gfx.PointerDown: if a.semantics.completion.open || a.semantics.definition.open || a.semantics.hover.open { @@ -462,7 +462,7 @@ func (a *App) pluginSemanticsPointer(event gfx.PointerEvent, p *project, d *docu if event.Modifiers&modifier == 0 { return gfx.EventResult{}, false } - line, column, ok := d.view.PositionAt(event.X, event.Y) + line, column, ok := view.PositionAt(event.X, event.Y) if !ok { return gfx.EventResult{}, false } @@ -476,7 +476,7 @@ func (a *App) pluginSemanticsPointer(event gfx.PointerEvent, p *project, d *docu a.leaveSemanticHover() return gfx.EventResult{}, false } - line, column, ok := d.view.PositionAt(event.X, event.Y) + line, column, ok := view.PositionAt(event.X, event.Y) if !ok { a.leaveSemanticHover() return gfx.EventResult{}, false @@ -488,7 +488,7 @@ func (a *App) pluginSemanticsPointer(event gfx.PointerEvent, p *project, d *docu return gfx.EventResult{}, false } a.releaseSemanticHover() - a.pointPluginHover(p, d, line, column, hoverRowAnchor(d, event.X, event.Y)) + a.pointPluginHover(p, d, line, column, hoverRowAnchor(view, event.X, event.Y)) return gfx.EventResult{}, false case gfx.PointerExit: a.leaveSemanticHover() @@ -543,7 +543,7 @@ func (a *App) startPluginLocations(kind semanticKind, p *project, d *document, l if a.plugins == nil || p == nil || d == nil || a.project != p { return } - if d.view.IsComposing() { + if d.caretView().IsComposing() { return } a.closeSemanticHover() @@ -587,7 +587,7 @@ func (a *App) startPluginHover(p *project, d *document, line, column int, anchor if a.plugins == nil || p == nil || d == nil || a.project != p { return } - if d.view.IsComposing() { + if d.caretView().IsComposing() { return } a.closeSemanticCompletion() @@ -665,11 +665,11 @@ func (a *App) requestPluginCompletion(p *project, d *document, line, column int, if a.plugins == nil || p == nil || d == nil || a.project != p { return } - if d.view.IsComposing() { + if d.caretView().IsComposing() { return } if automatic { - if caretLine, caretColumn := d.view.CaretUTF16(); caretLine != line || caretColumn != column { + if caretLine, caretColumn := d.caretView().CaretUTF16(); caretLine != line || caretColumn != column { return } } @@ -767,12 +767,12 @@ func (a *App) scheduleAutoCompletion(p *project, d *document, edit editorview.Ed a.semantics.autoCancel() a.semantics.autoCancel = nil } - if a.plugins == nil || a.project != p || d.view.IsComposing() { + if a.plugins == nil || a.project != p || d.caretView().IsComposing() { return } // An incomplete list is asked again on every word character typed while it is open. if completion := a.semantics.completion; completion.open && completion.incomplete && completion.documentID == d.id && isWordInsert(edit) { - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() a.requestPluginCompletion(p, d, line, column, completionTriggerContext(), true) return } @@ -792,7 +792,7 @@ func (a *App) scheduleAutoCompletion(p *project, d *document, edit editorview.Ed if !ok { return } - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() delay := a.semantics.autoDelay if delay == 0 { delay = semanticAutoCompletionDelay @@ -1212,7 +1212,7 @@ func (a *App) semanticPositionCurrent(pending *semanticPending, d *document) boo if !pending.requireCaret { return true } - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() return line == pending.line && column == pending.column } @@ -1313,7 +1313,7 @@ func (a *App) acceptPluginCompletion(index int) { if current != p || document == nil || a.project != p || document.view.Revision() != revision { return } - document.view.ApplyTextChange(change) + document.caretView().ApplyTextChange(change) } }) } @@ -1530,7 +1530,7 @@ func (a *App) pluginSemanticsCaretSync() { a.closeSemanticCompletion() return } - line, column := d.view.CaretUTF16() + line, column := d.caretView().CaretUTF16() if d.view.Revision() != state.completion.revision || line != state.completion.line || column != state.completion.column { a.closeSemanticCompletion() } diff --git a/desktop/internal/workbench/pluginsemantics_hover.go b/desktop/internal/workbench/pluginsemantics_hover.go index ff0b611a35..b75d536a73 100644 --- a/desktop/internal/workbench/pluginsemantics_hover.go +++ b/desktop/internal/workbench/pluginsemantics_hover.go @@ -10,6 +10,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/editor/rope" "github.com/1lck/Lithe-IDEA/desktop/internal/editor/syntax" + "github.com/1lck/Lithe-IDEA/desktop/internal/editorview" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/vivaui/viva/components" "github.com/vivaui/viva/gfx" @@ -540,9 +541,9 @@ func isHoverWordRune(r rune) bool { // hoverRowAnchor is the rectangle a pointer hover is placed under: the pointer's x across the // whole row it is on, so the popup starts right below the row and not over the next line. -func hoverRowAnchor(d *document, x, y float32) gfx.Rect { - height := d.view.LineHeight() - if _, fraction, ok := d.view.LineRowAt(y); ok && height > 0 { +func hoverRowAnchor(view *editorview.View, x, y float32) gfx.Rect { + height := view.LineHeight() + if _, fraction, ok := view.LineRowAt(y); ok && height > 0 { return gfx.Rect{X: x, Y: y - fraction*height, Height: height} } return gfx.Rect{X: x, Y: y} diff --git a/desktop/internal/workbench/pluginsemantics_view.go b/desktop/internal/workbench/pluginsemantics_view.go index cd05bcd7b0..74398e8bce 100644 --- a/desktop/internal/workbench/pluginsemantics_view.go +++ b/desktop/internal/workbench/pluginsemantics_view.go @@ -61,7 +61,7 @@ func (a *App) definitionPopup(c ui.C) { a.closeSemanticDefinition() return } - anchor, ok := d.view.CaretRect() + anchor, ok := d.caretView().CaretRect() if !ok { a.closeSemanticDefinition() return @@ -94,7 +94,7 @@ func (a *App) completionPopup(c ui.C) { a.closeSemanticCompletion() return } - anchor, ok := d.view.CaretRect() + anchor, ok := d.caretView().CaretRect() if !ok { a.closeSemanticCompletion() return diff --git a/desktop/internal/workbench/problems.go b/desktop/internal/workbench/problems.go index 2557e8a43e..1184406af7 100644 --- a/desktop/internal/workbench/problems.go +++ b/desktop/internal/workbench/problems.go @@ -66,7 +66,7 @@ type problemsView struct { 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 + // show says the Show Editor Preview option is on: an editable source view beside the tree // shows the selected diagnostic's line. preview is that view. show bool preview sourcePreview @@ -78,6 +78,12 @@ type problemsView struct { groupBy string } +// resetProblems is reset with the document without a tab that only the preview kept released. +func (a *App) resetProblems() { + a.closeSourcePreview(&a.problems.preview) + a.problems.reset() +} + // 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() { diff --git a/desktop/internal/workbench/problems_preview.go b/desktop/internal/workbench/problems_preview.go index a8cfb436d0..f465b33ff7 100644 --- a/desktop/internal/workbench/problems_preview.go +++ b/desktop/internal/workbench/problems_preview.go @@ -1,36 +1,64 @@ package workbench import ( + "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) -// 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. +// The Problems tree's preview is the shared source view (sourcePreview), editable: it shows the +// document of the selected row's diagnostic file, reveals its line and colors that line by the +// diagnostic's severity. The user fixes the problem there as in the editor; an edit reaches the +// file's tab at once and the other way round, and the language features work at its caret. -// 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) { +// problemsLineTint is how much of a severity's color the preview lays under its diagnostic's +// line: enough to tell an error from a warning at a glance, little enough to keep the code +// readable in both themes. +const problemsLineTint = 0.22 + +// selectedProblem is the diagnostic the selected row shows: its own, or a node's first one; +// false when nothing with a file is selected. +func (v *problemsView) selectedProblem() (core.ProblemsDiagnostic, bool) { item, ok := v.shown(v.selectedRow) if !ok || item.FileKey == "" { - return "", 0, false + return core.ProblemsDiagnostic{}, false } - return item.FileKey, item.Line, true + return item, true +} + +// problemLineColor is the tint the preview gives the line of a diagnostic of severity: the +// severity's mark color, red for errors, yellow for warnings and blue for the rest. +func (a *App) problemLineColor(severity int) gfx.Color { + _, color := a.problemSeverityMark(severity) + color.Alpha *= problemsLineTint + return color } // syncProblemsPreview follows the selection while the preview is on. A new file starts a load; the -// same file only moves the reveal. With nothing selected the last preview stays. -func (a *App) syncProblemsPreview(p *project) { +// same file only moves the reveal and the line's color. With nothing selected the last preview +// stays. While the preview has the keyboard (focused) the user works in it: an edit that moves or +// fixes the selected diagnostic changes only the line's color, not the caret or the file shown. +func (a *App) syncProblemsPreview(p *project, focused gfx.ID) { v := &a.problems if !v.show { return } - path, line, ok := v.selectedProblemLocation() + item, ok := v.selectedProblem() if !ok { return } - a.showSourcePreview(p, &v.preview, path, line+1, func(a *App) bool { return a.problems.show }) + sp := &v.preview + if sp.view != nil && sp.view.Owns(focused) { + if item.FileKey == sp.path { + sp.markLine(item.Line+1, a.problemLineColor(item.Severity)) + } else { + sp.markLine(0, gfx.Color{}) + } + return + } + a.showSourcePreview(p, sp, item.FileKey, item.Line+1, func(a *App) bool { return a.problems.show }) + sp.markLine(item.Line+1, a.problemLineColor(item.Severity)) } // problemsPreviewPane declares the preview beside the tree, or the reason there is none. diff --git a/desktop/internal/workbench/problems_test.go b/desktop/internal/workbench/problems_test.go index 3e6b210add..6ae70ac97e 100644 --- a/desktop/internal/workbench/problems_test.go +++ b/desktop/internal/workbench/problems_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/editorview" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/plugindiag" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" @@ -288,8 +289,8 @@ func TestClosingAProblemsNodeHandsItTheSelectionOfADiagnosticUnderIt(t *testing. 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") + if d := h.app.project.docs.byPath(v.diagnostics[v.result.Rows[2].Shows].FileKey); d != nil && !d.tabless { + t.Fatal("a click with the preview on opened the file in a tab") } h.app.toggleProblemsNode(a) @@ -298,8 +299,8 @@ func TestClosingAProblemsNodeHandsItTheSelectionOfADiagnosticUnderIt(t *testing. 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) + if item, ok := v.selectedProblem(); !ok || item.FileKey != v.result.Groups[0].FileKey || item.Line != 0 { + t.Fatalf("node shows %q:%d (%v)", item.FileKey, item.Line, ok) } h.app.expandProblems(false) @@ -414,7 +415,8 @@ func TestProblemsCacheIsDroppedWhenThePanelCloses(t *testing.T) { } // With the preview on, a click on a diagnostic only selects it: the shared source preview shows its -// file at its line without opening an editor, and a file that cannot be read shows why. +// file at its line as a document without a tab, released when the preview moves on, and a file that +// cannot be read shows why. func TestProblemsPreviewFollowsTheSelectedDiagnostic(t *testing.T) { h := newHarness(t, &testKernel{Client: core.NewClient()}) root := t.TempDir() @@ -426,6 +428,8 @@ func TestProblemsPreviewFollowsTheSelectedDiagnostic(t *testing.T) { h.open(root) h.app.pluginDiagnostics = map[string]*plugindiag.Set{"demo": problemSet(t, plugindiag.Diagnostic{FileKey: present, DisplayPath: "present.txt", Line: 2, Column: 0, Severity: plugindiag.SeverityError, Message: "on two"}, + plugindiag.Diagnostic{FileKey: present, DisplayPath: "present.txt", Line: 2, Column: 2, Severity: plugindiag.SeverityWarning, Message: "also on two"}, + plugindiag.Diagnostic{FileKey: present, DisplayPath: "present.txt", Line: 0, Column: 0, Severity: plugindiag.SeverityInformation, Message: "on zero"}, plugindiag.Diagnostic{FileKey: missing, DisplayPath: "missing.txt", Line: 0, Column: 0, Severity: plugindiag.SeverityWarning, Message: "gone"}, )} h.app.markProblemsChanged() @@ -439,8 +443,27 @@ func TestProblemsPreviewFollowsTheSelectedDiagnostic(t *testing.T) { 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) } - if h.app.project.docs.byPath(present) != nil { - t.Fatal("selecting a diagnostic with the preview on opened its file") + if d := h.app.project.docs.byPath(present); d == nil || !d.tabless || preview.doc != d { + t.Fatal("the preview does not edit the file's document without a tab") + } + // The line is colored by the severity of the selected diagnostic: red for the error, yellow + // for a warning on the same line, blue for information on another. + for _, step := range []struct { + message string + line int + severity int + }{{"on two", 3, 1}, {"also on two", 3, 2}, {"on zero", 1, 3}} { + if step.message != "on two" { + h.clickNamed(problemsRowNamed(t, h, problemsDiagnosticRow(t, h, step.message))) + h.settleChain() + } + want := lineTint{line: step.line, color: h.app.problemLineColor(step.severity)} + if preview.tinted != want { + t.Fatalf("%s: preview marks %+v, want %+v", step.message, preview.tinted, want) + } + } + if failure, warning, information := h.app.problemLineColor(1), h.app.problemLineColor(2), h.app.problemLineColor(3); failure == warning || warning == information || failure == information { + t.Fatalf("severities share a line color: %v %v %v", failure, warning, information) } h.clickNamed(problemsRowNamed(t, h, gone)) @@ -448,6 +471,98 @@ func TestProblemsPreviewFollowsTheSelectedDiagnostic(t *testing.T) { if preview.path != missing || preview.view != nil { t.Fatalf("preview of an unreadable file = %q, view %v", preview.path, preview.view != nil) } + if h.app.project.docs.byPath(present) != nil { + t.Fatal("the clean document without a tab outlived its preview") + } +} + +// The preview edits the file's document as a second editor of it: typing there reaches the file's +// tab and points the language features at the preview's caret, an edit in the tab reaches the +// preview, an undo chord in the preview takes back the document's edit, and while the preview has +// the keyboard a new list of diagnostics recolors the line without moving the caret. +func TestProblemsPreviewEditsTheDocument(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + root := t.TempDir() + path := filepath.Join(root, "a.txt") + if err := os.WriteFile(path, []byte("zero\none\ntwo\n"), 0o600); err != nil { + t.Fatal(err) + } + h.open(root) + p := h.app.project + h.app.openFile(p, path) + h.settle() + d := p.docs.byPath(path) + if d == nil || d.tabless { + t.Fatal("the file did not open in a tab") + } + publish := func(line int) { + h.app.pluginDiagnostics = map[string]*plugindiag.Set{"demo": problemSet(t, + plugindiag.Diagnostic{FileKey: path, DisplayPath: "a.txt", Line: line, Column: 0, Severity: plugindiag.SeverityError, Message: "broken"}, + )} + h.app.markProblemsChanged() + } + publish(1) + h.app.problems.show, h.app.problems.project = true, true + openProblemsPanel(t, h) + preview := &h.app.problems.preview + h.clickNamed(problemsRowNamed(t, h, problemsDiagnosticRow(t, h, "broken"))) + awaitDocumentState(t, h, func() bool { return preview.view != nil && preview.path == path }) + if preview.doc != d { + t.Fatal("the preview does not edit the open document") + } + text := func(v *editorview.View) string { + data, _ := v.Text() + return string(data) + } + + h.click(center(h.hit(preview.hit))) + preview.view.GoToLine(2) + if err := h.driver.Type("X"); err != nil { + t.Fatal(err) + } + h.settle() + if got := text(d.view); got != "zero\nXone\ntwo\n" || !d.dirty() { + t.Fatalf("the document after typing in the preview = %q (unsaved %v)", got, d.dirty()) + } + if d.caretView() != preview.view { + t.Fatal("the language features do not follow the preview's caret") + } + if hp, hd := h.app.pluginSemanticHit(preview.hit); hp != p || hd != d { + t.Fatal("the preview's text is not a semantic target of its document") + } + + d.view.ApplyEdit(editorview.Edit{Text: "// "}, true) + if got := text(preview.view); got != "// zero\nXone\ntwo\n" { + t.Fatalf("the preview after an edit in the tab = %q", got) + } + if handled, err := h.driver.ShortcutChord(primaryModifier(), 'z'); err != nil || !handled { + t.Fatalf("the undo chord in the preview: handled %v, %v", handled, err) + } + h.settle() + if got, shown := text(d.view), text(preview.view); got != "zero\nXone\ntwo\n" || shown != got { + t.Fatalf("undo in the preview left the document %q and the preview %q", got, shown) + } + + // A list in which the diagnostic moved down recolors its new line; the caret stays. + line, column := preview.view.Caret() + publish(2) + awaitProblems(t, h) + h.settle() + if item, ok := h.app.problems.selectedProblem(); !ok || item.Line != 2 { + t.Fatalf("the selection after the new list = %+v (%v)", item, ok) + } + if l, c := preview.view.Caret(); l != line || c != column { + t.Fatalf("the caret moved from %d:%d to %d:%d while the preview had the keyboard", line, column, l, c) + } + if want := (lineTint{line: 3, color: h.app.problemLineColor(int(plugindiag.SeverityError))}); preview.tinted != want { + t.Fatalf("the preview marks %+v, want %+v", preview.tinted, want) + } + + // A press in the tab points the language features back at it. + h.click(center(h.hit(d.hit))) + if d.caretView() != d.view { + t.Fatal("the language features stay on the preview after a press in the tab") + } } // A serve loop that ends without an explicit stop (a crash or self-exit) still diff --git a/desktop/internal/workbench/problems_view.go b/desktop/internal/workbench/problems_view.go index c9ca4e52d3..1009def6d3 100644 --- a/desktop/internal/workbench/problems_view.go +++ b/desktop/internal/workbench/problems_view.go @@ -67,7 +67,7 @@ func (a *App) problemsContent(c ui.C, p *project, lang i18n.Language) { a.problemsTree(c, p, lang) return } - a.syncProblemsPreview(p) + a.syncProblemsPreview(p, c.Canvas().Focused()) if v.split.Pos <= 0 { v.split.Pos = problemsTreeWidth } @@ -127,7 +127,7 @@ func (a *App) problemsToolbar(c ui.C, lang i18n.Language) { a.performed("workspace.problems.preview", surfaceButton) v.show = !v.show if !v.show { - v.preview.close() + a.closeSourcePreview(&v.preview) } }) } @@ -345,8 +345,9 @@ func problemsProjectTabText(lang i18n.Language, count int) string { 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 -// severities read as information, as Core ranks them. +// problemSeverityMark is the icon and color of an LSP severity: red for errors, yellow for +// warnings, and blue for information and hints. Unknown severities read as information, as Core +// ranks them. The preview colors a diagnostic's line with the same color. func (a *App) problemSeverityMark(severity int) (gfx.Icon, gfx.Color) { switch severity { case 1: @@ -354,7 +355,7 @@ func (a *App) problemSeverityMark(severity int) (gfx.Icon, gfx.Color) { case 2: return icons.CircleAlert, a.colors.Warning default: - return icons.Info, a.colors.Subtle + return icons.Info, a.colors.Accent } } diff --git a/desktop/internal/workbench/source_preview.go b/desktop/internal/workbench/source_preview.go index 40ae93b6fb..da16a5e83b 100644 --- a/desktop/internal/workbench/source_preview.go +++ b/desktop/internal/workbench/source_preview.go @@ -6,14 +6,20 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/editor/syntax" "github.com/1lck/Lithe-IDEA/desktop/internal/editorview" + "github.com/vivaui/viva/app" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) -// sourcePreview is a read-only view of one file that follows a selection in a list -// (Search Everywhere, Problems, References). It never takes the window's keyboard focus -// or writes the file, and an open document lends it its current text, so unsaved edits -// show. +// sourcePreview is a view of one file that follows a selection in a list (Search Everywhere, +// Problems, References). It shows an open document's current text, so unsaved edits show. +// +// A read-only preview never writes the file. An editable one (the Problems preview) is a second +// editor of the file's document, as the right side of a working-copy Diff tab is: an edit made in +// either view reaches the other at once, the document keeps the undo and saves the file, and a +// file that has no tab opens as a document without one (documents_tabless.go), which is released +// when the preview moves on and nothing of it is unsaved. The language features follow the +// preview's caret while the user works there (document.lens). type sourcePreview struct { // path is the file shown and line the one-based line revealed. A load replaces // view when its answer arrives for the same generation. @@ -25,19 +31,124 @@ type sourcePreview struct { hit gfx.ID input ui.Handlers draw func(*ui.DrawContext) + // tint colors line tintLine under its text, as the Problems preview marks its diagnostic's + // line in the color of the diagnostic's severity; a transparent tint marks nothing. tinted is + // the mark the view was last given, so a rebuild that asks for the same mark does not set it + // again. + tint gfx.Color + tintLine int + tinted lineTint + // doc is the document an editable preview (editablePreviews) edits and project its project, + // once the preview shows it. + doc *document + project *project } -// close releases the view's highlighter and forgets the file. +// lineTint is a one-based line and the color it is marked with; the zero value marks nothing. +type lineTint struct { + line int + color gfx.Color +} + +// close releases the view's highlighter and forgets the file. The document an editable preview +// showed stays; closeSourcePreview also releases it when only the preview kept it. func (sp *sourcePreview) close() { if sp.view != nil { sp.view.Close() } + if sp.doc != nil && sp.doc.lens == sp.view { + sp.doc.lens = nil + } sp.view = nil + sp.doc, sp.project = nil, nil sp.path = "" sp.failure = nil + sp.tinted = lineTint{} sp.generation++ } +// markLine colors one-based line with tint, or marks nothing when tint is transparent. A view that +// is still loading gets the mark when it arrives. +func (sp *sourcePreview) markLine(line int, tint gfx.Color) { + sp.tintLine, sp.tint = line, tint + sp.applyTint() +} + +// applyTint gives the view the mark of the tinted line when it has a different one. +func (sp *sourcePreview) applyTint() { + if sp.view == nil { + return + } + want := lineTint{line: sp.tintLine, color: sp.tint} + if want.line <= 0 || want.color.Alpha == 0 { + want = lineTint{} + } + if want == sp.tinted { + return + } + sp.tinted = want + if want.line == 0 { + sp.view.SetLineHighlights(nil) + return + } + sp.view.SetLineHighlights([]editorview.LineHighlight{{StartLine: want.line - 1, EndLine: want.line - 1, Color: want.color}}) +} + +// editablePreviews are the previews that edit their file's document. +func (a *App) editablePreviews() [1]*sourcePreview { + return [1]*sourcePreview{&a.problems.preview} +} + +// previewEditable reports whether sp edits its file's document. +func (a *App) previewEditable(sp *sourcePreview) bool { + for _, e := range a.editablePreviews() { + if e == sp { + return true + } + } + return false +} + +// closeSourcePreview closes sp and releases the document without a tab that only it kept. +func (a *App) closeSourcePreview(sp *sourcePreview) { + d, p := sp.doc, sp.project + sp.close() + if d != nil && p != nil && a.project == p && d.tabless { + a.releaseIdleTablessDocument(p, d.path) + } +} + +// previewShowsDocument reports whether an editable preview edits document d, which keeps a +// document without a tab from being released under it. +func (a *App) previewShowsDocument(d *document) bool { + for _, sp := range a.editablePreviews() { + if sp.doc == d { + return true + } + } + return false +} + +// documentPreviewView is the view of the editable preview that edits document d, or nil. +func (a *App) documentPreviewView(d *document) *editorview.View { + for _, sp := range a.editablePreviews() { + if sp.doc == d && sp.view != nil { + return sp.view + } + } + return nil +} + +// closePreviewsOfDocument closes every editable preview that edits document d, which is going +// away; the next frame shows the file again from what is left. +func (a *App) closePreviewsOfDocument(d *document) { + for _, sp := range a.editablePreviews() { + if sp.doc == d { + sp.close() + } + } +} + // show makes the preview follow path and line: a new file starts a load, the same // file only moves the reveal. alive reports whether the preview is still wanted when // a load finishes. @@ -54,6 +165,10 @@ func (a *App) showSourcePreview(p *project, sp *sourcePreview, path string, line } return } + if a.previewEditable(sp) { + a.showEditablePreview(p, sp, path, line, alive) + return + } sp.close() sp.path, sp.line = path, line generation := sp.generation @@ -92,6 +207,181 @@ func (a *App) showSourcePreview(p *project, sp *sourcePreview, path string, line }) } +// showEditablePreview makes the editable preview show the document of path: the open one, or +// one without a tab read in the background. The document the preview showed before is released +// when only the preview kept it. +func (a *App) showEditablePreview(p *project, sp *sourcePreview, path string, line int, alive func(*App) bool) { + a.closeSourcePreview(sp) + sp.path, sp.line = path, line + if d := p.docs.byPath(path); d != nil { + a.bindSourcePreview(p, sp, d) + return + } + generation := sp.generation + registry := a.syntaxRegistry() + kernel, _ := a.kernel.(editorKernel) + a.background(p, 0, func(ctx context.Context) func(*App) { + file := readTablessFile(ctx, kernel, registry, path) + return func(a *App) { + if sp.generation != generation || a.project != p || !alive(a) { + return + } + // A document opened meanwhile, by a tab or a Diff tab, is the one to edit. + d := p.docs.byPath(path) + if d == nil { + if file.err != nil { + sp.failure = file.err + return + } + d = a.addTablessDocument(p, path, file) + } + a.bindSourcePreview(p, sp, d) + } + }) +} + +// bindSourcePreview makes the editable view of document d, which shares the document's text, +// and reveals the line. +func (a *App) bindSourcePreview(p *project, sp *sourcePreview, d *document) { + var view *editorview.View + view = editorview.New(editorview.Config{ + Label: d.name, + Content: d.view.CopyContent(), + Syntax: a.syntaxRegistry().SyntaxForPath(d.path), + Notify: a.invalidator.Invalidate, + Save: func() { a.saveDocument(p, d.id) }, + OnEdit: func(edit editorview.Edit) { a.previewEdited(p, sp, view, edit) }, + }) + view.SetReadOnly(d.view.ReadOnly()) + view.SetWrap(false) + view.SetMinimap(false) + if sp.line > 0 { + view.GoToLine(sp.line) + } + sp.view, sp.doc, sp.project = view, d, p + sp.applyTint() + sp.input = a.editablePreviewInput(p, d, view) + sp.draw = a.sourcePreviewDraw(sp) + // The preview underlines the document's diagnostics too. + a.projectDocumentMarkers(d) +} + +// previewEdited gives the document an edit the user made in its preview, as one undo step of the +// document. A mirrored edit is not given back. +func (a *App) previewEdited(p *project, sp *sourcePreview, view *editorview.View, edit editorview.Edit) { + if p.diffs.mirroring > 0 { + return + } + d := sp.doc + if d == nil || sp.view != view || a.project != p { + return + } + if !a.editDocumentFrom(p, d, view, edit) { + // The preview and its document disagree on the text; the preview shows the document again. + p.diffs.mirroring++ + view.ShowContent(d.view.CopyContent()) + p.diffs.mirroring-- + } +} + +// mirrorPreviewEdit mirrors an edit of document d into the editable preview that shows it, unless +// the edit came from there. The document's undo already holds it, so the preview does not record it. +func (a *App) mirrorPreviewEdit(p *project, d *document, edit editorview.Edit) { + for _, sp := range a.editablePreviews() { + if sp.doc != d || sp.view == nil || sp.view == p.diffs.origin { + continue + } + p.diffs.mirroring++ + if !sp.view.ApplyEdit(edit, false) { + sp.view.ShowContent(d.view.CopyContent()) + } + p.diffs.mirroring-- + } +} + +// editablePreviewInput makes the handlers of the editable preview view of document d. They are +// the document's own: a key, a press or typing there points the language features at the +// preview, and an undo or redo chord takes back or does again the document's edits. +func (a *App) editablePreviewInput(p *project, d *document, view *editorview.View) ui.Handlers { + return ui.Handlers{ + Role: gfx.RoleTerminal, + Key: func(event gfx.KeyEvent) gfx.EventResult { + d.lens = view + if documentUndoChord(d, event) { + return gfx.EventResult{Handled: true, Repaint: true} + } + return a.documentViewKey(p, d, view, event) + }, + Pointer: func(event gfx.PointerEvent) gfx.EventResult { + if event.Kind == gfx.PointerDown { + d.lens = view + } + defer a.pluginSemanticsCaretSync() + if result, handled := a.pluginSemanticsPointer(event, p, d, view); handled { + return result + } + result, _ := view.Pointer(event) + return result + }, + Scroll: func(event gfx.ScrollEvent) gfx.EventResult { + a.pluginSemanticsScrolled(d) + result, _ := view.Scroll(event) + return result + }, + Text: func(ctx app.TextInputContext) *app.TextInput { + d.lens = view + return view.TextInput(ctx) + }, + } +} + +// sourcePreviewShortcut handles a chord pressed while an editable preview has the keyboard: undo +// and redo go to its document, the other editor chords (copy, cut, paste, select all, save) to +// the preview. +func (a *App) sourcePreviewShortcut(event gfx.KeyEvent) (gfx.EventResult, bool) { + for _, sp := range a.editablePreviews() { + if sp.doc == nil || sp.view == nil || !sp.view.Owns(event.Target) { + continue + } + if documentUndoChord(sp.doc, event) { + return gfx.EventResult{Handled: true, Repaint: true}, true + } + return sp.view.Shortcut(event) + } + return gfx.EventResult{}, false +} + +// followKeyboardView points the language features of the document whose editor or editable +// preview has the keyboard (id) at that view, before a chord acts on its caret. +func (a *App) followKeyboardView(id gfx.ID) { + p := a.project + if p == nil || id.IsZero() { + return + } + for _, sp := range a.editablePreviews() { + if sp.doc != nil && sp.view != nil && sp.view.Owns(id) { + sp.doc.lens = sp.view + return + } + } + for _, d := range p.docs.list { + if d.view.Owns(id) { + d.lens = nil + return + } + } +} + +// previewDocumentHit is the project and document of the editable preview whose text is id. +func (a *App) previewDocumentHit(id gfx.ID) (*project, *document) { + for _, sp := range a.editablePreviews() { + if sp.doc != nil && sp.view != nil && sp.hit == id && sp.project == a.project { + return sp.project, sp.doc + } + } + return nil, nil +} + // installSourcePreview makes the read-only view of the loaded text and reveals the line. func (a *App) installSourcePreview(sp *sourcePreview, content editorview.Content, grammar *syntax.Syntax) { view := editorview.New(editorview.Config{ @@ -107,6 +397,7 @@ func (a *App) installSourcePreview(sp *sourcePreview, content editorview.Content view.GoToLine(sp.line) } sp.view = view + sp.applyTint() sp.input = ui.Handlers{ Role: gfx.RoleTerminal, Key: func(event gfx.KeyEvent) gfx.EventResult { @@ -122,7 +413,13 @@ func (a *App) installSourcePreview(sp *sourcePreview, content editorview.Content return result }, } - sp.draw = func(dc *ui.DrawContext) { + sp.draw = a.sourcePreviewDraw(sp) +} + +// sourcePreviewDraw is the painter of the preview's view: without a minimap, a vertical bar or +// soft wrap, in the editor's font and look. +func (a *App) sourcePreviewDraw(sp *sourcePreview) func(*ui.DrawContext) { + return func(dc *ui.DrawContext) { v := sp.view if v == nil { return diff --git a/desktop/internal/workbench/theme.go b/desktop/internal/workbench/theme.go index e966ec52b8..ba790def06 100644 --- a/desktop/internal/workbench/theme.go +++ b/desktop/internal/workbench/theme.go @@ -102,12 +102,16 @@ func (a *App) applyLook(choice themeChoice) { // applySelectionFocus greys the selection of every list while another window has the // keyboard and restores it when this one comes back, the way IDEA dims an unfocused tree. +// Viva fills a selected tree row, and the row under the pointer in a menu or a sidebar, with +// the theme's Accent, so Accent takes the same color as Selection: the selected row shows in +// IDEA's selection blue instead of the faint grey Viva defaults to. func (a *App) applySelectionFocus() { + selection := a.colors.Selection if a.windowInactive { - a.theme.Selection = a.colors.SelectionIdle - return + selection = a.colors.SelectionIdle } - a.theme.Selection = a.colors.Selection + a.theme.Selection = selection + a.theme.Accent = selection } func lightLook() (gfx.Theme, palette) { @@ -153,6 +157,7 @@ func lightLook() (gfx.Theme, palette) { theme.Primary = accent theme.PrimaryForeground = gfx.RGB24(0xFFFFFF) theme.Selection = p.Selection + theme.Accent = p.Selection theme.Ring = accent theme.Success = p.Success theme.Metrics = theme.Metrics.WithDensity(gfx.DensityCompact) @@ -213,6 +218,7 @@ func darkLook() (gfx.Theme, palette) { theme.Primary = accent theme.PrimaryForeground = gfx.RGB24(0xFFFFFF) theme.Selection = p.Selection + theme.Accent = p.Selection theme.Ring = p.Accent theme.Success = p.Success theme.Metrics = theme.Metrics.WithDensity(gfx.DensityCompact) diff --git a/desktop/internal/workbench/theme_focus_test.go b/desktop/internal/workbench/theme_focus_test.go index b35bbde126..6378f79a66 100644 --- a/desktop/internal/workbench/theme_focus_test.go +++ b/desktop/internal/workbench/theme_focus_test.go @@ -9,14 +9,14 @@ import ( func TestSelectionGreysWhileAnotherWindowHasTheKeyboard(t *testing.T) { a := &App{} a.applyLook(themeLight) - if a.theme.Selection != a.colors.Selection { - t.Fatalf("active selection = %+v, want %+v", a.theme.Selection, a.colors.Selection) + if a.theme.Selection != a.colors.Selection || a.theme.Accent != a.colors.Selection { + t.Fatalf("active selection = %+v, accent %+v, want both %+v", a.theme.Selection, a.theme.Accent, a.colors.Selection) } a.windowInactive = true a.applySelectionFocus() - if a.theme.Selection != a.colors.SelectionIdle { - t.Fatalf("inactive selection = %+v, want the idle %+v", a.theme.Selection, a.colors.SelectionIdle) + if a.theme.Selection != a.colors.SelectionIdle || a.theme.Accent != a.colors.SelectionIdle { + t.Fatalf("inactive selection = %+v, accent %+v, want both the idle %+v", a.theme.Selection, a.theme.Accent, a.colors.SelectionIdle) } // A look change while the window stays inactive keeps the idle color. @@ -43,4 +43,8 @@ func TestIdleSelectionDiffersFromTheFocusedOne(t *testing.T) { if light.Selection != lightPalette.Selection || dark.Selection != darkPalette.Selection { t.Fatal("a look starts with the focused selection color") } + // Viva fills a selected tree row with the Accent, so it is the selection blue too. + if light.Accent != lightPalette.Selection || dark.Accent != darkPalette.Selection { + t.Fatal("a look fills a selected tree row with its selection color") + } } 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 index 7b2236005e..5de773e6f5 100644 Binary files a/docs/assets/problems-tree/after/problems-file-dark-zh-Hans.png 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 index d6ce20b079..1b25aafd61 100644 Binary files a/docs/assets/problems-tree/after/problems-file-light-en.png 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 index 890d4e4464..c67026e373 100644 Binary files a/docs/assets/problems-tree/after/problems-options-dark-zh-Hans.png 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 index 28cf0e7de8..c57f2cf84c 100644 Binary files a/docs/assets/problems-tree/after/problems-options-light-en.png 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 index 7c370ecda0..e2c09e79e1 100644 Binary files a/docs/assets/problems-tree/after/problems-project-dark-zh-Hans.png 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 index a2e9a8531a..378f9614bb 100644 Binary files a/docs/assets/problems-tree/after/problems-project-light-en.png and b/docs/assets/problems-tree/after/problems-project-light-en.png differ diff --git a/shared/platform-feature-matrix/features/diagnostics-workspace.json b/shared/platform-feature-matrix/features/diagnostics-workspace.json index d4cd06eed1..18f12fb3e7 100644 --- a/shared/platform-feature-matrix/features/diagnostics-workspace.json +++ b/shared/platform-feature-matrix/features/diagnostics-workspace.json @@ -11,6 +11,8 @@ "desktop/internal/workbench/problems.go", "desktop/internal/workbench/problems_view.go", "desktop/internal/workbench/problems_preview.go", + "desktop/internal/workbench/source_preview.go", + "desktop/internal/workbench/documents_tabless.go", "desktop/internal/workbench/shell_view.go", "desktop/internal/workbench/problems_test.go", "desktop/internal/workbench/problems_visual_test.go" @@ -24,13 +26,15 @@ "desktop/internal/workbench/problems.go", "desktop/internal/workbench/problems_view.go", "desktop/internal/workbench/problems_preview.go", + "desktop/internal/workbench/source_preview.go", + "desktop/internal/workbench/documents_tabless.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 比较绝对路径。在两端制造同名数字文件和多种严重程度的问题,确认顺序、计数、严重程度过滤、仅当前文件和搜索结果一致。 Viva:工具窗口标题栏显示“文件 N”和“项目 N”两个标签,默认打开文件标签;N 按显示选项统计当前编辑器文件和整个项目的问题,没有问题时只显示标签名,没有打开的文件时文件标签显示提示。左侧操作列依次为视图选项(显示错误、警告、信息与分组方式的菜单)、全部展开、全部收起和编辑器预览开关;树中文件节点显示文件图标、文件名、灰色目录和问题数,问题行显示严重程度图标、描述、来源和行号。折叠选中问题所在的文件节点后选中移到该节点,诊断消失后选中移到所在文件;树行、展开状态和选中移动全部由 Core 的 lsp.problems.query 计算。", + "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 计算。 Viva:预览按所选问题的严重程度给所在行着色(错误红、警告黄、信息与提示蓝),选中行使用主题选中蓝;预览是该文件文档的第二个编辑器,可直接输入、撤销、保存,标签页和预览的修改立即互相同步,未打开的文件以无标签文档打开、离开且无未保存修改时释放;预览中显示诊断波浪线,补全、悬停、跳转定义、查找用法、重命名和格式化按预览的光标工作;预览持有键盘焦点时诊断刷新只更新行颜色,不移动光标也不切换文件。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -62,5 +66,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:问题工具窗口按 IDEA 的 Problems 窗口改为树形:标题栏“文件 / 项目”标签带问题数,左侧操作列含视图选项菜单、全部展开、全部收起和编辑器预览开关;文件或严重程度节点可展开收起,开启预览时单击只选中并在右侧只读源码显示所在行,双击或 Enter 定位主编辑器。树的可见行、节点展开状态、选中保持和移动由 Core lsp.problems.query 的 rows / selected 返回,宿主只绘制。尚未实现快速修复灯泡和“更多”菜单;macOS 原生整机和 Windows 实机均未验收。" + "notes": "Viva:问题工具窗口按 IDEA 的 Problems 窗口改为树形:标题栏“文件 / 项目”标签带问题数,左侧操作列含视图选项菜单、全部展开、全部收起和编辑器预览开关;文件或严重程度节点可展开收起,开启预览时单击只选中并在右侧显示所在行,所在行按严重程度着色;预览可直接编辑,与文件标签页共用同一文档(撤销、保存、语言功能都走该文档),未打开的文件以无标签文档打开,双击或 Enter 定位主编辑器。树的可见行、节点展开状态、选中保持和移动由 Core lsp.problems.query 的 rows / selected 返回,宿主只绘制。尚未实现快速修复灯泡和“更多”菜单;macOS 原生整机和 Windows 实机均未验收。" }