MIMIC

Editors

mimic lsp is Mimic's language server. Any editor that speaks the Language Server Protocol gets, from the same mimic you build with:

  • Errors as you type, with the compiler's fixes as quick fixes ("make y mutable").
  • Hover: a function's signature, comment and effects (pure, concurrent, …); for a function from C, the header it came from; for a glyph or its word, what it does and how to type it.
  • Go to definition and find references, also into the standard library.
  • Glyph input: type \ and a letter, and completion offers the glyph (\i becomes ⍳, \k becomes ⌿); mimic glyphs lists them all.
  • Completion of names, modules (fs::), the primitives' words and keywords.
  • Formatting (mimic fmt), in the style the file mostly uses: words or glyphs.
  • The outline of a file, and a search for symbols across the project.
  • Names from C (c::sqrt, cpp::, an as name) as semantic tokens with the modifier foreign, so themes can colour them apart.
  • Signature help while typing a call's arguments: the signature, with the argument being typed marked.
  • Rename the program's own functions, types and variables everywhere they are used (the standard library's and C's names stay).
  • The call hierarchy: who calls a function, and what it calls.
  • Smart selection: grow the selection from a name to its brackets, the line, and on.
  • Inferred types after each let without an annotation (inlay hints: let total: i64 = …), and a code action that writes one in.
  • Extract into a function: select an expression; the variables it uses from around it become the new function's parameters.
  • Where code runs, as labels after the code (inlay hints): ∥ parallel, ⇶ fused, ≋ SIMD, ▣ GPU, ◷ task, → in order, with the reason on hover (mimic why lists them all).

Syntax highlighting comes from the grammars in mimic-syntax: TextMate for VS Code, tree-sitter for Neovim, Helix and Zed.

Debugging goes through mimic dap, the Debug Adapter Protocol: breakpoints on .mim lines, stepping, the call stack, and variables shown as Mimic prints them ([3 1 4], Point { x: 1.5, y: 2.0 }, ["a": 1], Some(7)). It runs LLVM's lldb-dap, which comes with Xcode on macOS and with the lldb package on Linux. A launch request takes program: a .mim file or a project folder, which it builds with debug information.

Mimic's own editor

mimic edit needs nothing installed: it is part of mimic, and knows everything the language server knows.

Everything is clickable. The toolbar at the top runs, tests, checks and audits, finds, opens the glyphs, the REPL and the manual; ≡ Commands (or F2) lists every command with its key, and typing filters the list. Folders in the file tree open and close with a click, and a file opens with one; tabs switch with a click and close with their ×; the bottom pane's tabs switch panes; a file.mim:12 in any pane (an error, a test failure, a finding) jumps there; the error count in the status bar opens the problems, and its hints are buttons too. The wheel scrolls the code, the tree or the pane, whichever is under it.

Key Does
F2 Every command, with its key: type part of its name, or click it
Ctrl-O Open a file of the project (type part of its name)
Ctrl-N, Ctrl-W A new program; close the file
Ctrl-S, Ctrl-Q Save; quit (it asks when something is unsaved)
Ctrl-G The glyph palette (type a word or what it does); or type \i, \e, \k …
Ctrl-F, F3, Ctrl-H Find, find again, replace
Ctrl-Z, Ctrl-Y Undo, redo
Ctrl-C, Ctrl-X, Ctrl-V, Ctrl-A Copy, cut, paste, select all (Shift and the arrows select too)
Ctrl-L Go to a line
F4, Ctrl-E The REPL: evaluate a line you type (F4), or the current line or selection (Ctrl-E); lets and fns stay for the next lines, as in mimic repl
F5, F6 Run, test (in the background; the output appears in its pane)
F7, F8, F9 Problems, audit, where code runs
F1 The manual for the word or glyph under the cursor
Ctrl-B, Ctrl-J Show or hide the files, the bottom pane
Alt-← Alt-→ The other open files

Errors appear as you type: a red mark beside the line, the code underlined, the message after it. Where code runs shows after each line as a label (∥ parallel, ◷ task, → in order).

The REPL

mimic repl is the quickest way to try an expression: type ⍳ 10 ▷ +/ (or \i 10 ▷ +/) and see 45. lets and fns you type stay for the lines after, and :show prints them as a program. On macOS, the system checks every new program the first time it runs, which adds about a second to each line; add your terminal app under System Settings → Privacy & Security → Developer Tools to skip the check (it also speeds up mimic run and mimic test).

