From 4d7443f2ae731b7a492a2f0609953650a0a950b8 Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Thu, 26 Aug 2021 20:26:13 -0400 Subject: [PATCH 01/10] added submodule --- .gitmodules | 3 + helix-syntax/languages/tree-sitter-lua | 1 + languages.toml | 7 ++ runtime/queries/lua/highlights.scm | 159 +++++++++++++++++++++++++ 4 files changed, 170 insertions(+) create mode 160000 helix-syntax/languages/tree-sitter-lua create mode 100644 runtime/queries/lua/highlights.scm diff --git a/.gitmodules b/.gitmodules index e750198aee56..fcc3d4bbc099 100644 --- a/.gitmodules +++ b/.gitmodules @@ -102,3 +102,6 @@ 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 diff --git a/helix-syntax/languages/tree-sitter-lua b/helix-syntax/languages/tree-sitter-lua new file mode 160000 index 000000000000..6f5d40190ec8 --- /dev/null +++ b/helix-syntax/languages/tree-sitter-lua @@ -0,0 +1 @@ +Subproject commit 6f5d40190ec8a0aa8c8410699353d820f4f7d7a6 diff --git a/languages.toml b/languages.toml index 47155523b87a..2fc3e2d2f707 100644 --- a/languages.toml +++ b/languages.toml @@ -224,6 +224,13 @@ roots = [] comment-token = ";" indent = { tab-width = 4, unit = " " } +[[language]] +name = "lua" +scope = "source.lua" +file-types = ["lua"] +roots = [] +indent = { tab-width = 2, unit = " " } + # [[language]] # name = "haskell" # scope = "source.haskell" diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm new file mode 100644 index 000000000000..1bcbb3587dca --- /dev/null +++ b/runtime/queries/lua/highlights.scm @@ -0,0 +1,159 @@ +;;; Highlighting for lua + +;;; Builtins +(self) @variable.builtin + +;; Keywords + +(if_statement +[ + "if" + "then" + "end" +] @conditional) + +[ + "else" + "elseif" + "then" +] @conditional + +(for_statement +[ + "for" + "do" + "end" +] @repeat) + +(for_in_statement +[ + "for" + "do" + "end" +] @repeat) + +(while_statement +[ + "while" + "do" + "end" +] @repeat) + +(repeat_statement +[ + "repeat" + "until" +] @repeat) + +(do_statement +[ + "do" + "end" +] @keyword) + +[ + "in" + "local" + (break_statement) + "goto" +] @keyword + +"return" @keyword.return + +;; Operators + +[ + "not" + "and" + "or" +] @keyword.operator + +[ +"=" +"~=" +"==" +"<=" +">=" +"<" +">" +"+" +"-" +"%" +"/" +"//" +"*" +"^" +"&" +"~" +"|" +">>" +"<<" +".." +"#" + ] @operator + +;; Punctuation +["," "." ":" ";"] @punctuation.delimiter + +;; Brackets +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +;; Variables +(identifier) @variable + +;; Constants +[ +(false) +(true) +] @boolean +(nil) @constant.builtin +(spread) @constant ;; "..." +((identifier) @constant + (#match? @constant "^[A-Z][A-Z_0-9]*$")) + +;; Functions +(function [(function_name) (identifier)] @function) +(function ["function" "end"] @keyword.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) + +(property_identifier) @property + +(function_call + [((identifier) @variable (method) @method) + ((_) (method) @method) + (identifier) @function + (field_expression (property_identifier) @function)] + . (arguments)) + +;; Parameters +(parameters + (identifier) @parameter) + +;; 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) @field (_)) +(shebang) @comment + +;; Error +(ERROR) @error From 12f50e5cdcacb1d4c74fa60f124dd977a532a939 Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Thu, 26 Aug 2021 20:36:43 -0400 Subject: [PATCH 02/10] small changes --- runtime/queries/lua/highlights.scm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 1bcbb3587dca..c54e8e7ee794 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -56,10 +56,9 @@ "local" (break_statement) "goto" + "return" ] @keyword -"return" @keyword.return - ;; Operators [ @@ -152,7 +151,7 @@ (number) @number (label_statement) @label ; A bit of a tricky one, this will only match field names -(field . (identifier) @field (_)) +(field . (identifier) @property (_)) (shebang) @comment ;; Error From 36aeba6fb88cd2a10ea4defc91a71f38a1e320e1 Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Fri, 27 Aug 2021 10:05:40 -0400 Subject: [PATCH 03/10] updated some stuff --- runtime/queries/lua/highlights.scm | 8 ++++---- runtime/queries/lua/indents.toml | 33 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 runtime/queries/lua/indents.toml diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index c54e8e7ee794..73a111b27d4a 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -104,10 +104,10 @@ "}" ] @punctuation.bracket -;; Variables -(identifier) @variable +; ;; Variables +; (identifier) @variable -;; Constants +; ;; Constants [ (false) (true) @@ -117,7 +117,7 @@ ((identifier) @constant (#match? @constant "^[A-Z][A-Z_0-9]*$")) -;; Functions +; ;; Functions (function [(function_name) (identifier)] @function) (function ["function" "end"] @keyword.function) diff --git a/runtime/queries/lua/indents.toml b/runtime/queries/lua/indents.toml new file mode 100644 index 000000000000..d67ca54c0714 --- /dev/null +++ b/runtime/queries/lua/indents.toml @@ -0,0 +1,33 @@ +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", + "}", + ")", +] +# [ +# "{" +# "(" +# "then" +# (else) +# (elseif) +# ] @branch + +# (comment) @ignore From c75ee3bbbd195357442fc1e4da4444c5c25747ac Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Fri, 27 Aug 2021 10:07:04 -0400 Subject: [PATCH 04/10] remove --- runtime/queries/lua/highlights.scm | 3 --- 1 file changed, 3 deletions(-) diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 73a111b27d4a..8d571e65d1b8 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -104,9 +104,6 @@ "}" ] @punctuation.bracket -; ;; Variables -; (identifier) @variable - ; ;; Constants [ (false) From 2ba622ab1700da3d54cdc36e59586eb221d10837 Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Fri, 27 Aug 2021 10:20:45 -0400 Subject: [PATCH 05/10] shallow clone --- .gitmodules | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitmodules b/.gitmodules index fcc3d4bbc099..eda3552475bf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -105,3 +105,4 @@ [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 From 897a2005963b029d5bcbcd2d41f314740caddfe4 Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Tue, 31 Aug 2021 08:57:04 -0400 Subject: [PATCH 06/10] correct indent --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index eda3552475bf..81abe942a280 100644 --- a/.gitmodules +++ b/.gitmodules @@ -105,4 +105,4 @@ [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 + shallow = true From da692c7c517d17ea7941c5fd77cd690d5f6adc24 Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Wed, 1 Sep 2021 07:35:57 -0400 Subject: [PATCH 07/10] shallow --- .gitmodules | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitmodules b/.gitmodules index b918311637fd..83d214816f8e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -105,6 +105,7 @@ [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-zig"] path = helix-syntax/languages/tree-sitter-zig url = https://github.com/maxxnino/tree-sitter-zig From e38c8e47e13722788a0cb95463b2872f265f3309 Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Wed, 1 Sep 2021 09:08:43 -0400 Subject: [PATCH 08/10] ok --- runtime/queries/lua/indents.toml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/runtime/queries/lua/indents.toml b/runtime/queries/lua/indents.toml index d67ca54c0714..df1a9752a043 100644 --- a/runtime/queries/lua/indents.toml +++ b/runtime/queries/lua/indents.toml @@ -22,12 +22,3 @@ oudent = [ "}", ")", ] -# [ -# "{" -# "(" -# "then" -# (else) -# (elseif) -# ] @branch - -# (comment) @ignore From a7cf3f951a03fab5e1a6c83366715b5ab9890837 Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Wed, 1 Sep 2021 11:03:38 -0400 Subject: [PATCH 09/10] highlights --- runtime/queries/lua/highlights.scm | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 8d571e65d1b8..2b7c910caf55 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -114,10 +114,19 @@ ((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) @@ -128,19 +137,15 @@ (function_definition ["function" "end"] @keyword.function) -(property_identifier) @property - (function_call - [((identifier) @variable (method) @method) + [ + ((identifier) @variable (method) @method) ((_) (method) @method) (identifier) @function - (field_expression (property_identifier) @function)] + (field_expression (property_identifier) @function) + ] . (arguments)) -;; Parameters -(parameters - (identifier) @parameter) - ;; Nodes (table ["{" "}"] @constructor) (comment) @comment @@ -151,5 +156,11 @@ (field . (identifier) @property (_)) (shebang) @comment +;; Property +(property_identifier) @property + +;; Variable +(identifier) @variable + ;; Error (ERROR) @error From 97e8857a38731bd13e9b780365e4ae72a2d6c6fe Mon Sep 17 00:00:00 2001 From: Brian Shu Date: Wed, 1 Sep 2021 11:19:43 -0400 Subject: [PATCH 10/10] proper captures --- runtime/queries/lua/highlights.scm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 2b7c910caf55..8e27a39af702 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -10,40 +10,40 @@ "if" "then" "end" -] @conditional) +] @keyword.control.conditional) [ "else" "elseif" "then" -] @conditional +] @keyword.control.conditional (for_statement [ "for" "do" "end" -] @repeat) +] @keyword.control.loop) (for_in_statement [ "for" "do" "end" -] @repeat) +] @keyword.control.loop) (while_statement [ "while" "do" "end" -] @repeat) +] @keyword.control.loop) (repeat_statement [ "repeat" "until" -] @repeat) +] @keyword.control.loop) (do_statement [