Skip to content

Commit

Permalink
Add dart lsp config and queries
Browse files Browse the repository at this point in the history
The setup requires that dart be in the users path, such as:
```
export PATH="$HOME/Android/flutter/bin/cache/dart-sdk/bin/:$PATH"
```

Refactor the dart highlights
  • Loading branch information
flukejones committed Dec 12, 2021
1 parent 3307f44 commit 4c1d9a0
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@
path = helix-syntax/languages/tree-sitter-llvm
url = https://github.com/benwilliamgraham/tree-sitter-llvm
shallow = true
[submodule "helix-syntax/languages/tree-sitter-dart"]
path = helix-syntax/languages/tree-sitter-dart
url = https://github.com/UserNobody14/tree-sitter-dart.git
shallow = true
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-dart
Submodule tree-sitter-dart added at 6a2537
10 changes: 10 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,13 @@ roots = []
file-types = ["ll"]
comment-token = ";"
indent = { tab-width = 2, unit = " " }

[[language]]
name = "dart"
scope = "source.dart"
file-types = ["dart"]
roots = ["pubspec.yaml"]
auto-format = true
comment-token = "//"
language-server = { command = "dart", args = ["language-server", "--client-id=helix"] }
indent = { tab-width = 2, unit = " " }
239 changes: 239 additions & 0 deletions runtime/queries/dart/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
(dotted_identifier_list) @string

; Methods
; --------------------
(super) @function

; TODO: add method/call_expression to grammar and
; distinguish method call from variable access
(function_expression_body (identifier) @function)
; ((identifier)(selector (argument_part)) @function)

; NOTE: This query is a bit of a work around for the fact that the dart grammar doesn't
; specifically identify a node as a function call
(((identifier) @function (#match? @function "^_?[a-z]"))
. (selector . (argument_part))) @function

; Annotations
; --------------------
(annotation
name: (identifier) @attribute)
(marker_annotation
name: (identifier) @attribute)

; Types
; --------------------
(class_definition
name: (identifier) @type)
(constructor_signature
name: (identifier) @type)
(scoped_identifier
scope: (identifier) @type)
(function_signature
name: (identifier) @method)
(getter_signature
(identifier) @method)
(setter_signature
name: (identifier) @method)
(enum_declaration
name: (identifier) @type)
(enum_constant
name: (identifier) @type)
(void_type) @type

((scoped_identifier
scope: (identifier) @type
name: (identifier) @type)
(#match? @type "^[a-zA-Z]"))

(type_identifier) @type

; Variables
; --------------------
((identifier) @type
(#match? @type "^_?[A-Z].*[a-z]")) ; catch Classes or IClasses not CLASSES

("Function" @type)

; properties
(unconditional_assignable_selector
(identifier) @variable.other.member)

(conditional_assignable_selector
(identifier) @variable.other.member)

; assignments
;(assignment_expression (identifier) @variable)
;(assignment_expression
; left: (assignable_expression) @variable)

(this) @variable.builtin
(super) @variable.builtin

; Parameters
; --------------------
(formal_parameter
name: (identifier) @variable.parameter)

(named_argument
(label (identifier) @variable.parameter))

; Literals
; --------------------
[
(hex_integer_literal)
(decimal_integer_literal)
(decimal_floating_point_literal)
;(octal_integer_literal)
;(hex_floating_point_literal)
] @constant.numeric.integer

(symbol_literal) @symbol
(string_literal) @string

[
(null_literal)
] @constant.builtin

[
(true)
(false)
] @constant.builtin.boolean

(documentation_comment) @comment
(comment) @comment

; Operators and Tokens
; --------------------
(template_substitution
"$" @punctuation.special
"{" @punctuation.special
"}" @punctuation.special) @embedded

(template_substitution
"$" @punctuation.special
(identifier_dollar_escaped) @variable
) @embedded

(escape_sequence) @string.escape

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

[
";"
"."
","
"?."
] @punctuation.delimiter

; Operators
;---------------------
; Seems to be restricted. Basic ops are not available?
[
"@"
"=>"
".."
"??"
"=="
"?"
":"
"&&"
"%"
"<"
">"
"="
">="
"<="
"||"
(multiplicative_operator)
(increment_operator)
(is_operator)
(prefix_operator)
(equality_operator)
(additive_operator)
] @operator

; Keywords
; --------------------
["if" "else" "switch" "default"] @keyword.control.conditional
["import" "library" "export"] @keyword.control.import
["do" "while" "continue" "for"] @keyword.control.repeat
["return" "yield"] @keyword.control.return
["in" "is"] @keyword.operator

[
"try"
"throw"
"catch"
"finally"
(break_statement)
] @keyword.control.exception

; Reserved words (cannot be used as identifiers)
[
; TODO:
; "rethrow" cannot be targeted at all and seems to be an invisible node
; TODO:
; the assert keyword cannot be specifically targeted
; because the grammar selects the whole node or the content
; of the assertion not just the keyword
; assert
(case_builtin)
"late"
"required"
"extension"
"on"
"class"
"enum"
"extends"
"in"
"is"
"new"
"super"
"with"
] @keyword

; Built in identifiers:
[
"Function"
"abstract"
"as"
"async"
"async*"
"sync*"
"await"
"covariant"
"deferred"
"dynamic"
"external"
"factory"
"get"
"implements"
"interface"
"library"
"operator"
"mixin"
"part"
"set"
"show"
"static"
"typedef"
"var"
] @keyword

((identifier) @variable.builtin
(#vim-match? @variable.builtin "^(abstract|as|covariant|deferred|dynamic|export|external|factory|Function|get|implements|import|interface|library|operator|mixin|part|set|static|typedef)$"))


; Error
(ERROR) @error

0 comments on commit 4c1d9a0

Please # to comment.