VS Code

The Mimic extension (mimic-vscode) starts mimic lsp by itself and adds:

  • the highlighting, and the Mimic file icon;
  • the glyph palette (Cmd+Alt+G on macOS, Ctrl+Alt+G elsewhere): every glyph with its word, how to type it and what it does;
  • ▶ Run and Debug above fn main, ▶ Run test above each test, and the Test Explorer (also for examples in comments); F5 debugs the current project or file;
  • the manual beside your code (Mimic: Open the Manual…, or Cmd/Ctrl+Alt+M for the word under the cursor);
  • Convert File to Glyphs / Words;
  • setup that just works: it finds mimic as your terminal does, or where the installer puts it; the status bar shows the version and what it can do; Mimic: Install or Update Mimic installs the release for your machine (checked against its SHA256SUMS); with a Mimic too old for the language server, errors show on save;
  • Profile above fn main: a panel with each function's share of the time, where it runs, how busy each core was, GPU time and memory, and each function's share at the end of its first line; the Mimic side bar lists the hot functions and every decision about where the open file's code runs (mimic why);
  • the REPL: Mimic: Open REPL, and Shift+Enter to send the selection or line; notebooks (.mimnb, Mimic: New Notebook), whose code cells share one session;
  • glyphs as you type (\i becomes ⍳ at once), the Glyphs and Project views, help with mim.mim, tasks with a build target, mimic audit findings on save, previews of the docs and of UI programs, a property test's failing case kept as a test in one click, coverage in the Test Explorer, the Audit view, formatting on save in words or glyphs, lists and matrices from the debugger as tables and charts, and mimic mcp offered to agents (VS Code 1.101 and newer);
  • Show net above functions that compile to interaction nets: their nets drawn as graphs (click a reference to open its definition), and Trace, which reduces a call round by round, plays the rounds and charts how many redexes each had; .mnet files get errors on save, formatting and hovers for each kind of node.

Until it is in the VS Code Marketplace and Open VSX, install the .vsix from the extension's releases: Extensions view → … → Install from VSIX….

Neovim (0.11 or newer)

vim.filetype.add({ extension = { mim = "mimic" } })
vim.lsp.config("mimic", {
  cmd = { "mimic", "lsp" },
  filetypes = { "mimic" },
  root_markers = { "mim.mim" },
})
vim.lsp.enable("mimic")

For highlighting, add the tree-sitter grammar as the mimic-syntax README shows.

Helix

In ~/.config/helix/languages.toml (with debugger for :debug-start):

[language-server.mimic]
command = "mimic"
args = ["lsp"]

[[language]]
name = "mimic"
scope = "source.mimic"
file-types = ["mim"]
roots = ["mim.mim"]
comment-token = "//"
indent = { tab-width = 4, unit = "    " }
language-servers = ["mimic"]

[language.debugger]
name = "mimic"
transport = "stdio"
command = "mimic"
args = ["dap"]

[[language.debugger.templates]]
name = "project"
request = "launch"
completion = [ { name = "project folder", completion = "directory", default = "." } ]
args = { program = "{0}" }

Emacs (eglot)

(define-derived-mode mimic-mode prog-mode "Mimic")
(add-to-list 'auto-mode-alist '("\\.mim\\'" . mimic-mode))
(with-eval-after-load 'eglot
  (add-to-list 'eglot-server-programs '(mimic-mode "mimic" "lsp")))

Then M-x eglot in a .mim file. For debugging, dape can use mimic dap as its adapter.

Sublime Text (with the LSP package)

In the LSP package's settings:

{
  "clients": {
    "mimic": {
      "enabled": true,
      "command": ["mimic", "lsp"],
      "selector": "source.mimic"
    }
  }
}

Zed

Zed adds languages through extensions; until a Mimic extension for Zed is published, use the tree-sitter grammar and mimic lsp in a dev extension (Zed's documentation explains how).

Without a language server

mimic check --emit-json and mimic query (mimic man workbench) answer the same questions as JSON, for scripts and tools of your own.

From docs/manual/editors.md in the Mimic repository.