Initial change to integrate Harper.js#3
Conversation
- Refactor src/lint.ts: clean Harper linter wrapper using LocalLinter - Create src/extension.ts: CodeMirror extension with decorations, tooltips, and update listener - Update main.ts: MarkEdit API integration using addExtension Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
…nt for messages Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
| }); | ||
|
|
||
| // Base theme for lint decorations and tooltips | ||
| const baseTheme = EditorView.baseTheme({ |
There was a problem hiding this comment.
@copilot this file is currently not well organized because on purpose, try moving styling, decoration, and tooltip to dedicated files.
There was a problem hiding this comment.
Split into dedicated files in cea8716: src/styling.ts (base theme), src/decoration.ts (diagnostics state field, types, lint-to-diagnostic conversion), src/tooltip.ts (hover tooltip rendering). extension.ts now only contains the lint scheduler and the composition.
Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
|
@copilot Just curious. CodeMirror is viewport based to handle long documents. It means that the content you see on the screen isn't necessarily the full content. Two questions:
I don't want to look into the details, you tell me how good the performance and correctness is in the current implementation. |
Good questions. Here's the analysis: 1. Correctness with viewport-based rendering: The implementation is robust. 2. Viewport-based linting for performance: Full-document linting is the better choice here for a few reasons:
For very large documents (100k+ words), full-document linting could become noticeable, but for typical editing workloads this approach is both simpler and more correct. If perf becomes an issue in practice, the right optimization would likely be incremental/dirty-range tracking rather than viewport slicing. |
|
This is a good start. |
Integrates Harper.js into MarkEdit as a real-time grammar checker using native CodeMirror primitives.
Changes
main.ts— Replaced test stub withMarkEdit.addExtension(proofreadingExtension())per MarkEdit conventionssrc/lint.ts— Cleaned up to export only theLocalLinterwrapper withbinaryInlinedsrc/extension.ts— New file containing the CodeMirror extension:StateField+StateEffectmanaging diagnostics and a mappedDecorationSetViewPluginthat debouncesdocChanged(500ms), runs Harper async, discards stale resultshoverTooltiprendering diagnostic title, message, and suggestion action buttonsSuggestionKindvariants handled (Replace, Remove, InsertAfter)Architecture
All text rendering uses
textContentto avoid XSS vectors from linter output.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.