Repository navigation
Conversation
`set_diagnostics(list[Diagnostic])` and `clear_diagnostics()` render inline error/warning marks with hover tooltips on user-supplied lines, backed by CodeMirror's built-in lint system. Each `Diagnostic` is a small TypedDict with required `line` (1-indexed) and `message`, plus optional `severity` (`'error'` | `'warning'` | `'info'` | `'hint'`, default `'error'`) and `source` (label shown next to the message). The editor installs `CM.linter(() => [])` so that `setDiagnostics()` works and inline error marks render. **Important:** we deliberately do NOT use `CM.lintGutter()` — it pulls in `lintGutterTooltip`, a StateField that registers itself via `showTooltip.from(field)` and returns null on most transactions. That null provider sits in the `showTooltip` facet and silently suppresses the autocomplete popup outside of paren contexts. `CM.linter()`'s only tooltip is a `hoverTooltip` that fires on mouseover, not on every keystroke. Adds `@codemirror/lint` to the dist bundle (already a transitive dependency of `codemirror`, just needs to be re-exported from `src/index.mjs` so it ends up in `dist/`). Bundle rebuilt. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
- Diagnostic TypedDict: make `line`/`message` required and use `NotRequired` for `severity`/`source`, matching the docstring. - `set_diagnostics` docstring: drop the inaccurate gutter-underline claim; we deliberately don't install `lintGutter()`. - JS: drop the dead empty-string fallback for `message` (now required), and `console.warn` + skip non-integer or out-of-range line numbers instead of silently clamping them onto the wrong line. - Test: drop the slack `screen.wait(0.3)`; assert that severity-suffixed classes (`.cm-lintRange-error`, `.cm-lintRange-info`) appear; add a case exercising the default-`error` severity branch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ount read-back - Add optional column/end_column to Diagnostic for sub-line marks - Add open_lint_panel/close_lint_panel/toggle_lint_panel - Add async get_diagnostic_count returning a per-severity dict - Use ?? instead of || when forwarding source so empty strings pass through - Drop :class: cross-ref and add *Added in version X.Y.0* placeholders
Adds DiagnosticCount TypedDict and exposes both Diagnostic and DiagnosticCount from nicegui.elements.codemirror so users can import them without reaching into the inner module.
Inject a renderMessage callback per diagnostic in setDiagnostics that runs the message through NiceGUI's global setHTML polyfill (DOMPurify- backed). Plain text keeps working as-is; sanitized HTML (`<code>`, `<b>`, etc.) renders inline in the lint panel and hover tooltips.
6 tasks done
Jepson2k
marked this pull request as ready for review
May 2, 2026 23:32
falkoschindler
self-requested a review
May 5, 2026 12:58
…gs to logAndEmit Replace set_diagnostics()/clear_diagnostics() with a mutable diagnostics property keyed on the codemirror element. Constructor gains diagnostics and diagnostic_message_html parameters; message content renders as plain text by default. JS routes out-of-range line warnings through logAndEmit so the Python logger picks them up.
6 tasks done
Resolve conflicts from zauberzeug#6000 (CodeMirror custom keybindings), which refactored the same files. Diagnostics and keybindings are orthogonal, so each conflict keeps both: - codemirror.py: keep `Literal`/`TypedDict` imports (still used by the Diagnostic severity literal and the TypedDicts); import SUPPORTED_LANGUAGES/THEMES from .constants and KeyBindingElement from .keybindings (dropping the inline Literals); add CodeMirrorKeyBindingEventArguments to the events import; class now extends KeyBindingElement; keep the Diagnostic/DiagnosticCount TypedDicts and both constructor params/docstrings. - codemirror.js: keep both the diagnostics props/methods (applyDiagnostics, lint-panel helpers, getDiagnosticCount) and the keymap props/methods. - codemirror_documentation.py: keep both the Linting Diagnostics and Custom Keybindings demos. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drop the defensive list() copy when storing diagnostics in the constructor and setter: the declared list[Diagnostic] type already guarantees the shape, and this matches how the sibling line_tooltips stores its value verbatim. Also reflow the Diagnostic and diagnostics docstrings to one sentence per line per CONTRIBUTING.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6 tasks done
Contributor
falkoschindler
marked this pull request as draft
August 19, 2026 12:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Embedding
ui.codemirroras an in-app editor often needs to surface programmatically computed diagnostics — type-check results, lint output, runtime errors mapped back to source — onto specific lines or column ranges, with hover tooltips so the user can read the message without leaving the editor. CodeMirror 6's@codemirror/lintpackage provides this, but it isn't bundled in the current dist and there's no Python API for it.Implementation
DiagnosticTypedDictwith requiredline(1-indexed) andmessage, plus optionalseverity('error'|'warning'|'info'|'hint', default'error'),source(label shown next to the message), andcolumn/end_column(1-indexed, exclusive end) for sub-line ranges.diagnosticsis a mutable list ofDiagnosticdicts; mutating it (or reassigning) syncs to the client.open_lint_panel()/close_lint_panel()/toggle_lint_panel()show or hide CodeMirror's built-in panel listing the current diagnostics.get_diagnostic_count()(async) returns a per-severity dict for status-bar UIs.@codemirror/lintwas already a transitive dep, sopackage.jsondoesn't change — just re-exports fromsrc/index.mjsand a bundle rebuild.Diagnostic messages render as plain text by default; pass
diagnostic_message_html=Trueto the constructor to render messages as sanitized HTML via NiceGUI'ssetHTMLpolyfill. Out-of-range diagnostic lines are routed to the Python logger vialogAndEmit('warning', ...).Progress