From 63d52de5e7406344c1f2466a659644b268beb553 Mon Sep 17 00:00:00 2001 From: Brian Dorsey Date: Sun, 25 Feb 2024 23:23:30 -0800 Subject: [PATCH 1/3] update languages.toml: tree-sitter-lua grammar repo has moved, use new URL and the rev of the latest release (v0.0.19) --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index 750ec90889cc..155ce60b2dd3 100644 --- a/languages.toml +++ b/languages.toml @@ -1101,7 +1101,7 @@ language-servers = [ "lua-language-server" ] [[grammar]] name = "lua" -source = { git = "https://github.com/MunifTanjim/tree-sitter-lua", rev = "887dfd4e83c469300c279314ff1619b1d0b85b91" } +source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-lua", rev = "88e446476a1e97a8724dff7a23e2d709855077f2" } [[language]] name = "svelte" From ef5f4c6e5e383f437bda4b778648b7f2f11f42a9 Mon Sep 17 00:00:00 2001 From: Brian Dorsey Date: Tue, 27 Feb 2024 21:23:08 -0800 Subject: [PATCH 2/3] update highlight queries a novice attempt to port query updates from the source repo to Helix captures and ordering --- runtime/queries/lua/highlights.scm | 81 +++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 13 deletions(-) diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index f48e607c597f..0db10821c893 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -1,9 +1,5 @@ ;;; Highlighting for lua -;;; Builtins -((identifier) @variable.builtin - (#eq? @variable.builtin "self")) - ;; Keywords (if_statement @@ -130,16 +126,65 @@ ((identifier) @constant (#match? @constant "^[A-Z][A-Z_0-9]*$")) -;; Parameters -(parameters - (identifier) @variable.parameter) +;; Tables + +(field name: (identifier) @field) + +(dot_index_expression field: (identifier) @field) + +(table_constructor +[ + "{" + "}" +] @constructor) + +;; Functions + +(parameters (identifier) @variable.parameter) -; ;; Functions -(function_declaration name: (identifier) @function) -(function_call name: (identifier) @function.call) +(function_call + (identifier) @function.builtin + (#any-of? @function.builtin + ;; built-in functions in Lua 5.1 + "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" + "load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print" + "rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable" + "tonumber" "tostring" "type" "unpack" "xpcall")) -(function_declaration name: (dot_index_expression field: (identifier) @function)) -(function_call name: (dot_index_expression field: (identifier) @function.call)) +(function_declaration + name: [ + (identifier) @function + (dot_index_expression + field: (identifier) @function) + ]) + +(function_declaration + name: (method_index_expression + method: (identifier) @function.method)) + +(assignment_statement + (variable_list . + name: [ + (identifier) @function + (dot_index_expression + field: (identifier) @function) + ]) + (expression_list . + value: (function_definition))) + +(table_constructor + (field + name: (identifier) @function + value: (function_definition))) + +(function_call + name: [ + (identifier) @function.call + (dot_index_expression + field: (identifier) @function.call) + (method_index_expression + method: (identifier) @function.method.call) + ]) ; TODO: incorrectly highlights variable N in `N, nop = 42, function() end` (assignment_statement @@ -153,6 +198,7 @@ ;; Nodes (comment) @comment (string) @string +(escape_sequence) @string.escape (number) @constant.numeric.integer (label_statement) @label ; A bit of a tricky one, this will only match field names @@ -162,7 +208,16 @@ ;; Property (dot_index_expression field: (identifier) @variable.other.member) -;; Variable +;; Variables +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) + +(variable_list + (attribute + "<" @punctuation.bracket + (identifier) @attribute + ">" @punctuation.bracket)) + (identifier) @variable ;; Error From 4d423f3b8a44690bbd24fdcec6a1783e8a65442c Mon Sep 17 00:00:00 2001 From: Brian Dorsey Date: Wed, 28 Feb 2024 09:30:19 -0800 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Michael Davis --- runtime/queries/lua/highlights.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 0db10821c893..2f3b3c05f6e8 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -128,9 +128,9 @@ ;; Tables -(field name: (identifier) @field) +(field name: (identifier) @variable.other.member) -(dot_index_expression field: (identifier) @field) +(dot_index_expression field: (identifier) @variable.other.member) (table_constructor [ @@ -198,7 +198,7 @@ ;; Nodes (comment) @comment (string) @string -(escape_sequence) @string.escape +(escape_sequence) @constant.character.escape (number) @constant.numeric.integer (label_statement) @label ; A bit of a tricky one, this will only match field names