From 15f23a313bd293df876c04e3559a62ce16a00855 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Fri, 27 Oct 2023 01:27:42 +0200 Subject: [PATCH] Add typst language and lsp (#7474) Co-authored-by: Michael Davis --- book/src/generated/lang-support.md | 1 + languages.toml | 22 ++++++++ runtime/queries/typst/highlights.scm | 77 ++++++++++++++++++++++++++++ runtime/queries/typst/injections.scm | 6 +++ 4 files changed, 106 insertions(+) create mode 100644 runtime/queries/typst/highlights.scm create mode 100644 runtime/queries/typst/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 6fdc6f1151e1..58bc3d059970 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -163,6 +163,7 @@ | tsx | ✓ | ✓ | ✓ | `typescript-language-server` | | twig | ✓ | | | | | typescript | ✓ | ✓ | ✓ | `typescript-language-server` | +| typst | ✓ | | | `typst-lsp` | | ungrammar | ✓ | | | | | unison | ✓ | | | | | uxntal | ✓ | | | | diff --git a/languages.toml b/languages.toml index 77c629e49462..a6c9d5567f10 100644 --- a/languages.toml +++ b/languages.toml @@ -88,6 +88,7 @@ wgsl_analyzer = { command = "wgsl_analyzer" } yaml-language-server = { command = "yaml-language-server", args = ["--stdio"] } zls = { command = "zls" } blueprint-compiler = { command = "blueprint-compiler", args = ["lsp"] } +typst-lsp = { command = "typst-lsp" } [language-server.ansible-language-server] command = "ansible-language-server" @@ -2912,6 +2913,27 @@ roots = [] indent = { tab-width = 2, unit = " " } grammar = "html" +[[language]] +name = "typst" +scope = "source.typst" +injection-regex = "typst" +file-types = ["typst", "typ"] +roots = [] +comment-token = "//" +language-servers = ["typst-lsp"] +indent = { tab-width = 2, unit = " " } + +[language.auto-pairs] +'(' = ')' +'{' = '}' +'[' = ']' +'$' = '$' +'"' = '"' + +[[grammar]] +name = "typst" +source = { git = "https://github.com/uben0/tree-sitter-typst", rev = "e35aa22395fdde82bbc4b5700c324ce346dfc9e5" } + [[language]] name = "nunjucks" scope = "text.html.nunjucks" diff --git a/runtime/queries/typst/highlights.scm b/runtime/queries/typst/highlights.scm new file mode 100644 index 000000000000..b422e05b3e1d --- /dev/null +++ b/runtime/queries/typst/highlights.scm @@ -0,0 +1,77 @@ +(call + item: (ident) @function) +(call + item: (field field: (ident) @function.method)) +(tagged field: (ident) @tag) +(field field: (ident) @tag) +(comment) @comment + +; CONTROL +(let "let" @keyword.storage.type) +(branch ["if" "else"] @keyword.control.conditional) +(while "while" @keyword.control.repeat) +(for ["for" "in"] @keyword.control.repeat) +(import "import" @keyword.control.import) +(as "as" @keyword.operator) +(include "include" @keyword.control.import) +(show "show" @keyword.control) +(set "set" @keyword.control) +(return "return" @keyword.control) +(flow ["break" "continue"] @keyword.control) + +; OPERATOR +(in ["in" "not"] @keyword.operator) +(and "and" @keyword.operator) +(or "or" @keyword.operator) +(not "not" @keyword.operator) +(sign ["+" "-"] @operator) +(add "+" @operator) +(sub "-" @operator) +(mul "*" @operator) +(div "/" @operator) +(cmp ["==" "<=" ">=" "!=" "<" ">"] @operator) +(fraction "/" @operator) +(fac "!" @operator) +(attach ["^" "_"] @operator) +(wildcard) @operator + +; VALUE +(raw_blck "```" @operator) @markup.raw.block +(raw_span "`" @operator) @markup.raw.block +(raw_blck lang: (ident) @tag) +(label) @tag +(ref) @tag +(number) @constant.numeric +(string) @string +(content ["[" "]"] @operator) +(bool) @constant.builtin.boolean +(builtin) @constant.builtin +(none) @constant.builtin +(auto) @constant.builtin +(ident) @variable +(call + item: (builtin) @function.builtin) + +; MARKUP +(item "-" @markup.list) +(term ["/" ":"] @markup.list) +(heading ["=" "==" "===" "====" "====="] @markup.heading.marker) @markup.heading +(url) @tag +(emph) @markup.italic +(strong) @markup.bold +(symbol) @constant.character +(shorthand) @constant.builtin +(quote) @markup.quote +(align) @operator +(letter) @constant.character +(linebreak) @constant.builtin + +(math "$" @operator) +"#" @operator +"end" @operator + +(escape) @constant.character.escape +["(" ")" "{" "}"] @punctuation.bracket +["," ";" ".." ":" "sep"] @punctuation.delimiter +"assign" @punctuation +(field "." @punctuation) diff --git a/runtime/queries/typst/injections.scm b/runtime/queries/typst/injections.scm new file mode 100644 index 000000000000..8039b4cab7ca --- /dev/null +++ b/runtime/queries/typst/injections.scm @@ -0,0 +1,6 @@ +(raw_blck + (blob) @injection.shebang @injection.content) + +(raw_blck + lang: (ident) @injection.language + (blob) @injection.content) \ No newline at end of file