diff --git a/README.md b/README.md index 7132a0e..abea47d 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,49 @@ # 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 -"lsp": { - "tinymist": { - "settings": { - "exportPdf": "onSave", - "outputPath": "$root/$name" - } - } + +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": { + // Enable background preview + // Server will be running on 127.0.0.1:23635 + "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", + } + } + }, + + "languages": { + "Typst": { + // Disable soft wrap + "soft_wrap": "none", + }, + }, } ``` -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). 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/brackets.scm b/languages/typst/brackets.scm index 00cebf2..0e43fd4 100644 --- a/languages/typst/brackets.scm +++ b/languages/typst/brackets.scm @@ -8,7 +8,17 @@ "}" @close) ("\"" @open - "\"" @close) + "\"" @close + (#set! rainbow.exclude)) + +("`" @open + "`" @close + (#set! rainbow.exclude)) + +("```" @open + "```" @close + (#set! rainbow.exclude)) ("$" @open - "$" @close) + "$" @close + (#set! rainbow.exclude)) diff --git a/languages/typst/config.toml b/languages/typst/config.toml index 1ebe173..ee378f2 100644 --- a/languages/typst/config.toml +++ b/languages/typst/config.toml @@ -2,20 +2,19 @@ name = "Typst" grammar = "typst" 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 }, { 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/highlights.scm b/languages/typst/highlights.scm index 0535d9c..a1b58ee 100644 --- a/languages/typst/highlights.scm +++ b/languages/typst/highlights.scm @@ -1,9 +1,6 @@ ; 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) - (branch [ "if" @@ -19,9 +16,21 @@ "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 +43,8 @@ (set "set" @keyword.control) -(return - "return" @keyword.control) - -(flow - [ - "break" - "continue" - ] @keyword.control) +(let + "let" @keyword.storage.type) ; OPERATOR (in @@ -90,77 +93,78 @@ ">" ] @operator) -(fraction - "/" @operator) +; VALUE +(ident) @variable -(fac - "!" @operator) +(tagged + field: (ident) @variable.parameter) -(attach - [ - "^" - "_" - ] @operator) +(field + field: (_) @property) -(wildcard) @operator +(call + item: (ident) @function) -; VALUE -(ident) @variable +(call + item: (field + field: (ident) @function.method)) +; RAW (raw_blck - "```" @punctuation.delimiter + "```" @punctuation.delimiter @embedded (blob) @text.literal) (raw_blck - lang: (ident) @tag) + lang: (ident) @tag @embedded) (raw_span "`" @punctuation.delimiter (blob) @text.literal) -(label) @tag - -(ref) @tag +; MATH +[ + (label) + (ref) +] @tag @label (number) @number (string) @string -(content - [ - "[" - "]" - ] @operator) - (bool) @boolean (none) @constant.builtin (auto) @constant.builtin -; Functions (formula - (ident) @function.method) + (ident) @constant) + +(formula + (field + (ident) @constant)) (attach - (ident) @function.method) + (ident) @constant) -(formula +(attach (field - (ident) @function.method)) + (ident) @constant)) -(tagged - field: (ident) @tag) +(fraction + (ident) @constant) -(field - field: (ident) @tag) +(attach + [ + "^" + "_" + ] @operator) -(call - item: (ident) @function) +(fraction + "/" @operator) -(call - item: (field - field: (ident) @function.method)) +(fac + "!" @operator) ; MARKUP (item @@ -174,7 +178,7 @@ (heading) @title -(url) @tag +(url) @tag @link_uri (emph) @emphasis @@ -182,28 +186,32 @@ (symbol) @operator -(shorthand) @constant.builtin +(shorthand) @constant.builtin @operator (quote) @markup.quote -(align) @operator - -(linebreak) @constant.builtin +(code + "#" @punctuation.special) (math - "$" @operator) + "$" @punctuation.special) -"#" @operator +[ + (align) + (linebreak) +] @punctuation.special "end" @operator -(escape) @constant.character.escape +(escape) @string.escape [ "(" ")" "{" "}" + "[" + "]" ] @punctuation.bracket [ 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/outline.scm b/languages/typst/outline.scm index e90c354..96bfdbf 100644 --- a/languages/typst/outline.scm +++ b/languages/typst/outline.scm @@ -1,10 +1,6 @@ -(heading - [ - "=" - "==" - "===" - "====" - "=====" - "======" - ] @context - (text) @name) @item +(section + (heading + . + _ @context + . + (text) @name)) @item 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 diff --git a/languages/typst/tasks.json b/languages/typst/tasks.json index 18cef82..2950ca3 100644 --- a/languages/typst/tasks.json +++ b/languages/typst/tasks.json @@ -1,14 +1,22 @@ [ { - "label": "Typst: export file", + "label": "Typst: Export File", "command": "typst", "args": ["compile", "\"$ZED_FILE\""], + "hide": "on_success" }, { - "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" } ]