Add support for roc lsp and highlighting

main
trivernis 10 months ago
parent 7e3413d5e8
commit 2bd663eb4a
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -2,6 +2,10 @@
command = "biome" command = "biome"
args = ["lsp-proxy"] args = ["lsp-proxy"]
[language-server.roc_lang_server]
command = "roc_lang_server"
args = []
[[language]] [[language]]
name = "typescript" name = "typescript"
language-servers = ["typescript-language-server", "biome"] language-servers = ["typescript-language-server", "biome"]
@ -35,11 +39,23 @@ source = { git = "https://github.com/alexlafroscia/tree-sitter-glimmer", rev = "
[[language]] [[language]]
name = "roc" name = "roc"
language-servers = [] language-servers = ["roc_lang_server"]
auto-format = false auto-format = true
indent = { tab-width = 4, unit = " " } indent = { tab-width = 4, unit = " " }
file-types = ["roc"] file-types = ["roc"]
scope = "source.elm" shebangs = ["roc"]
grammar = "elm" scope = "source.roc"
comment-token = "#" comment-token = "#"
roots = [] roots = []
formatter = { command = "roc", args = ['format', '--stdin', '--stdout'] }
grammar = "roc"
[language.auto-pairs]
'(' = ')'
'{' = '}'
'[' = ']'
'"' = '"'
[[grammar]]
name = "roc"
source = { git = "https://github.com/faldor20/tree-sitter-roc", rev = "381743cd40ee19a9508c6445aacb9085d4bc0cf8" }

@ -0,0 +1,178 @@
;;----comments----
[
(line_comment)
(doc_comment)
] @comment
;;-----Punctuation----
[
"?"
(arrow)
(back_arrow)
(backslash)
] @punctuation.delimiter
[
","
":"
] @punctuation.delimiter
[
"("
")"
"{"
"}"
"["
"]"
] @punctuation.bracket
[
"|"
"&"
(operator)
(wildcard_pattern)
] @operator
[
"if"
"then"
"else"
] @keyword.control.conditional
[
(implements)
(when)
(is)
"as"
(to)
] @keyword.control.roc
;----headers-----
(interface_header(name)@type.interface)
(imports
(imports_entry
(module)@namespace))
(packages
(record_pattern
(record_field_pattern
(field_name)@namespace)))
(app_name) @string
(import_as) @string
[
"app"
"packages"
"imports"
"provides"
"interface"
"exposes"
"expect"
(import_as)
] @keyword.control
;---annotations----
(annotation_type_def
(annotation_pre_colon
(identifier)@function )
(function_type))
(annotation_type_def
(annotation_pre_colon
(identifier)@parameter.definition ))
;----decleration types----
(value_declaration(decl_left
(identifier_pattern
(identifier)@function))(expr_body(anon_fun_expr)))
(value_declaration(decl_left
(identifier_pattern
(identifier) @parameter.definition)))
(backpassing_expr assignee: (identifier_pattern (identifier) @parameter.definition))
;----tags----
(tags_type(apply_type(concrete_type)@constructor))
(tag)@constructor
(opaque_tag)@constructor
;-----builtins----
(variable_expr
(module)@module
(identifier)@constant.builtin.boolean
(#eq? @constant.builtin.boolean "true" )
(#eq? @module "Bool" )
)
(variable_expr
(module)@module
(identifier)@constant.builtin.boolean
(#eq? @constant.builtin.boolean "false" )
(#eq? @module "Bool" )
)
[
"dbg"
] @constant.builtin
;----function invocations ----
(function_call_expr
caller: (variable_expr
(identifier)@function))
(function_call_expr
caller: (field_access_expr (identifier)@function .))
(bin_op_expr (operator "|>")@operator(variable_expr(identifier)@function))
;----function arguments----
(argument_patterns(identifier_pattern
(identifier)@variable.parameter))
(argument_patterns(_(identifier_pattern(identifier)@variable.parameter)))
(argument_patterns(_(_(identifier_pattern(identifier)@variable.parameter))))
(argument_patterns(_(_(_(identifier_pattern(identifier)@variable.parameter)))))
(argument_patterns(_(_(_(_(identifier_pattern(identifier)@variable.parameter))))))
(argument_patterns(_(_(_(_(_(identifier_pattern(identifier)@variable.parameter)))))))
;;----records----
(field_name)@variable.other.member
(record_field_pattern (_(identifier) @variable))
;matches the second identifier and all subsequent ones
(field_access_expr (identifier) @variable.other.member)
;-----consts-----
[
(int)
(uint)
(iint)
(xint)
(natural)
] @constant.numeric.integer
[
(decimal)
(float)
] @constant.numeric.float
(string)@string
(char) @constant.character
(escape_char)@constant.character.escape
;---keep most generic types at bottom for helix---
(module)@namespace
(module)@module
(identifier)@variable
(concrete_type)@type

@ -0,0 +1,126 @@
;;How to write indents:
;;think about the structures that should have indents inside and mark them with indent and extend
;;think about the structures that indicate the end of an indent and mark them with extend.prevent-once
;;find partially complete structures and create speciall rules for them.
;;eg: (ERROR (is))
[
(value_declaration)
(then)
(else)
(when_is_expr)
(when_is_branch)
(record_field_expr)
;(function_call_expr)
; (function_type)
(annotation_type_def)
; (parenthesized_type)
(interface_header)
(expect)
] @indent
[
(value_declaration)
(then)
(else)
(when_is_expr)
(when_is_branch)
(record_field_expr)
;(function_call_expr)
; (function_type)
(annotation_type_def)
(interface_header)
(expect)
; (record_expr)
] @extend
[
(exposes)
(imports)
(provides)
(requires)
]@indent
(ERROR "expect")@indent @extend
[
"["
"{"
"("]@indent @extend
["}"
"]"
")"]@outdent
[
(record_expr)
(list_expr)
(tuple_expr)
(record_pattern)
(list_pattern)
(tuple_pattern)
(tuple_type)
(parenthesized_type)
(parenthesized_expr)
(paren_pattern)
]@indent
;;starting a when is expression
(ERROR (is)@indent @extend)
;;starting a record_field
(ERROR ":"@indent @extend)
;starting a type annotation
(ERROR "(")@indent @extend
;starting a variable declaration
(ERROR "=")@indent @extend
;;It's annoying when pipelines automatically dedent this pervents that
(expr_body
result: (bin_op_expr)
)@extend
;this automatically dedents, this may be more annying than helpful when writing pipelines
(expr_body
result: (_)
) @extend.prevent-once
;;If we maybe don't want all expressions causing dedents
; (value_declaration
; (expr_body
; result: (_)
; ) @extend.prevent-once
; )
; (then
; (expr_body
; result: (_)
; ) @extend.prevent-once
; )
; (else
; (expr_body
; result: (_)
; ) @extend.prevent-once
; )
; (when_is_branch
; (expr_body
; result: (_)
; )@extend.prevent-once
; )
; (expect
; (expr_body
; result: (_)
; )@extend.prevent-once
; )
; (record_field_expr
; (expr_body
; result: (_)
; ) @extend.prevent-once
; )
; (record_field_expr
; (expr_body
; result: (_)
; ) @extend.prevent-once
; )

@ -0,0 +1,21 @@
(expr_body) @local.scope
(value_declaration(decl_left
(identifier_pattern
(identifier)@local.definition)))
;;This would make parameters that are functions not get highlighted as functions but as parameters.. not sure if that's something we ever want
; (argument_patterns(identifier_pattern
; (identifier)@local.definition))
; (argument_patterns(long_identifier)@local.definition)
(exposes_list(ident)@local.reference)
(opaque_type_def(apply_type(concrete_type)@local.definition))
(alias_type_def(apply_type(concrete_type)@local.definition))
(exposes(ident)@local.reference)
(identifier)@local.reference
(tag_expr(tag))@local.reference

@ -0,0 +1,12 @@
; Function calls
(function_call_expr
caller: (variable_expr
(identifier)@name ))@reference.call
(function_call_expr
caller: (field_access_expr (identifier)@name .))@reference.call
; Function definitions
(value_declaration(decl_left
(identifier_pattern
(identifier)@name))(expr_body(anon_fun_expr)))@definition.function

@ -0,0 +1,38 @@
(anon_fun_expr
(expr_body) @function.inside
) @function.around
(argument_patterns
((_) @parameter.inside . ","? @parameter.around) @parameter.around
)
(function_type
((_) @parameter.inside . ","? @parameter.around) @parameter.around(#not-eq? @parameter.inside "->")
)
(function_call_expr
.
(_)
(parenthesized_expr (expr_body) @parameter.inside) @parameter.around
)
(function_call_expr
.
(_) ((_) @parameter.inside) @parameter.around
)
[
(annotation_type_def ) @class.inside
(alias_type_def ) @class.inside
(opaque_type_def ) @class.inside
] @class.around
(apply_type_arg) @parameter.inside
(expect
(expr_body) @test.inside
) @test.around
(line_comment) @comment.around
(doc_comment) @comment.around
Loading…
Cancel
Save