From ae3f9366118bae9775b5229b817d1131c84cfc96 Mon Sep 17 00:00:00 2001 From: oberblastmeister <61095988+oberblastmeister@users.noreply.github.com> Date: Wed, 1 Sep 2021 11:54:21 -0400 Subject: [PATCH] Lua support (#665) * added submodule * small changes * updated some stuff * remove * shallow clone * correct indent * shallow * ok * highlights * proper captures --- .gitmodules | 4 + helix-syntax/languages/tree-sitter-lua | 1 + languages.toml | 8 ++ runtime/queries/lua/highlights.scm | 166 +++++++++++++++++++++++++ runtime/queries/lua/indents.toml | 24 ++++ 5 files changed, 203 insertions(+) create mode 160000 helix-syntax/languages/tree-sitter-lua create mode 100644 runtime/queries/lua/highlights.scm create mode 100644 runtime/queries/lua/indents.toml diff --git a/.gitmodules b/.gitmodules index aba8084c..ae4984da 100644 --- a/.gitmodules +++ b/.gitmodules @@ -102,6 +102,10 @@ path = helix-syntax/languages/tree-sitter-protobuf url = https://github.com/yusdacra/tree-sitter-protobuf.git shallow = true +[submodule "helix-syntax/languages/tree-sitter-lua"] + path = helix-syntax/languages/tree-sitter-lua + url = https://github.com/nvim-treesitter/tree-sitter-lua + shallow = true [submodule "helix-syntax/languages/tree-sitter-yaml"] path = helix-syntax/languages/tree-sitter-yaml url = https://github.com/ikatyang/tree-sitter-yaml diff --git a/helix-syntax/languages/tree-sitter-lua b/helix-syntax/languages/tree-sitter-lua new file mode 160000 index 00000000..6f5d4019 --- /dev/null +++ b/helix-syntax/languages/tree-sitter-lua @@ -0,0 +1 @@ +Subproject commit 6f5d40190ec8a0aa8c8410699353d820f4f7d7a6 diff --git a/languages.toml b/languages.toml index 7a2ea24d..7164c4df 100644 --- a/languages.toml +++ b/languages.toml @@ -224,6 +224,14 @@ roots = [] comment-token = ";" indent = { tab-width = 4, unit = " " } +[[language]] +name = "lua" +scope = "source.lua" +file-types = ["lua"] +roots = [] +comment-token = "--" +indent = { tab-width = 2, unit = " " } + [[language]] name = "yaml" scope = "source.yaml" diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm new file mode 100644 index 00000000..8e27a39a --- /dev/null +++ b/runtime/queries/lua/highlights.scm @@ -0,0 +1,166 @@ +;;; Highlighting for lua + +;;; Builtins +(self) @variable.builtin + +;; Keywords + +(if_statement +[ + "if" + "then" + "end" +] @keyword.control.conditional) + +[ + "else" + "elseif" + "then" +] @keyword.control.conditional + +(for_statement +[ + "for" + "do" + "end" +] @keyword.control.loop) + +(for_in_statement +[ + "for" + "do" + "end" +] @keyword.control.loop) + +(while_statement +[ + "while" + "do" + "end" +] @keyword.control.loop) + +(repeat_statement +[ + "repeat" + "until" +] @keyword.control.loop) + +(do_statement +[ + "do" + "end" +] @keyword) + +[ + "in" + "local" + (break_statement) + "goto" + "return" +] @keyword + +;; Operators + +[ + "not" + "and" + "or" +] @keyword.operator + +[ +"=" +"~=" +"==" +"<=" +">=" +"<" +">" +"+" +"-" +"%" +"/" +"//" +"*" +"^" +"&" +"~" +"|" +">>" +"<<" +".." +"#" + ] @operator + +;; Punctuation +["," "." ":" ";"] @punctuation.delimiter + +;; Brackets +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +; ;; Constants +[ +(false) +(true) +] @boolean +(nil) @constant.builtin +(spread) @constant ;; "..." +((identifier) @constant + (#match? @constant "^[A-Z][A-Z_0-9]*$")) + +;; Parameters +(parameters + (identifier) @parameter) + +; ;; Functions +(function [(function_name) (identifier)] @function) +(function ["function" "end"] @keyword.function) + +(function + (function_name + (function_name_field + (property_identifier) @function .))) + +(local_function (identifier) @function) +(local_function ["function" "end"] @keyword.function) + +(variable_declaration + (variable_declarator (identifier) @function) (function_definition)) +(local_variable_declaration + (variable_declarator (identifier) @function) (function_definition)) + +(function_definition ["function" "end"] @keyword.function) + +(function_call + [ + ((identifier) @variable (method) @method) + ((_) (method) @method) + (identifier) @function + (field_expression (property_identifier) @function) + ] + . (arguments)) + +;; Nodes +(table ["{" "}"] @constructor) +(comment) @comment +(string) @string +(number) @number +(label_statement) @label +; A bit of a tricky one, this will only match field names +(field . (identifier) @property (_)) +(shebang) @comment + +;; Property +(property_identifier) @property + +;; Variable +(identifier) @variable + +;; Error +(ERROR) @error diff --git a/runtime/queries/lua/indents.toml b/runtime/queries/lua/indents.toml new file mode 100644 index 00000000..df1a9752 --- /dev/null +++ b/runtime/queries/lua/indents.toml @@ -0,0 +1,24 @@ +indent = [ + "function_definition", + "variable_declaration", + "local_variable_declaration", + "field", + "local_function", + "function", + "if_statement", + "for_statement", + "for_in_statement", + "repeat_statement", + "return_statement", + "while_statement", + "table", + "arguments", + "do_statement", +] + +oudent = [ + "end", + "until", + "}", + ")", +]