diff --git a/queries/highlights.scm b/queries/highlights.scm index 0a1245a28..060eeb094 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -7,6 +7,15 @@ (constant name: (identifier) @constant) +; Modules +(module) @module +(import alias: (identifier) @module) +(remote_type_identifier module: (identifier) @module) +((function_call function: (field_access record: (identifier) @module)) + (#is-not? local)) +((binary_expression "|>" (field_access record: (identifier) @module)) + (#is-not? local)) + ; Functions (function name: (identifier) @function) diff --git a/queries/locals.scm b/queries/locals.scm new file mode 100644 index 000000000..e4e4900a4 --- /dev/null +++ b/queries/locals.scm @@ -0,0 +1,13 @@ +; Scopes +(function_body) @local.scope + +; Definitions +(let pattern: (identifier) @local.definition) +(function_parameter name: (identifier) @local.definition) +(list_pattern (identifier) @local.definition) +(list_pattern assign: (identifier) @local.definition) +(tuple_pattern (identifier) @local.definition) +(record_pattern_argument pattern: (identifier) @local.definition) + +; References +(identifier) @local.reference diff --git a/test/highlight/functions.gleam b/test/highlight/functions.gleam index 44f825d3a..c3d49d0f0 100644 --- a/test/highlight/functions.gleam +++ b/test/highlight/functions.gleam @@ -3,11 +3,11 @@ pub fn replace( // <- keyword // ^ function // ^ punctuation.bracket - in string: String, + in original: String, // <- property // ^ variable.parameter - // ^ type - // ^ punctuation.delimeter + // ^ type + // ^ punctuation.delimeter each pattern: String, // <- property // ^ variable.parameter @@ -22,15 +22,15 @@ pub fn replace( // <- punctuation.delimeter // ^ type // ^ punctuation.bracket - string.replace(in: string, each: pattern, with: replacement) - // <- variable - // ^ property - // ^ property - // ^ variable - // ^ property - // ^ variable - // ^ property - // ^ variable + string.replace(in: original, each: pattern, with: replacement) + // <- module + // ^ property + // ^ property + // ^ variable.parameter + // ^ property + // ^ variable.parameter + // ^ property + // ^ variable.parameter } fn trial(uri) { diff --git a/test/highlight/modules.gleam b/test/highlight/modules.gleam new file mode 100644 index 000000000..034c99de5 --- /dev/null +++ b/test/highlight/modules.gleam @@ -0,0 +1,40 @@ +import gleam/io +// ^ module +// ^ module +// ^ module +import animal/cat as kitty +// ^ module +// ^ module + +pub fn main() { + io.println("hello world") + // <- module +} + +type MyType { + MyType(func: fn() -> Int) +} + +fn record_access_case(param: MyType) { + let binding = MyType(func: fn() { 42 }) + let _ = binding.func() + // ^ variable + let _ = param.func() + // ^ variable.parameter +} + +fn pipe_operator_case(string: String) { + string + // <- variable.parameter + |> iodata.new + // ^ module + |> iodata.reverse + // ^ module +} + +fn remote_type_case() { + gleam.Ok(1) + // <- module + // ^ punctuation.delimeter + // ^ type +}