Skip to content
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

Merged
merged 26 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
20eb148
Dart support; initial commit
agent3bood Feb 1, 2024
acd6bf2
cleanup
agent3bood Feb 1, 2024
8ec9d22
cleanup
agent3bood Feb 1, 2024
a7462f6
cleanup
agent3bood Feb 1, 2024
b8a1416
Handle multiple headers
agent3bood Feb 2, 2024
b1f017e
Merge remote-tracking branch 'origin/main' into dert-supprt
agent3bood Feb 2, 2024
bc1657a
Merge remote-tracking branch 'origin/main' into dert-supprt
agent3bood Feb 5, 2024
1a34dcf
lsp header parsing
agent3bood Feb 5, 2024
6acf712
cleanup
agent3bood Feb 5, 2024
f00f173
spelling
agent3bood Feb 5, 2024
d6dac9c
Merge remote-tracking branch 'origin/main' into dert-supprt
agent3bood Feb 6, 2024
5975306
fork tree-sitter-dart
agent3bood Feb 6, 2024
e802dc1
Cargo.lock
agent3bood Feb 6, 2024
a0520b6
tree-sitter-dart version
agent3bood Feb 6, 2024
e844351
tree-sitter-dart version
agent3bood Feb 6, 2024
2f6c878
Merge remote-tracking branch 'origin/main' into dert-supprt
agent3bood Feb 8, 2024
1926a67
refactor new syntax
agent3bood Feb 8, 2024
9f5e99d
Merge branch 'main' of github.com:agent3bood/zed into dert-supprt
agent3bood Feb 8, 2024
4e9518e
dart config
agent3bood Feb 8, 2024
f4e1cd0
Merge branch 'main' of github.com:agent3bood/zed into dert-supprt
agent3bood Feb 10, 2024
adc0864
Merge branch 'main' of github.com:agent3bood/zed into dert-supprt
agent3bood Feb 12, 2024
c14c08b
ast syntax
agent3bood Feb 12, 2024
86ecf53
Merge branch 'main' of github.com:agent3bood/zed into dert-supprt
agent3bood Feb 12, 2024
a7b9820
syntax
agent3bood Feb 13, 2024
166c039
Merge branch 'main' of github.com:agent3bood/zed into dert-supprt
agent3bood Feb 16, 2024
1dcff6d
Merge branch 'main' of github.com:agent3bood/zed into dert-supprt
agent3bood Feb 19, 2024
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
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ tree-sitter-clojure = { git = "https://github.com/prcastro/tree-sitter-clojure",
tree-sitter-c-sharp = { git = "https://github.com/tree-sitter/tree-sitter-c-sharp", rev = "dd5e59721a5f8dae34604060833902b882023aaf" }
tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "f44509141e7e483323d2ec178f2d2e6c0fc041c1" }
tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" }
tree-sitter-dart = { git = "https://github.com/agent3bood/tree-sitter-dart", rev = "48934e3bf757a9b78f17bdfaa3e2b4284656fdc7" }
Copy link

@HenriqueNas HenriqueNas Feb 12, 2024

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?

Copy link
Contributor Author

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.

tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "a2861e88a730287a60c11ea9299c033c7d076e30" }
tree-sitter-elm = { git = "https://github.com/elm-tooling/tree-sitter-elm", rev = "692c50c0b961364c40299e73c1306aecb5d20f40" }
tree-sitter-embedded-template = "0.20.0"
Expand Down
1 change: 1 addition & 0 deletions crates/zed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ tree-sitter-c.workspace = true
tree-sitter-clojure.workspace = true
tree-sitter-cpp.workspace = true
tree-sitter-css.workspace = true
tree-sitter-dart.workspace = true
tree-sitter-elixir.workspace = true
tree-sitter-elm.workspace = true
tree-sitter-embedded-template.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/zed/src/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod c;
mod clojure;
mod csharp;
mod css;
mod dart;
mod deno;
mod elixir;
mod elm;
Expand Down Expand Up @@ -117,6 +118,7 @@ pub fn init(
("vue", tree_sitter_vue::language()),
("yaml", tree_sitter_yaml::language()),
("zig", tree_sitter_zig::language()),
("dart", tree_sitter_dart::language()),
]);

let language = |asset_dir_name: &'static str, adapters| {
Expand Down Expand Up @@ -310,6 +312,7 @@ pub fn init(
node_runtime.clone(),
))],
);
language("dart", vec![Arc::new(dart::DartLanguageServer {})]);
}

#[cfg(any(test, feature = "test-support"))]
Expand Down
53 changes: 53 additions & 0 deletions crates/zed/src/languages/dart.rs
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
}
}
6 changes: 6 additions & 0 deletions crates/zed/src/languages/dart/brackets.scm
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)
13 changes: 13 additions & 0 deletions crates/zed/src/languages/dart/config.toml
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"] },
]
221 changes: 221 additions & 0 deletions crates/zed/src/languages/dart/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
(dotted_identifier_list) @string

; Methods
; --------------------
(function_type
name: (identifier) @method)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be function or function.method for us to pick it up.

(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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with these usages of @method.

(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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we give special highlighting @parameter, because in general, we don't have a way of highlighting all of the occurrences of the parameter consistently. Could you remove these parameter ones?


(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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we highlight this group either. Maybe just use keyword for these? Or if you want to allow themes to target them specifically, you could do keyword.include.


; 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing with conditional, repeat, and exception: I think just use keyword. You could add a suffix like keyword.conditional, but we usually don't do that in our queries, so I don't think any themes will target that.


["do" "while" "continue" "for"] @repeat

; Error
(ERROR) @error
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

7 changes: 7 additions & 0 deletions crates/zed/src/languages/dart/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
(if_statement)
(for_statement)
] @indent

(_ "{" "}" @end) @indent
(_ "(" ")" @end) @indent
19 changes: 19 additions & 0 deletions crates/zed/src/languages/dart/outline.scm
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
Loading