Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Shopify Engineering 7 min read Case study mediumAdept

Building a ShopifyQL Code Editor

Shopify integrated ShopifyQL into the CodeMirror editor by writing an adapter that feeds its existing ANTLR-based, LSP-conforming TypeScript language server into CodeMirror's Lezer parse trees, avoiding a Lezer grammar rewrite. The hard part was converting LSP semantic tokens, whose line and character offsets are relative to the previous token and can go negative when comments are parsed on a separate ANTLR channel, into CodeMirror's absolute document offsets. A custom TokenIterator tracks line lengths and the current position to compute absolute start and end offsets for a Lezer buffer. The language server's validate, complete and hover functions were then wired to CodeMirror's linting, autocomplete and hover-tooltip plugins.

Assumes: Language Server Protocol basicsparsers and tokenizationTypeScript

Related posts

  • Improving the Developer Experience with the Ruby LSP

    Shopify Engineering mediumAdept

    Ruby LSP is a pure-Ruby language server from Shopify that provides editor features for Ruby without type checking or type annotations, aiming for performance and stability on large codebases like Shopify's Core monolith and leaning toward Rails-specific features. The post explains how the Language Server Protocol decouples editors from language tooling via JSON over STDIN/STDOUT, and how document synchronization keeps the server's view of open files current. It then walks through implementing a nonpositional Folding Range request by parsing files with the Syntax Tree gem (built on Ripper) and collecting class and method ranges with a visitor. The supported features are listed, and the post notes that YJIT gives a performance boost and that the YARP parser will add portability and error tolerance.

  • Ghostwriter AI & Complete Code Beta

    Replit mediumAdept

    Replit's Ghostwriter adds AI code completion, generation, transformation, explanation and semantic search to its IDE, with Complete Code starting in closed beta. Completion is built on Salesforce's CodeGen, converted to FasterTransformer and served on Triton, with a 2B model distilled to about 1B parameters and int8 quantization under exploration, for a median latency under 400ms. On the editor side, suggestions are matched against existing whitespace, braces and AST structure, adjusted as the user keeps typing, filtered by heuristics and streamed line by line. Other features use a 'society of models': a fine-tuned CodeBERT embedding model for contextual natural-language code search, and large OpenAI and 100B+ parameter models for explaining, generating and transforming code.

  • Enabling low-latency, syntax-aware editing using Tree-sitter

    Zed mediumAdept

    Zed builds its syntax-aware features on Tree-sitter, a GLR-based incremental parsing framework with error recovery that produces concrete syntax trees. Syntax-aware selection uses the CST directly. Highlighting, symbol outlines, auto-indentation and language injections are each driven by declarative Tree-sitter queries, which compile to state machines matched in a single depth-first walk, so adding a language needs only a grammar and query files. Injected trees, such as JavaScript inside HTML or Rust macro arguments, are kept in a copy-on-write B-tree called a sum tree, which lets edits be re-parsed incrementally on a background thread while the main thread keeps reading the previous snapshot.

  • Postgres Language Server: Initial Release

    Supabase mediumAdept

    Postgres Language Server is an LSP implementation for Postgres offering autocompletion, syntax error highlighting, type-checking via PREPARE/EXPLAIN against a live database, and a Squawk-inspired linter, available for VSCode, Neovim and as a CLI. Its architecture treats each SQL statement as an independent compilation unit with the database schema as the source of truth. A custom Pratt-parser statement splitter falls back to semicolons and double newlines. libpg_query handles precise parsing of valid SQL, while tree-sitter covers incomplete input for autocompletion. On edits, only changed statements are invalidated and later statements just have their ranges shifted, so cached ASTs survive. Completions are scored from a lazily loaded in-memory schema cache, so no database query is needed per keystroke.

  • Zed Has Rainbow Brackets

    Zed mediumAdept

    Zed implements rainbow brackets without language servers or a persistent syntax tree by running each language's tree-sitter brackets.scm queries over independent 50-row chunks and coloring pairs by nesting depth across 7 cycling theme accent colors. Chunks may occasionally be off by one color at boundaries, a tradeoff accepted to avoid maintaining global bracket state. Results are cached on the buffer rather than the ephemeral editor, versioned with clock::Global, invalidated eagerly on edits and re-queried lazily only for visible ranges. Upstream tree-sitter changes that limit query search ranges keep performance acceptable, and a visual test notation annotates each bracket with its color index.

The quest for software engineering knowledge.

Look:
Layout: