Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lua support #665

Merged
merged 12 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@
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
oberblastmeister marked this conversation as resolved.
Show resolved Hide resolved
shallow = true
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-lua
Submodule tree-sitter-lua added at 6f5d40
7 changes: 7 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
155 changes: 155 additions & 0 deletions runtime/queries/lua/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
;;; Highlighting for lua

;;; Builtins
(self) @variable.builtin

;; Keywords

(if_statement
[
"if"
"then"
"end"
] @conditional)
oberblastmeister marked this conversation as resolved.
Show resolved Hide resolved

[
"else"
"elseif"
"then"
] @conditional
oberblastmeister marked this conversation as resolved.
Show resolved Hide resolved

(for_statement
[
"for"
"do"
"end"
] @repeat)
oberblastmeister marked this conversation as resolved.
Show resolved Hide resolved

(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"
"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]*$"))

; ;; 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) @property (_))
(shebang) @comment

;; Error
(ERROR) @error
33 changes: 33 additions & 0 deletions runtime/queries/lua/indents.toml
Original file line number Diff line number Diff line change
@@ -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