Skip to content

Instantly share code, notes, and snippets.

View marijnh's full-sized avatar

Marijn Haverbeke marijnh

View GitHub Profile
Never see JavaDoc again
Inline documentation is great. JSDoc/JavaDoc syntax is an acquired taste that I never managed to acquire. So I want to show you an alternative tool with alternative syntax that I wrote.

(This is a response to https://github.com/google/xi-editor/blob/master/doc/rope_science/rope_science_11.md that didn't fit in a tweet.)

CodeMirror uses a largely similar approach, with a somewhat different framing.

Firstly, it stores the mode (highlighter) state directly in the document data structure (which I probably wouldn't do again if I were to redesign this), not in a separate cache. Each line can have an optional 'highlight state after this line' field. During highlighting, a cached state is left every N lines.

The frontier is simply the line number up to which point highlighting has happened. When you edit above the frontier, it it moved back to the line before the change.

Highlighting never proceeds past the end of the viewport. So startup is cheap (only highlight the first screenful), and in the 99% case of changes happening inside the viewport, re-highlighting complexity is bounded by the size of the viewport, since only the area between the change and the end of the viewport needs to be proces

/*
# Clean UI programming in a vacuum
This app was written for Chapter 19 in the 3rd edition of Eloquent
JavaScript—it aims to demonstrate modern UI programming without
depending on a specific framework or library.
Its convention is that components have an interface like this:
```
@marijnh
marijnh / theme-ttcn.js
Last active March 22, 2023 10:19
TTCN theme for CM6
import {HighlightStyle, syntaxHighlighting} from "@codemirror/language"
import {tags as t} from "@lezer/highlight"
export const ttcnHighlightStyle = HighlightStyle.define([
{tag: t.quote,
color: "#090"},
{tag: t.deleted,
color: "#d44"},
{tag: t.inserted,
color: "#292"},