Skip to content

Initial syntax support - #73

Merged
maxbrunsfeld merged 56 commits into
mainfrom
grammars-cursor
May 28, 2021
Merged

Initial syntax support#73
maxbrunsfeld merged 56 commits into
mainfrom
grammars-cursor

Conversation

@as-cii

@as-cii as-cii commented May 28, 2021

Copy link
Copy Markdown
Member

Refs #64

This pull request introduces tree-sitter to the Buffer and includes a Rust grammar that is used to produce a syntax tree for files ending in .rs. To achieve this, we maintain a syntax tree which we re-parse and interpolate as new edits flow into the buffer.

The syntax tree is currently used for a couple of features:

  • Syntax highlighting. When writing a language, Zed will read a highlights.scm file that describes how certain parts of the syntax tree (expressed as queries over it) map to style names. These style names can then be used in a theme (see the light.toml included in this diff) to describe how to style the text (at the moment we support styling the text via color, weight and italic).
  • Commands for expanding (alt-up) and shrinking (alt-down) the active selections based on the syntax tree.
  • A command for jumping to the enclosing bracket, bound to ctrl-m.

/cc: @nathansobo @maxbrunsfeld

maxbrunsfeld and others added 30 commits May 22, 2021 12:34
* Include it, along with settings in `OpenParams` grouped under a new struct called `AppState`

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This is consistent with how we name the other chunk iterators.
Note that this API doesn't take a DisplayPoint: it could but it
makes things a bit harder on the implementation side and we don't
really need it anyway, as text is laid out on a line-by-line basis
anyway.
* Introduce a Theme struct as a new part of the app's settings
* Store on each Language a ThemeMap, which converts the capture ids
  from that language's highlight query into StyleIds, which identify
  styles in the current Theme.
* Update `highlighted_chunks` methods to provide StyleIds instead of
  capture ids.
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
@as-cii as-cii mentioned this pull request May 28, 2021
as-cii and others added 5 commits May 28, 2021 19:35
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Max Brunsfeld <max@zed.dev>
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Pass ranges to `set_byte_range`, `set_point_range`

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
@maxbrunsfeld
maxbrunsfeld merged commit 9369249 into main May 28, 2021
@maxbrunsfeld
maxbrunsfeld deleted the grammars-cursor branch May 28, 2021 21:40
Anthony-Eid added a commit to Anthony-Eid/zed that referenced this pull request Dec 11, 2024
…s#73)

* Move process to transport struct itself

* Add test to make sure we can send request and receive a response

* Align other handle methods

* Fix issues inside cargo.toml require test features inside the correct *-dependencies

* Remove comments that are not needed

* Add as_fake instead of downcasting

* Clean up

* Override get_binary method so we don't fail on install

* Fix false positive clippy error

This error was a match variant not being covered when the variant wasn't possible dued
to a feature flag. I'm pretty sure this is a bug in clippy/rust-analyzer and will
open an issue on their repos

* Remove not needed clone

* Panic when we receive an event/reverse request inside the test

* reuse the type of the closure

* Add a way to fake receiving events

* Oops remove fake event from different test

* Clipppyyyy

---------

Co-authored-by: Anthony Eid <hello@anthonyeid.me>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
ShalashaskaOcelot pushed a commit to ShalashaskaOcelot/zed that referenced this pull request Aug 11, 2026
Phase 69 collects three places where a notebook is a file-backed item and
NotebookEditor doesn't behave like Editor does: a loose notebook (one outside
every project root) is silently dropped on restore because its invisible
single-file worktree isn't recreated and deserialize errors instead of falling
back; the deleted-on-disk strikethrough never applied to notebooks, since the
indicator is per-item rather than tab machinery and the notebook reads none of
the disk state its backing buffer already carries; and unsaved changes to a
SAVED notebook are lost on quit, because contents are serialized only for
untitled ones.

The user's decision, recorded in the phase: generic session-restore semantics
stay as upstream wrote them, even though they'd prefer otherwise. That keeps
fork changes inside notebook code, and it means a file deleted BETWEEN sessions
still returns as a blank tab with no marker — the notebook will match .md's
rough edge rather than fix it. Written down so the limit is deliberate.

The hot-exit item carries the one real risk and the reason it isn't just a flag
flip: the notebook encodes its JSON on the main thread, so extending it from
untitled notebooks to every dirty one puts megabytes of base64 output through
the main thread up to five times a second while typing. The phase requires
moving the encode to a background thread, along with storing mtime and
narrowing should_serialize to the editor's event set.

Bug zed-industries#73 is the "Failed to trash 1 of 1 file" toast on a delete that actually
worked. Fs::trash demands undo metadata from the trash backend, and on Windows a
failed metadata lookup is warned-and-skipped, leaving an empty list that turns
into an error after the file has already reached the Recycle Bin. Analysis only
— inferred from the crate source, not reproduced, since this container has no
desktop trash. No fix attempted.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JkvYRuX9r6PmLXpxNie2R7
ShalashaskaOcelot pushed a commit to ShalashaskaOcelot/zed that referenced this pull request Aug 13, 2026
Test results from 2026-08-11. Bugs zed-industries#7, zed-industries#66, zed-industries#67, zed-industries#68, zed-industries#70 and zed-industries#72 confirmed
fixed and removed; zed-industries#64 failed and stays open with the finding recorded; zed-industries#73's
repro is confirmed on Windows. Three fixes here.

zed-industries#69 (column titles wrapping their last character) was NOT fixed by the previous
attempt, and that attempt was aimed at the wrong layer. Measuring headers
semibold was a real discrepancy and stays, but the cause is that the table
renders at a different font SIZE from the one it measures with: ui's
font_buffer sets only the font family, so the size stayed ambient while
TableView::new measured against buffer_font_size. Every glyph then rendered a
fraction wider than measured, and the error accumulates with string length —
invisible on a 15-character title, just past the padding slack on a
16-character one, which is exactly the reported Column_number_9-fits,
Column_number_10-wraps threshold. The rendered size is now pinned to the
measured one.

zed-industries#74: a notebook whose file was deleted while Zed was closed didn't restore at
all, taking any unsaved changes with it. Nothing to do with deletion handling —
open_buffer deliberately returns an empty buffer for a path with no entry, so
the notebook parses, but try_open then demanded a worktree entry id and a
deleted file has none. That id was already optional on NotebookItem (it is only
a fallback for entry_id, which re-resolves from the path), so nothing needed it
to be present.

zed-industries#75: a restored untitled notebook showed no dirty marker until the next
keystroke. Same trap phase 69 fixed for file-backed notebooks and missed here:
rebuilding a notebook from stored JSON makes those cells their own baseline, so
it reads as clean. Contents are only stored when there ARE unsaved changes, so a
restored untitled notebook is unsaved by definition and now says so.

Also filed zed-industries#76: restoring unsaved changes over a file edited elsewhere gives no
notification. The conflict flag may well be set correctly and simply invisible
until save time, which is the first thing to check — the two possible causes
need different fixes, so nothing is attempted yet.

Backlogged from zed-industries#72's confirmation: a restart should read Restarting → Idle,
not Restarting → Starting → Idle.

Verified: clippy clean, 57 repl tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JkvYRuX9r6PmLXpxNie2R7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants