From 8b7d0d62f53fe0146a654f802299b1876f6d1597 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Sat, 28 Mar 2026 17:37:17 +0100 Subject: [PATCH 01/15] made a few changes --- README.md | 26 +++++-- languages/typst/highlights.scm | 125 +++++++++++++++++++-------------- languages/typst/outline.scm | 18 +++-- languages/typst/tasks.json | 13 +++- 4 files changed, 109 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 7132a0e..f5242de 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,40 @@ # Typst Extension for Zed ## Usage -To register the LSP and enable certain features such as compile on save, add the -following your `settings.json` (or `.zed/settings.json` in the project root for -project-specific config), -```json +To register the LSP and enable certain features (such as compile on save), add the following your `settings.json` (or `.zed/settings.json` in the project root for project-specific config), + +```jsonc +// In settings.json "lsp": { "tinymist": { + "initialization_options": { + // Enable background preview + "preview": { + "background": { + "enabled": true, + }, + }, + }, + "settings": { + // Compile on save + // This will compile a PDF for the `main.typ` file in the project root. "exportPdf": "onSave", "outputPath": "$root/$name" + + // Enable formatter + "formatterMode": "typstyle", } } } ``` -This will compile a PDF for the `main.typ` file in the project root. -To see all available options refer to [the tinymist documentation](https://github.com/Myriad-Dreamin/tinymist/blob/main/editors/neovim/Configuration.md). +To see all available options refer to [the tinymist documentation](https://github.com/Myriad-Dreamin/tinymist/blob/main/editors/neovim/Configuration.md). Beware that the configuration options displayed there apply to **NeoVim**, not Zed, so some might be incorrect or misleading ## Components + - Tree Sitter: [tree-sitter-typst](https://github.com/uben0/tree-sitter-typst/) - Language Server: [tinymist](https://github.com/Myriad-Dreamin/tinymist/) diff --git a/languages/typst/highlights.scm b/languages/typst/highlights.scm index 0535d9c..76eb1de 100644 --- a/languages/typst/highlights.scm +++ b/languages/typst/highlights.scm @@ -1,9 +1,8 @@ ; Taken from https://github.com/uben0/tree-sitter-typst/blob/f457c77edffd4b93190794355ff5acf7acfb99c6/editors/helix/queries/highlights.scm#L4 ; Improved by @Gaspartcho -; CONTROL -(let - "let" @keyword.storage.type) + +; CONTROL (branch [ "if" @@ -19,9 +18,22 @@ "in" ] @keyword.control.repeat) +(flow + [ + "break" + "continue" + ] @keyword.control) + +(return + "return" @keyword.control) + + +; DIRECTIVES (import "import" @keyword.control.import) +(wildcard) @operator + (as "as" @keyword.operator) @@ -34,14 +46,9 @@ (set "set" @keyword.control) -(return - "return" @keyword.control) +(let + "let" @keyword.storage.type) -(flow - [ - "break" - "continue" - ] @keyword.control) ; OPERATOR (in @@ -90,77 +97,82 @@ ">" ] @operator) -(fraction - "/" @operator) +(tagged + field: (ident) @variable.parameter) -(fac - "!" @operator) +(field + field: (_) @property +) -(attach - [ - "^" - "_" - ] @operator) - -(wildcard) @operator ; VALUE (ident) @variable +(call + item: (ident) @function) + +(call + item: (field + field: (ident) @function.method)) + +; RAW (raw_blck - "```" @punctuation.delimiter + "```" @embedded (blob) @text.literal) (raw_blck - lang: (ident) @tag) + lang: (ident) @embedded) (raw_span "`" @punctuation.delimiter (blob) @text.literal) -(label) @tag -(ref) @tag +; MATH +[ + (label) + (ref) +] @label (number) @number (string) @string -(content - [ - "[" - "]" - ] @operator) - (bool) @boolean (none) @constant.builtin (auto) @constant.builtin -; Functions (formula - (ident) @function.method) - -(attach - (ident) @function.method) + (ident) @constant) (formula (field - (ident) @function.method)) + (ident) @constant + ) +) -(tagged - field: (ident) @tag) +(attach + (ident) @constant) -(field - field: (ident) @tag) +(attach + (field + (ident) @constant + ) +) -(call - item: (ident) @function) +(attach + [ + "^" + "_" + ] @operator) -(call - item: (field - field: (ident) @function.method)) +(fraction + "/" @operator) + +(fac + "!" @operator) ; MARKUP (item @@ -174,7 +186,7 @@ (heading) @title -(url) @tag +(url) @link_uri (emph) @emphasis @@ -182,28 +194,33 @@ (symbol) @operator -(shorthand) @constant.builtin +(shorthand) @operator (quote) @markup.quote -(align) @operator - -(linebreak) @constant.builtin +(code + "#" @punctuation.special) (math - "$" @operator) + "$" @punctuation.special) + +[ + (align) + (linebreak) +] @punctuation.special -"#" @operator "end" @operator -(escape) @constant.character.escape +(escape) @string.escape [ "(" ")" "{" "}" + "[" + "]" ] @punctuation.bracket [ diff --git a/languages/typst/outline.scm b/languages/typst/outline.scm index e90c354..3e5384d 100644 --- a/languages/typst/outline.scm +++ b/languages/typst/outline.scm @@ -1,10 +1,8 @@ -(heading - [ - "=" - "==" - "===" - "====" - "=====" - "======" - ] @context - (text) @name) @item +(section + (heading + . + _ @context + . + (_)+ @name + ) +) @item diff --git a/languages/typst/tasks.json b/languages/typst/tasks.json index 18cef82..9f49852 100644 --- a/languages/typst/tasks.json +++ b/languages/typst/tasks.json @@ -1,14 +1,21 @@ [ { - "label": "Typst: export file", + "label": "Typst: Export File", "command": "typst", - "args": ["compile", "\"$ZED_FILE\""], + "args": ["compile", "\"$ZED_FILE\""] }, { - "label": "Typst: watch file", + "label": "Typst: Watch File", "command": "typst", "args": ["watch", "\"$ZED_FILE\""], "reveal": "never", "hide": "always" + }, + { + "label": "Typst: Open Preview", + "command": "xdg-open", + "args": ["http://127.0.0.1:23635/"], + "reveal": "never", + "hide": "always" } ] From 8103c2a5855ca499c10929b3f77c7c2e9b3fdd71 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Sat, 28 Mar 2026 17:54:57 +0100 Subject: [PATCH 02/15] fixed outline --- languages/typst/outline.scm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/languages/typst/outline.scm b/languages/typst/outline.scm index 3e5384d..72eeca0 100644 --- a/languages/typst/outline.scm +++ b/languages/typst/outline.scm @@ -1,8 +1,6 @@ (section (heading - . - _ @context - . - (_)+ @name + . _ @context + . (text) @name ) ) @item From 222e0be67e7feab9f63dc607829f407bce9ae8c2 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Sat, 28 Mar 2026 17:59:54 +0100 Subject: [PATCH 03/15] added more info to the preview conf --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f5242de..b802237 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ To register the LSP and enable certain features (such as compile on save), add t "tinymist": { "initialization_options": { // Enable background preview + // Server will be running on 127.0.0.1:23635 "preview": { "background": { "enabled": true, From b1e390f2df07f0f35f3e9a4c2bf5fb4a902be687 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Sat, 28 Mar 2026 18:12:05 +0100 Subject: [PATCH 04/15] fix formatting --- languages/typst/highlights.scm | 20 ++++---------------- languages/typst/outline.scm | 10 +++++----- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/languages/typst/highlights.scm b/languages/typst/highlights.scm index 76eb1de..c766b99 100644 --- a/languages/typst/highlights.scm +++ b/languages/typst/highlights.scm @@ -1,7 +1,5 @@ ; Taken from https://github.com/uben0/tree-sitter-typst/blob/f457c77edffd4b93190794355ff5acf7acfb99c6/editors/helix/queries/highlights.scm#L4 ; Improved by @Gaspartcho - - ; CONTROL (branch [ @@ -27,7 +25,6 @@ (return "return" @keyword.control) - ; DIRECTIVES (import "import" @keyword.control.import) @@ -49,7 +46,6 @@ (let "let" @keyword.storage.type) - ; OPERATOR (in [ @@ -101,9 +97,7 @@ field: (ident) @variable.parameter) (field - field: (_) @property -) - + field: (_) @property) ; VALUE (ident) @variable @@ -127,7 +121,6 @@ "`" @punctuation.delimiter (blob) @text.literal) - ; MATH [ (label) @@ -149,18 +142,14 @@ (formula (field - (ident) @constant - ) -) + (ident) @constant)) (attach (ident) @constant) (attach (field - (ident) @constant - ) -) + (ident) @constant)) (attach [ @@ -199,7 +188,7 @@ (quote) @markup.quote (code - "#" @punctuation.special) + "#" @punctuation.special) (math "$" @punctuation.special) @@ -209,7 +198,6 @@ (linebreak) ] @punctuation.special - "end" @operator (escape) @string.escape diff --git a/languages/typst/outline.scm b/languages/typst/outline.scm index 72eeca0..96bfdbf 100644 --- a/languages/typst/outline.scm +++ b/languages/typst/outline.scm @@ -1,6 +1,6 @@ (section - (heading - . _ @context - . (text) @name - ) -) @item + (heading + . + _ @context + . + (text) @name)) @item From fd834151c9e20da3a7ace23ad84177eb2d3fb81f Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Sun, 29 Mar 2026 17:16:55 +0200 Subject: [PATCH 05/15] fixed variable.parameter highlighting --- languages/typst/highlights.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/languages/typst/highlights.scm b/languages/typst/highlights.scm index c766b99..38c109c 100644 --- a/languages/typst/highlights.scm +++ b/languages/typst/highlights.scm @@ -93,15 +93,15 @@ ">" ] @operator) +; VALUE +(ident) @variable + (tagged field: (ident) @variable.parameter) (field field: (_) @property) -; VALUE -(ident) @variable - (call item: (ident) @function) From 3b0aa4f243005e3270e628f3ccd37e587d23dd6a Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Sun, 29 Mar 2026 17:55:37 +0200 Subject: [PATCH 06/15] improved auto_brackets, auto lists and block comments --- languages/typst/config.toml | 18 ++++++++---------- languages/typst/indents.scm | 3 +++ languages/typst/overrides.scm | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/languages/typst/config.toml b/languages/typst/config.toml index 1ebe173..85cf84a 100644 --- a/languages/typst/config.toml +++ b/languages/typst/config.toml @@ -2,20 +2,18 @@ name = "Typst" grammar = "typst" path_suffixes = ["typ", "typst"] line_comments = ["// "] +documentation_comment = { start = "/*", prefix = "* ", end = "*/", tab_size = 1 } tab_size = 2 brackets = [ + { start = "/*", end = " */", close = true, newline = true, not_in = ["string", "comment"] }, { start = "(", end = ")", close = true, newline = true }, { start = "{", end = "}", close = true, newline = true }, { start = "[", end = "]", close = true, newline = true }, { start = "$", end = "$", close = true, newline = true }, - { start = "\"", end = "\"", close = true, newline = false, not_in = [ - "string", - ] }, - { start = "*", end = "*", close = false, newline = false, surround = true, not_in = [ - "math" - ] }, - { start = "_", end = "_", close = false, newline = false, surround = true, not_in = [ - "math" - ] }, - { start = "`", end = "`", close = false, newline = false, surround = true }, + { start = "`", end = "`", close = true, newline = false, surround = true }, + { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] }, + { start = "*", end = "*", close = true, newline = false, surround = true, not_in = ["string", "math"] }, + { start = "_", end = "_", close = true, newline = false, surround = true, not_in = ["string", "math"] }, ] +unordered_list = ["- ", "+ "] +ordered_list = [{ pattern = "(\\d+)\\. ", format = "{1}. " }] diff --git a/languages/typst/indents.scm b/languages/typst/indents.scm index 26a0af9..8efacdf 100644 --- a/languages/typst/indents.scm +++ b/languages/typst/indents.scm @@ -13,3 +13,6 @@ (_ "$" "$" @end) @indent + +((comment) @indent + (#match? @indent "^/\\*")) diff --git a/languages/typst/overrides.scm b/languages/typst/overrides.scm index 2f6c6c4..4ca3794 100644 --- a/languages/typst/overrides.scm +++ b/languages/typst/overrides.scm @@ -1,3 +1,5 @@ (string) @string (math) @math + +(comment) @comment.inclusive From 16f1fcb667b40daa7ab61846501dc3d764992336 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Sun, 29 Mar 2026 18:06:19 +0200 Subject: [PATCH 07/15] prevented string and math blocks to be affected by raimbow brackets. Added raw span/block to bracket matching --- languages/typst/brackets.scm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/languages/typst/brackets.scm b/languages/typst/brackets.scm index 00cebf2..6e4cda9 100644 --- a/languages/typst/brackets.scm +++ b/languages/typst/brackets.scm @@ -8,7 +8,21 @@ "}" @close) ("\"" @open - "\"" @close) + "\"" @close + (#set! rainbow.exclude)) + +("`" @open + "`" @close + (#set! rainbow.exclude)) + +("`" @open + "`" @close + (#set! rainbow.exclude)) + +("```" @open + "```" @close + (#set! rainbow.exclude)) ("$" @open - "$" @close) + "$" @close + (#set! rainbow.exclude)) From e0de517d2986ccadada23ae41fe1fce49e146ac2 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Mon, 30 Mar 2026 22:06:23 +0200 Subject: [PATCH 08/15] improved "Export File" task behavior --- languages/typst/tasks.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/languages/typst/tasks.json b/languages/typst/tasks.json index 9f49852..2950ca3 100644 --- a/languages/typst/tasks.json +++ b/languages/typst/tasks.json @@ -2,7 +2,8 @@ { "label": "Typst: Export File", "command": "typst", - "args": ["compile", "\"$ZED_FILE\""] + "args": ["compile", "\"$ZED_FILE\""], + "hide": "on_success" }, { "label": "Typst: Watch File", From 0ffae73a04ee6ef7cb34b9fdcc26eef47414cf23 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Mon, 6 Apr 2026 10:39:51 +0200 Subject: [PATCH 09/15] fixed false information about configuration file and formatted the `jsonc` part of the readme --- README.md | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b802237..8bfa166 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,15 @@ ## Usage -To register the LSP and enable certain features (such as compile on save), add the following your `settings.json` (or `.zed/settings.json` in the project root for project-specific config), +To register the LSP and enable certain features (such as compile on save), add the following to your local (resp. server) configuration file (`~/.zed/settings.json`): ```jsonc // In settings.json -"lsp": { - "tinymist": { - "initialization_options": { +{ + // ... + "lsp": { + "tinymist": { + "initialization_options": { // Enable background preview // Server will be running on 127.0.0.1:23635 "preview": { @@ -18,21 +20,22 @@ To register the LSP and enable certain features (such as compile on save), add t }, }, - "settings": { - // Compile on save - // This will compile a PDF for the `main.typ` file in the project root. - "exportPdf": "onSave", - "outputPath": "$root/$name" - - // Enable formatter - "formatterMode": "typstyle", - } - } + "settings": { + // Compile on save + // This will compile a PDF for the `main.typ` file in the project root. + "exportPdf": "onSave", + "outputPath": "$root/$name" + + // Enable formatter + "formatterMode": "typstyle", + } + } + } + // ... } ``` - -To see all available options refer to [the tinymist documentation](https://github.com/Myriad-Dreamin/tinymist/blob/main/editors/neovim/Configuration.md). +To see all available options refer to [the tinymist documentation](https://github.com/Myriad-Dreamin/tinymist/blob/main/editors/neovim/Configuration.md). Beware that the configuration options displayed there apply to **NeoVim**, not Zed, so some might be incorrect or misleading ## Components From 0de9652e2c85c334a281e176add5e2aeeed13cd3 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Mon, 11 May 2026 11:14:38 +0200 Subject: [PATCH 10/15] added highlights fallback captures for raw blocks --- languages/typst/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/languages/typst/highlights.scm b/languages/typst/highlights.scm index 38c109c..453d4ee 100644 --- a/languages/typst/highlights.scm +++ b/languages/typst/highlights.scm @@ -111,11 +111,11 @@ ; RAW (raw_blck - "```" @embedded + "```" @punctuation.delimiter @embedded (blob) @text.literal) (raw_blck - lang: (ident) @embedded) + lang: (ident) @tag @embedded) (raw_span "`" @punctuation.delimiter From bad1624d62987da8c11e0d60e069d4c12e246960 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Mon, 11 May 2026 11:19:00 +0200 Subject: [PATCH 11/15] removed duplicate entry in bracket capture --- languages/typst/brackets.scm | 4 ---- 1 file changed, 4 deletions(-) diff --git a/languages/typst/brackets.scm b/languages/typst/brackets.scm index 6e4cda9..0e43fd4 100644 --- a/languages/typst/brackets.scm +++ b/languages/typst/brackets.scm @@ -15,10 +15,6 @@ "`" @close (#set! rainbow.exclude)) -("`" @open - "`" @close - (#set! rainbow.exclude)) - ("```" @open "```" @close (#set! rainbow.exclude)) From 70148e58b9a21cc024fae6fed04fb2c3a37a7b0d Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Mon, 11 May 2026 11:36:15 +0200 Subject: [PATCH 12/15] Added instructions to the README to enable soft wrap in the editor --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8bfa166..7559841 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ To register the LSP and enable certain features (such as compile on save), add t ```jsonc // In settings.json { - // ... "lsp": { "tinymist": { "initialization_options": { @@ -28,10 +27,16 @@ To register the LSP and enable certain features (such as compile on save), add t // Enable formatter "formatterMode": "typstyle", - } - } - } - // ... + } + } + }, + + "languages": { + "Typst": { + // Enable soft wrap + "soft_wrap": "editor_width", + }, + }, } ``` From a0d912b6b6102695255d80eb0514f4c8c0f5f8c2 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Mon, 11 May 2026 11:46:42 +0200 Subject: [PATCH 13/15] enabled soft wrap by default --- README.md | 4 ++-- languages/typst/config.toml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7559841..abea47d 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ To register the LSP and enable certain features (such as compile on save), add t "languages": { "Typst": { - // Enable soft wrap - "soft_wrap": "editor_width", + // Disable soft wrap + "soft_wrap": "none", }, }, } diff --git a/languages/typst/config.toml b/languages/typst/config.toml index 85cf84a..ee378f2 100644 --- a/languages/typst/config.toml +++ b/languages/typst/config.toml @@ -4,6 +4,7 @@ path_suffixes = ["typ", "typst"] line_comments = ["// "] documentation_comment = { start = "/*", prefix = "* ", end = "*/", tab_size = 1 } tab_size = 2 +soft_wrap = "editor_width" brackets = [ { start = "/*", end = " */", close = true, newline = true, not_in = ["string", "comment"] }, { start = "(", end = ")", close = true, newline = true }, From 403d4ababfb8305f15a484fbde89f869d674f4c4 Mon Sep 17 00:00:00 2001 From: Gaspard Deremble Date: Tue, 12 May 2026 19:11:22 +0200 Subject: [PATCH 14/15] fixed bug where fractions identifiers would not be captured --- languages/typst/highlights.scm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/languages/typst/highlights.scm b/languages/typst/highlights.scm index 453d4ee..007feb6 100644 --- a/languages/typst/highlights.scm +++ b/languages/typst/highlights.scm @@ -151,6 +151,9 @@ (field (ident) @constant)) +(fraction + (ident) @constant) + (attach [ "^" From c15b7e343590791d6a0cbfbe15ba008b445a644c Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Thu, 14 May 2026 12:51:04 +0200 Subject: [PATCH 15/15] Apply suggestions from code review Co-authored-by: Finn Evers --- languages/typst/highlights.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/languages/typst/highlights.scm b/languages/typst/highlights.scm index 007feb6..a1b58ee 100644 --- a/languages/typst/highlights.scm +++ b/languages/typst/highlights.scm @@ -125,7 +125,7 @@ [ (label) (ref) -] @label +] @tag @label (number) @number @@ -178,7 +178,7 @@ (heading) @title -(url) @link_uri +(url) @tag @link_uri (emph) @emphasis @@ -186,7 +186,7 @@ (symbol) @operator -(shorthand) @operator +(shorthand) @constant.builtin @operator (quote) @markup.quote