A code editor widget for Gio, in Go.

Syntax highlighting, completions from any language server and split or unified diffs for Go desktop apps, drawn by Gio in your own process, so the app ships one UI stack.

[ fig. 1 ] the library, compiled to WebAssemblylive
views
theme
script
loading the WebAssembly build…
GOOS=js GOARCH=wasmLezer grammar for GoGo Mono, built incompletion: go/types after a dot, the file's words elsewhere; no language server in a browser, see fig. 2

[ fig. 2 ] package lsp, with gopls

Attach a language server to the Editor.

lsp.Attach sends every edit to the server and fills the Editor's hooks from its answers. lsp/servers knows 428 servers and how to install 252 of them. Tested with gopls.

  1. 01 typingcompletion after a dot or two letters, documentation beside the menu, signature help, hover, Ctrl+click to a definition
  2. 02 diagnosticswavy underline, a dot in the gutter, F8 to the next
  3. 03 code actionsCtrl+. or the bulb in the gutter
  4. 04 renameF2, in place, across files
Typing in the Editor with gopls attached: completion, signature help, a hover, then Ctrl+click to a definition A diagnostic popup over an undefined name Code actions listed under the cursor, the bulb in the gutter F2 opens an input over a name

[ table 1 ] showing code in a Go desktop app

Three ways to put code on screen.

webview + CodeMirror or Monacoplain text widgetgodemirror
UI stacksGio and a browser engine, bridgedoneone: Gio
highlightingyesnoLezer grammars in Go, off the UI goroutine
language serverthrough the bridgenopackage lsp, in process
diff viewCodeMirror mergenoDiffView, with revert
themeCSS, apart from the appthe app'sthe app's, plus ported CodeMirror themes

[ table 2 ] measured in the repository

428language servers in lsp/servers
252with an install recipe
13,000lines show at once, colored when ready
140 msa program scroll glides, eased out

[ listing 1 ] cmd/examples/lsp, abridged

Quick start.

// go get github.com/lichdotdev/godemirror
editor, err := godemirror.NewEditor("monospace", unit.Sp(13))
err = editor.SetState(godemirror.EditorStateConfig{Filename: path, Doc: text})

srv := servers.Lookup(path)[0]
client, err := lsp.Start(ctx, lsp.Config{Command: srv.Command, RootDir: root})
doc, err := lsp.Attach(client, editor, lsp.FileURI(path), lsp.Options{
	LanguageID: servers.LanguageID(servers.FileType(path)),
	Invalidate: window.Invalidate,
})
editor.Layout(gtx) // in the frame loop

The library is pure Go; the app around it is an ordinary Gio app. Tested on Linux; macOS and Windows build but CI does not run them yet. Limits: docs/ceilings.md.