-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Dart support #7220
Dart support #7220
Changes from 22 commits
20eb148
acd6bf2
8ec9d22
a7462f6
b8a1416
b1f017e
bc1657a
1a34dcf
6acf712
f00f173
d6dac9c
5975306
e802dc1
a0520b6
e844351
2f6c878
1926a67
9f5e99d
4e9518e
f4e1cd0
adc0864
c14c08b
86ecf53
a7b9820
166c039
1dcff6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use anyhow::{anyhow, Result}; | ||
use async_trait::async_trait; | ||
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate}; | ||
use lsp::LanguageServerBinary; | ||
use std::{any::Any, path::PathBuf}; | ||
|
||
pub struct DartLanguageServer; | ||
|
||
#[async_trait] | ||
impl LspAdapter for DartLanguageServer { | ||
fn name(&self) -> LanguageServerName { | ||
LanguageServerName("dart".into()) | ||
} | ||
|
||
fn short_name(&self) -> &'static str { | ||
"dart" | ||
} | ||
|
||
async fn fetch_latest_server_version( | ||
&self, | ||
_: &dyn LspAdapterDelegate, | ||
) -> Result<Box<dyn 'static + Send + Any>> { | ||
Ok(Box::new(())) | ||
} | ||
|
||
async fn fetch_server_binary( | ||
&self, | ||
_: Box<dyn 'static + Send + Any>, | ||
_: PathBuf, | ||
_: &dyn LspAdapterDelegate, | ||
) -> Result<LanguageServerBinary> { | ||
Err(anyhow!("dart must me installed from dart.dev/get-dart")) | ||
} | ||
|
||
async fn cached_server_binary( | ||
&self, | ||
_: PathBuf, | ||
_: &dyn LspAdapterDelegate, | ||
) -> Option<LanguageServerBinary> { | ||
Some(LanguageServerBinary { | ||
path: "dart".into(), | ||
arguments: vec!["language-server".into(), "--protocol=lsp".into()], | ||
}) | ||
} | ||
|
||
fn can_be_reinstalled(&self) -> bool { | ||
false | ||
} | ||
|
||
async fn installation_test_binary(&self, _: PathBuf) -> Option<LanguageServerBinary> { | ||
None | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
("(" @open ")" @close) | ||
("[" @open "]" @close) | ||
("{" @open "}" @close) | ||
("<" @open ">" @close) | ||
("\"" @open "\"" @close) | ||
("'" @open "'" @close) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name = "Dart" | ||
grammar = "dart" | ||
path_suffixes = ["dart"] | ||
line_comments = ["// "] | ||
autoclose_before = ";:.,=}])>" | ||
brackets = [ | ||
{ start = "{", end = "}", close = true, newline = true }, | ||
{ start = "[", end = "]", close = true, newline = true }, | ||
{ start = "(", end = ")", close = true, newline = true }, | ||
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] }, | ||
{ start = "'", end = "'", close = true, newline = false, not_in = ["string"] }, | ||
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] }, | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
(dotted_identifier_list) @string | ||
|
||
; Methods | ||
; -------------------- | ||
(function_type | ||
name: (identifier) @method) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to be |
||
(super) @function | ||
|
||
; Annotations | ||
; -------------------- | ||
(annotation | ||
name: (identifier) @attribute) | ||
|
||
; Operators and Tokens | ||
; -------------------- | ||
(template_substitution | ||
"$" @punctuation.special | ||
"{" @punctuation.special | ||
"}" @punctuation.special | ||
) @none | ||
|
||
(template_substitution | ||
"$" @punctuation.special | ||
(identifier_dollar_escaped) @variable | ||
) @none | ||
|
||
(escape_sequence) @string.escape | ||
|
||
[ | ||
"@" | ||
"=>" | ||
".." | ||
"??" | ||
"==" | ||
"?" | ||
":" | ||
"&&" | ||
"%" | ||
"<" | ||
">" | ||
"=" | ||
">=" | ||
"<=" | ||
"||" | ||
(increment_operator) | ||
(is_operator) | ||
(prefix_operator) | ||
(equality_operator) | ||
(additive_operator) | ||
] @operator | ||
|
||
[ | ||
"(" | ||
")" | ||
"[" | ||
"]" | ||
"{" | ||
"}" | ||
] @punctuation.bracket | ||
|
||
; Delimiters | ||
; -------------------- | ||
[ | ||
";" | ||
"." | ||
"," | ||
] @punctuation.delimiter | ||
|
||
; Types | ||
; -------------------- | ||
(class_definition | ||
name: (identifier) @type) | ||
(constructor_signature | ||
name: (identifier) @type) | ||
;; TODO: does not work | ||
;(type_identifier | ||
;(identifier) @type) | ||
(scoped_identifier | ||
scope: (identifier) @type) | ||
(function_signature | ||
name: (identifier) @method) | ||
(getter_signature | ||
(identifier) @method) | ||
(setter_signature | ||
name: (identifier) @method) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with these usages of |
||
(enum_declaration | ||
name: (identifier) @type) | ||
(enum_constant | ||
name: (identifier) @type) | ||
(type_identifier) @type | ||
(void_type) @type | ||
|
||
((scoped_identifier | ||
scope: (identifier) @type | ||
name: (identifier) @type) | ||
(#match? @type "^[a-zA-Z]")) | ||
|
||
(type_identifier) @type | ||
|
||
; Variables | ||
; -------------------- | ||
; var keyword | ||
(inferred_type) @keyword | ||
|
||
(const_builtin) @constant.builtin | ||
(final_builtin) @constant.builtin | ||
|
||
((identifier) @type | ||
(#match? @type "^_?[A-Z]")) | ||
|
||
("Function" @type) | ||
|
||
; properties | ||
; TODO: add method/call_expression to grammar and | ||
; distinguish method call from variable access | ||
(unconditional_assignable_selector | ||
(identifier) @property) | ||
|
||
; assignments | ||
(assignment_expression | ||
left: (assignable_expression) @variable) | ||
|
||
(this) @variable.builtin | ||
|
||
; Parameters | ||
; -------------------- | ||
(formal_parameter | ||
name: (identifier) @parameter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we give special highlighting |
||
|
||
(named_argument | ||
(label (identifier) @parameter)) | ||
|
||
; Literals | ||
; -------------------- | ||
[ | ||
(hex_integer_literal) | ||
(decimal_integer_literal) | ||
(decimal_floating_point_literal) | ||
; TODO: inaccessible nodes | ||
; (octal_integer_literal) | ||
; (hex_floating_point_literal) | ||
] @number | ||
|
||
(symbol_literal) @symbol | ||
(string_literal) @string | ||
(true) @boolean | ||
(false) @boolean | ||
(null_literal) @constant.builtin | ||
|
||
(documentation_comment) @comment | ||
(comment) @comment | ||
|
||
; Keywords | ||
; -------------------- | ||
["import" "library" "export"] @include | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we highlight this group either. Maybe just use |
||
|
||
; Reserved words (cannot be used as identifiers) | ||
; TODO: "rethrow" @keyword | ||
[ | ||
; "assert" | ||
(case_builtin) | ||
"extension" | ||
"on" | ||
"class" | ||
"enum" | ||
"extends" | ||
"in" | ||
"is" | ||
"new" | ||
"return" | ||
"super" | ||
"with" | ||
] @keyword | ||
|
||
|
||
; Built in identifiers: | ||
; alone these are marked as keywords | ||
[ | ||
"abstract" | ||
"as" | ||
"async" | ||
"async*" | ||
"yield" | ||
"sync*" | ||
"await" | ||
"covariant" | ||
"deferred" | ||
"dynamic" | ||
"external" | ||
"factory" | ||
"get" | ||
"implements" | ||
"interface" | ||
"library" | ||
"operator" | ||
"mixin" | ||
"part" | ||
"set" | ||
"show" | ||
"static" | ||
"typedef" | ||
] @keyword | ||
|
||
; when used as an identifier: | ||
((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)$")) | ||
|
||
["if" "else" "switch" "default"] @conditional | ||
|
||
[ | ||
"try" | ||
"throw" | ||
"catch" | ||
"finally" | ||
(break_statement) | ||
] @exception | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing with |
||
|
||
["do" "while" "continue" "for"] @repeat | ||
|
||
; Error | ||
(ERROR) @error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove this? We usually don't highlight errors in our highlight queries, because sometimes there are false positives. Also, I don't think themes target this. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
(if_statement) | ||
(for_statement) | ||
] @indent | ||
|
||
(_ "{" "}" @end) @indent | ||
(_ "(" ")" @end) @indent |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
(class_definition | ||
"class" @context | ||
name: (_) @name) @item | ||
|
||
(function_signature | ||
name: (_) @name) @item | ||
|
||
(getter_signature | ||
"get" @context | ||
name: (_) @name) @item | ||
|
||
(setter_signature | ||
"set" @context | ||
name: (_) @name) @item | ||
|
||
(enum_declaration | ||
"enum" @context | ||
name: (_) @name) @item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this can be merged and released asap !!
but, just for curiosity:
why did you linked your fork of "official" Dart tree-sitter repository instead of it self?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no official package for Dart, the website links to "https://github.com/UserNobody14/tree-sitter-dart", which I forked to fix some issues on it.