Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 49 additions & 5 deletions languages/emmyluadoc/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,44 +1,72 @@
; Highlights query for EmmyLuaDoc

; Comment Prefix
(comment_prefix) @comment

; Annotation Keywords
"@class" @keyword

"@interface" @keyword

"@field" @keyword

"@type" @keyword

"@param" @keyword

"@return" @keyword

"@generic" @keyword

"@overload" @keyword

"@see" @keyword

"@alias" @keyword

"@enum" @keyword

"@module" @keyword

"@cast" @keyword

"@version" @keyword

"@diagnostic" @keyword

"@operator" @keyword

"@namespace" @keyword

"@using" @keyword

"@language" @keyword

"@attribute" @keyword

"@as" @keyword

; Other/unknown annotations
(tag_name) @keyword

; Special annotation nodes
(deprecated_annotation) @keyword

(private_annotation) @keyword

(protected_annotation) @keyword

(public_annotation) @keyword

(package_annotation) @keyword

(async_annotation) @keyword

(nodiscard_annotation) @keyword

(meta_annotation) @keyword

(readonly_annotation) @keyword

(export_annotation) @keyword

; Visibility modifiers
Expand Down Expand Up @@ -71,7 +99,8 @@

; Built-in types
((identifier) @type.builtin
(#match? @type.builtin "^(string|number|integer|boolean|table|function|thread|userdata|nil|any|unknown|self)$"))
(#match? @type.builtin
"^(string|number|integer|boolean|table|function|thread|userdata|nil|any|unknown|self)$"))

; Class definitions
(class_annotation
Expand Down Expand Up @@ -127,19 +156,34 @@
; Operators
[
"call"
"add" "sub" "mul" "div" "mod" "pow"
"add"
"sub"
"mul"
"div"
"mod"
"pow"
"concat"
"len"
"eq" "lt" "le"
"eq"
"lt"
"le"
"unm"
"bnot" "band" "bor" "bxor" "shl" "shr"
"bnot"
"band"
"bor"
"bxor"
"shl"
"shr"
"index"
] @operator

; Literals
(string) @string

(number) @number

(boolean) @boolean

"nil" @constant.builtin

; Template types
Expand Down
11 changes: 8 additions & 3 deletions languages/lua/brackets.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
("[" @open "]" @close)
("{" @open "}" @close)
("(" @open ")" @close)
("[" @open
"]" @close)

("{" @open
"}" @close)

("(" @open
")" @close)
17 changes: 7 additions & 10 deletions languages/lua/embedding.scm
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
(
(comment)* @context
.
(function_declaration
"function" @name
name: (_) @name
(comment)* @collapse
body: (block) @collapse
) @item
)
((comment)* @context
.
(function_declaration
"function" @name
name: (_) @name
(comment)* @collapse
body: (block) @collapse) @item)
92 changes: 46 additions & 46 deletions languages/lua/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
;; Keywords

; Keywords
[
"do"
"else"
Expand All @@ -19,12 +18,11 @@
(break_statement)
] @keyword

;; Operators

; Operators
[
"and"
"not"
"or"
"and"
"not"
"or"
] @keyword.operator

[
Expand All @@ -51,42 +49,41 @@
".."
] @operator

;; Punctuations

; Punctuations
[
";"
":"
","
"."
] @punctuation.delimiter

;; Brackets

; Brackets
[
"("
")"
"["
"]"
"{"
"}"
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket

;; Variables

; Variables
(identifier) @variable

((identifier) @variable.special
(#eq? @variable.special "self"))
(#eq? @variable.special "self"))

(variable_list
attribute: (attribute
(["<" ">"] @punctuation.bracket
attribute: (attribute
([
"<"
">"
] @punctuation.bracket
(identifier) @attribute)))

;; Constants

; Constants
((identifier) @constant
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
(#match? @constant "^[A-Z][A-Z_0-9]*$"))

(vararg_expression) @constant

Expand All @@ -97,52 +94,55 @@
(true)
] @boolean

;; Tables
; Tables
(field
name: (identifier) @property)

(field name: (identifier) @property)

(dot_index_expression field: (identifier) @property)
(dot_index_expression
field: (identifier) @property)

(table_constructor
[
"{"
"}"
] @constructor)
[
"{"
"}"
] @constructor)

;; Functions

(parameters (identifier) @parameter)
; Functions
(parameters
(identifier) @parameter)

(function_call
name: [
(identifier) @function
(dot_index_expression field: (identifier) @function)
(dot_index_expression
field: (identifier) @function)
])

(function_declaration
name: [
(identifier) @function.definition
(dot_index_expression field: (identifier) @function.definition)
(dot_index_expression
field: (identifier) @function.definition)
])

(method_index_expression method: (identifier) @function.method)
(method_index_expression
method: (identifier) @function.method)

(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"))

;; Others
; 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"))

; Others
(comment) @comment

(hash_bang_line) @preproc

(number) @number

(string) @string

(escape_sequence) @string.escape
43 changes: 32 additions & 11 deletions languages/lua/indents.scm
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
(if_statement "end" @end) @indent
(do_statement "end" @end) @indent
(while_statement "end" @end) @indent
(for_statement "end" @end) @indent
(repeat_statement "until" @end) @indent
(function_declaration "end" @end) @indent
(function_definition "end" @end) @indent

(_ "[" "]" @end) @indent
(_ "{" "}" @end) @indent
(_ "(" ")" @end) @indent
(if_statement
"end" @end) @indent

(do_statement
"end" @end) @indent

(while_statement
"end" @end) @indent

(for_statement
"end" @end) @indent

(repeat_statement
"until" @end) @indent

(function_declaration
"end" @end) @indent

(function_definition
"end" @end) @indent

(_
"["
"]" @end) @indent

(_
"{"
"}" @end) @indent

(_
"("
")" @end) @indent
19 changes: 11 additions & 8 deletions languages/lua/injections.scm
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
;; Injections for Lua code

;; LuaCats Doc comments injection
; Injections for Lua code
; LuaCats Doc comments injection
(((comment) @_emmyluadoc_comment
(#match? @_emmyluadoc_comment "^---")) @injection.content
(#set! injection.language "emmyluadoc"))

;; Add support for TODO, FIXME, HACK, etc with the "comment" extension
; Add support for TODO, FIXME, HACK, etc with the "comment" extension
((comment) @injection.content
(#set! injection.language "comment"))

;; LuaJIT FFI C code injection
; LuaJIT FFI C code injection
((function_call
name: [
(identifier) @_cdef_identifier
(_ _ (identifier) @_cdef_identifier)
(_
_
(identifier) @_cdef_identifier)
]
arguments: (arguments (string content: _ @injection.content
(#set! injection.language "c"))))
arguments: (arguments
(string
content: _ @injection.content
(#set! injection.language "c"))))
(#eq? @_cdef_identifier "cdef"))
4 changes: 2 additions & 2 deletions languages/lua/outline.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(function_declaration
"function" @context
name: (_) @name) @item
"function" @context
name: (_) @name) @item
Loading