---
title: "Enabling low-latency, syntax-aware editing using Tree-sitter"
description: "Zed builds its syntax-aware features on Tree-sitter, a GLR-based incremental parsing framework with error recovery that produces concrete syntax trees."
url: "https://swe.quest/articles/enabling-low-latency-syntax-aware-editing-using-tree-sitter-9ffe8225d976568b"
canonical: "https://zed.dev/blog/syntax-aware-editing"
source: "Zed"
published: "2023-03-27"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 10
tags: ["developer-tools","compilers","data-structures","rust"]
---

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

A post on [Zed](https://swe.quest/sources/zed.md), published 2023-03-27, 10 min read, Deep dive. Original: [https://zed.dev/blog/syntax-aware-editing](https://zed.dev/blog/syntax-aware-editing)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Developer tools](https://swe.quest/tags/developer-tools.md) (Engineering practices)
- [Compilers](https://swe.quest/tags/compilers.md) (Compilers & runtimes)
- [Data structures](https://swe.quest/tags/data-structures.md) (Architecture & design)
- [Rust](https://swe.quest/tags/rust.md) (Languages)

## Prerequisites

- syntax trees and parsing basics
- context-free grammars

## Keywords

Tree-sitter, Zed, GLR parsing, Language Server Protocol, sum tree, concrete syntax tree

## Related posts

- [Zed Has Rainbow Brackets](https://swe.quest/articles/zed-has-rainbow-brackets-56d1fa479c442850.md): Zed · 2025-12-03 · Medium · 6 min read · Developer tools, Rust, Caching, Performance engineering, Testing
  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.
- [Extensible Language Support in Zed - Part 1](https://swe.quest/articles/extensible-language-support-in-zed-part-1-13bc037c6f5096a9.md): Zed · 2024-04-18 · Medium · 7 min read · WebAssembly, Developer tools, Sandboxing & isolation, Compilers, Rust
  Zed loads third-party Tree-sitter grammars as WebAssembly modules using a hybrid design.
- [Syntax-Aware Task Spawning With Tree-Sitter](https://swe.quest/articles/syntax-aware-task-spawning-with-tree-sitter-c8a0858f66d9d4d1.md): Zed · 2024-05-21 · Medium · 8 min read · Developer tools, Developer productivity
  Zed Tasks run shell commands from the editor using variables such as $ZED\_SYMBOL (filled from Tree-sitter with the enclosing symbol), $ZED\_FILE and $ZED\_SELECTED\_TEXT.
- [Rope & SumTree](https://swe.quest/articles/rope-sumtree-f2c50a52279e3db4.md): Zed · 2024-04-23 · Medium · 22 min read · Data structures, Rust, Developer tools, Concurrency
  Zed represents buffer text with a rope rather than a string, because contiguous strings make mid-file inserts and deletes, line navigation and very large files expensive.
- [Zed Weekly: #18](https://swe.quest/articles/zed-weekly-18-7d443e4b9455171f.md): Zed · 2023-09-05 · Easy · 4 min read · Developer tools, AI for coding, RAG & retrieval
  Zed's semantic index now batches embedding requests by token count rather than span count, cutting OpenAI requests and improving throughput and consistency.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
