From 20eb148b7b43485814e8fcfe24d50a459783f132 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Thu, 1 Feb 2024 18:08:20 +0300 Subject: [PATCH 01/16] Dart support; initial commit --- Cargo.lock | 10 + Cargo.toml | 1 + crates/lsp/src/lsp.rs | 14 +- crates/zed/Cargo.toml | 1 + crates/zed/src/languages.rs | 6 + crates/zed/src/languages/dart.rs | 86 +++++++ crates/zed/src/languages/dart/brackets.scm | 6 + crates/zed/src/languages/dart/config.toml | 12 + crates/zed/src/languages/dart/highlights.scm | 222 +++++++++++++++++++ crates/zed/src/languages/dart/indents.scm | 7 + 10 files changed, 358 insertions(+), 7 deletions(-) create mode 100644 crates/zed/src/languages/dart.rs create mode 100644 crates/zed/src/languages/dart/brackets.scm create mode 100644 crates/zed/src/languages/dart/config.toml create mode 100644 crates/zed/src/languages/dart/highlights.scm create mode 100644 crates/zed/src/languages/dart/indents.scm diff --git a/Cargo.lock b/Cargo.lock index 7b3a5ba6f3c797..dea56910c6efc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8784,6 +8784,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-dart" +version = "0.0.1" +source = "git+https://github.com/UserNobody14/tree-sitter-dart?rev=f71e310a93010863f4b17a2a501ea8e2032c345b#f71e310a93010863f4b17a2a501ea8e2032c345b" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-elixir" version = "0.1.0" @@ -10399,6 +10408,7 @@ dependencies = [ "tree-sitter-c-sharp", "tree-sitter-cpp", "tree-sitter-css", + "tree-sitter-dart", "tree-sitter-elixir", "tree-sitter-elm", "tree-sitter-embedded-template", diff --git a/Cargo.toml b/Cargo.toml index f46d32a53c84b8..86f2dfadfef82f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -139,6 +139,7 @@ tree-sitter-c = "0.20.1" 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/UserNobody14/tree-sitter-dart", rev = "f71e310a93010863f4b17a2a501ea8e2032c345b" } 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" diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index f9cd138217cfed..3731d5eb94cf0e 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -4,7 +4,7 @@ pub use lsp_types::*; use anyhow::{anyhow, Context, Result}; use collections::HashMap; -use futures::{channel::oneshot, io::BufWriter, AsyncRead, AsyncWrite, FutureExt}; +use futures::{channel::oneshot, io::BufWriter, AsyncRead, AsyncWrite, FutureExt, AsyncBufRead}; use gpui::{AppContext, AsyncAppContext, BackgroundExecutor, Task}; use parking_lot::Mutex; use postage::{barrier, prelude::Stream}; @@ -307,7 +307,7 @@ impl LanguageServer { response_handlers: Arc>>>, io_handlers: Arc>>, cx: AsyncAppContext, - ) -> anyhow::Result<()> + ) -> Result<()> where Stdout: AsyncRead + Unpin + Send + 'static, F: FnMut(AnyNotification) + 'static + Send, @@ -378,7 +378,7 @@ impl LanguageServer { } else { warn!( "failed to deserialize LSP message:\n{}", - std::str::from_utf8(&buffer)? + str::from_utf8(&buffer)? ); } @@ -393,7 +393,7 @@ impl LanguageServer { stderr: Stderr, io_handlers: Arc>>, stderr_capture: Arc>>, - ) -> anyhow::Result<()> + ) -> Result<()> where Stderr: AsyncRead + Unpin + Send + 'static, { @@ -430,7 +430,7 @@ impl LanguageServer { output_done_tx: barrier::Sender, response_handlers: Arc>>>, io_handlers: Arc>>, - ) -> anyhow::Result<()> + ) -> Result<()> where Stdin: AsyncWrite + Unpin + Send + 'static, { @@ -626,7 +626,7 @@ impl LanguageServer { let outbound_tx = self.outbound_tx.clone(); let executor = self.executor.clone(); let mut output_done = self.output_done_rx.lock().take().unwrap(); - let shutdown_request = Self::request_internal::( + let shutdown_request = Self::request_internal::( &next_id, &response_handlers, &outbound_tx, @@ -856,7 +856,7 @@ impl LanguageServer { outbound_tx: &channel::Sender, executor: &BackgroundExecutor, params: T::Params, - ) -> impl 'static + Future> + ) -> impl 'static + Future> where T::Result: 'static + Send, { diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index b87b79e2f0e151..004e9f4fa57dd9 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -111,6 +111,7 @@ tree-sitter-c-sharp.workspace = true tree-sitter-c.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 diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index add9f9c1924adc..797845ca43abc8 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -12,6 +12,7 @@ use self::{deno::DenoSettings, elixir::ElixirSettings}; mod c; mod csharp; mod css; +mod dart; mod deno; mod elixir; mod elm; @@ -310,6 +311,11 @@ pub fn init( vec![Arc::new(uiua::UiuaLanguageServer {})], ); language("proto", tree_sitter_proto::language(), vec![]); + language( + "dart", + tree_sitter_dart::language(), + vec![Arc::new(dart::DartLanguageServer {})], + ); if let Ok(children) = std::fs::read_dir(&*PLUGINS_DIR) { for child in children { diff --git a/crates/zed/src/languages/dart.rs b/crates/zed/src/languages/dart.rs new file mode 100644 index 00000000000000..00a5189afc6cec --- /dev/null +++ b/crates/zed/src/languages/dart.rs @@ -0,0 +1,86 @@ +use anyhow::{anyhow, Result}; +use async_trait::async_trait; +use language::{LanguageServerName, LspAdapter, LspAdapterDelegate}; +use lsp::LanguageServerBinary; +use std::{any::Any, path::PathBuf}; +// use util::ResultExt; +use futures::{StreamExt}; + +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> { + Ok(Box::new(())) + } + + async fn fetch_server_binary( + &self, + _: Box, + _: PathBuf, + _: &dyn LspAdapterDelegate, + ) -> Result { + Err(anyhow!("dart must me installed from dart.dev/get-dart")) + } + + async fn cached_server_binary( + &self, + _: PathBuf, + _: &dyn LspAdapterDelegate, + ) -> Option { + // get_cached_server_binary(container_dir).await + + // println!("{:?}", container_dir); + Some(LanguageServerBinary { + path: "dart".into(), + arguments: vec!["language-server".into(), "--protocol=lsp".into()], + }) + // Some(LanguageServerBinary { + // path: "typescript-language-server".into(), + // arguments: vec!["--stdio".into()], + // }) + } + + fn can_be_reinstalled(&self) -> bool { + false + } + + async fn installation_test_binary(&self, _: PathBuf) -> Option { + None + // get_cached_server_binary(container_dir) + // .await + // .map(|mut binary| { + // binary.arguments = vec!["--help".into()]; + // binary + // }) + } +} + +// async fn get_cached_server_binary(container_dir: PathBuf) -> Option { +// (|| async move { +// let mut last = None; +// let mut entries = smol::fs::read_dir(&container_dir).await?; +// while let Some(entry) = entries.next().await { +// last = Some(entry?.path()); +// } +// +// anyhow::Ok(LanguageServerBinary { +// path: last.ok_or_else(|| anyhow!("no cached binary"))?, +// arguments: Default::default(), +// }) +// })() +// .await +// .log_err() +// } + diff --git a/crates/zed/src/languages/dart/brackets.scm b/crates/zed/src/languages/dart/brackets.scm new file mode 100644 index 00000000000000..8d96f95f864cef --- /dev/null +++ b/crates/zed/src/languages/dart/brackets.scm @@ -0,0 +1,6 @@ +("(" @open ")" @close) +("[" @open "]" @close) +("{" @open "}" @close) +("<" @open ">" @close) +("\"" @open "\"" @close) +("'" @open "'" @close) diff --git a/crates/zed/src/languages/dart/config.toml b/crates/zed/src/languages/dart/config.toml new file mode 100644 index 00000000000000..db858cb63510eb --- /dev/null +++ b/crates/zed/src/languages/dart/config.toml @@ -0,0 +1,12 @@ +name = "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"] }, +] diff --git a/crates/zed/src/languages/dart/highlights.scm b/crates/zed/src/languages/dart/highlights.scm new file mode 100644 index 00000000000000..87544af1059a19 --- /dev/null +++ b/crates/zed/src/languages/dart/highlights.scm @@ -0,0 +1,222 @@ +(dotted_identifier_list) @string + +; Methods +; -------------------- +;; TODO: does not work +;(function_type +;name: (identifier) @method) +(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) +(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) + +(named_argument + (label (identifier) @parameter)) + +; Literals +; -------------------- +[ + (hex_integer_literal) + (decimal_integer_literal) + (decimal_floating_point_literal) + ; TODO: inaccessbile 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 + +; 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 + +["do" "while" "continue" "for"] @repeat + +; Error +(ERROR) @error \ No newline at end of file diff --git a/crates/zed/src/languages/dart/indents.scm b/crates/zed/src/languages/dart/indents.scm new file mode 100644 index 00000000000000..3e8210957c732d --- /dev/null +++ b/crates/zed/src/languages/dart/indents.scm @@ -0,0 +1,7 @@ +[ + (if_statement) + (for_statement) +] @indent + +(_ "{" "}" @end) @indent +(_ "(" ")" @end) @indent From acd6bf2f10fa3056879ce6908e1346c8e65eb947 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Thu, 1 Feb 2024 18:17:02 +0300 Subject: [PATCH 02/16] cleanup --- crates/zed/src/languages/dart.rs | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/crates/zed/src/languages/dart.rs b/crates/zed/src/languages/dart.rs index 00a5189afc6cec..ce6a2125a307c4 100644 --- a/crates/zed/src/languages/dart.rs +++ b/crates/zed/src/languages/dart.rs @@ -3,7 +3,6 @@ use async_trait::async_trait; use language::{LanguageServerName, LspAdapter, LspAdapterDelegate}; use lsp::LanguageServerBinary; use std::{any::Any, path::PathBuf}; -// use util::ResultExt; use futures::{StreamExt}; pub struct DartLanguageServer; @@ -39,17 +38,10 @@ impl LspAdapter for DartLanguageServer { _: PathBuf, _: &dyn LspAdapterDelegate, ) -> Option { - // get_cached_server_binary(container_dir).await - - // println!("{:?}", container_dir); Some(LanguageServerBinary { path: "dart".into(), arguments: vec!["language-server".into(), "--protocol=lsp".into()], }) - // Some(LanguageServerBinary { - // path: "typescript-language-server".into(), - // arguments: vec!["--stdio".into()], - // }) } fn can_be_reinstalled(&self) -> bool { @@ -58,29 +50,5 @@ impl LspAdapter for DartLanguageServer { async fn installation_test_binary(&self, _: PathBuf) -> Option { None - // get_cached_server_binary(container_dir) - // .await - // .map(|mut binary| { - // binary.arguments = vec!["--help".into()]; - // binary - // }) } } - -// async fn get_cached_server_binary(container_dir: PathBuf) -> Option { -// (|| async move { -// let mut last = None; -// let mut entries = smol::fs::read_dir(&container_dir).await?; -// while let Some(entry) = entries.next().await { -// last = Some(entry?.path()); -// } -// -// anyhow::Ok(LanguageServerBinary { -// path: last.ok_or_else(|| anyhow!("no cached binary"))?, -// arguments: Default::default(), -// }) -// })() -// .await -// .log_err() -// } - From 8ec9d22d61721bf35e95e23221904c6b0f76b467 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Thu, 1 Feb 2024 20:25:04 +0300 Subject: [PATCH 03/16] cleanup --- crates/zed/src/languages/dart.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/zed/src/languages/dart.rs b/crates/zed/src/languages/dart.rs index ce6a2125a307c4..ba340fc876aa59 100644 --- a/crates/zed/src/languages/dart.rs +++ b/crates/zed/src/languages/dart.rs @@ -3,7 +3,6 @@ use async_trait::async_trait; use language::{LanguageServerName, LspAdapter, LspAdapterDelegate}; use lsp::LanguageServerBinary; use std::{any::Any, path::PathBuf}; -use futures::{StreamExt}; pub struct DartLanguageServer; From a7462f66c529a86682b67d3bc8807ddda9acee81 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Thu, 1 Feb 2024 22:20:08 +0300 Subject: [PATCH 04/16] cleanup --- crates/lsp/src/lsp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index 3731d5eb94cf0e..3326bde00f6385 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -4,7 +4,7 @@ pub use lsp_types::*; use anyhow::{anyhow, Context, Result}; use collections::HashMap; -use futures::{channel::oneshot, io::BufWriter, AsyncRead, AsyncWrite, FutureExt, AsyncBufRead}; +use futures::{channel::oneshot, io::BufWriter, AsyncRead, AsyncWrite, FutureExt}; use gpui::{AppContext, AsyncAppContext, BackgroundExecutor, Task}; use parking_lot::Mutex; use postage::{barrier, prelude::Stream}; From b8a1416a88d123e64c52665b6d0a58abbe1d66d4 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Fri, 2 Feb 2024 12:34:45 +0300 Subject: [PATCH 05/16] Handle multiple headers --- crates/lsp/src/lsp.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index 3326bde00f6385..54f1a0b28c0b0c 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -320,21 +320,26 @@ impl LanguageServer { } }); let mut buffer = Vec::new(); - loop { + 'outer: loop { buffer.clear(); - if stdout.read_until(b'\n', &mut buffer).await? == 0 { - break; - }; - - if stdout.read_until(b'\n', &mut buffer).await? == 0 { - break; - }; + while let Ok(bytes_read) = stdout.read_until(b'\n', &mut buffer).await { + if bytes_read == 0 { + break 'outer; + } + if buffer.ends_with(b"\r\n\r\n") { + break; + } + } let header = std::str::from_utf8(&buffer)?; let message_len: usize = header .strip_prefix(CONTENT_LEN_HEADER) .ok_or_else(|| anyhow!("invalid LSP message header {header:?}"))? + .split_whitespace() + .collect::>() + .get_mut(0) + .ok_or_else(|| anyhow!("invalid LSP message header {header:?}"))? .trim_end() .parse()?; From 1a34dcf55c843cc3cc77b315ed7a85d5907faa1a Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Mon, 5 Feb 2024 15:48:32 +0300 Subject: [PATCH 06/16] lsp header parsing --- crates/lsp/src/lsp.rs | 66 +++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index 2c7aababd398c8..b2eec4f4c2185b 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -320,50 +320,36 @@ impl LanguageServer { } }); let mut buffer = Vec::new(); - loop { + 'outer: loop { buffer.clear(); - if stdout.read_until(b'\n', &mut buffer).await? == 0 { - break; - }; - - if stdout.read_until(b'\n', &mut buffer).await? == 0 { - break; - }; - - let header = std::str::from_utf8(&buffer)?; - let mut segments = header.lines(); - - let message_len: usize = segments - .next() - .with_context(|| { - format!("unable to find the first line of the LSP message header `{header}`") - })? - .strip_prefix(CONTENT_LEN_HEADER) - .with_context(|| format!("invalid LSP message header `{header}`"))? - .parse() - .with_context(|| { - format!("failed to parse Content-Length of LSP message header: `{header}`") - })?; - - if let Some(second_segment) = segments.next() { - match second_segment { - "" => (), // Header end - header_field => { - if header_field.starts_with("Content-Type:") { - stdout.read_until(b'\n', &mut buffer).await?; - } else { - anyhow::bail!( - "inside `{header}`, expected a Content-Type header field or a header ending CRLF, got `{second_segment:?}`" - ) - } - } + while let Ok(bytes_read) = stdout.read_until(b'\n', &mut buffer).await { + if bytes_read == 0 { + break 'outer; } - } else { - anyhow::bail!( - "unable to find the second line of the LSP message header `{header}`" - ); + if buffer.ends_with(b"\r\n\r\n") { + break; + } + } + + let header = str::from_utf8(&buffer)?; + let mut message_len: Option = None; + while let Some(header_line) = header.lines().next() { + if header_line.starts_with(CONTENT_LEN_HEADER) { + message_len = Some(header_line + .strip_prefix(CONTENT_LEN_HEADER) + .with_context(|| format!("invalid LSP message header `{header}`"))? + .parse::().with_context(|| { + format!("failed to parse Content-Length of LSP message header: `{header}`") + })?); + break; + } + } + if message_len.is_none() { + warn!("missing Content-Length header in LSP message: `{header}`"); + continue; } + let message_len = message_len.unwrap(); buffer.resize(message_len, 0); stdout.read_exact(&mut buffer).await?; From 6acf712f1d299ebbc4072c3a2ee9d1c3d51e9ee6 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Mon, 5 Feb 2024 15:49:47 +0300 Subject: [PATCH 07/16] cleanup --- crates/zed/src/languages/dart/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/zed/src/languages/dart/highlights.scm b/crates/zed/src/languages/dart/highlights.scm index 87544af1059a19..1971197a9f1ba8 100644 --- a/crates/zed/src/languages/dart/highlights.scm +++ b/crates/zed/src/languages/dart/highlights.scm @@ -219,4 +219,4 @@ ["do" "while" "continue" "for"] @repeat ; Error -(ERROR) @error \ No newline at end of file +(ERROR) @error From f00f173016667e615739ac2c73958550a0f95bf8 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Mon, 5 Feb 2024 16:09:05 +0300 Subject: [PATCH 08/16] spelling --- crates/zed/src/languages/dart/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/zed/src/languages/dart/highlights.scm b/crates/zed/src/languages/dart/highlights.scm index 1971197a9f1ba8..ff5242c0ab4252 100644 --- a/crates/zed/src/languages/dart/highlights.scm +++ b/crates/zed/src/languages/dart/highlights.scm @@ -137,7 +137,7 @@ (hex_integer_literal) (decimal_integer_literal) (decimal_floating_point_literal) - ; TODO: inaccessbile nodes + ; TODO: inaccessible nodes ; (octal_integer_literal) ; (hex_floating_point_literal) ] @number From 5975306b31fe97e489e9e2e589bf2a5fd62e2aaa Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Tue, 6 Feb 2024 20:49:34 +0300 Subject: [PATCH 09/16] fork tree-sitter-dart --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4a98bbfd7904d6..3db334a0efd985 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -146,7 +146,7 @@ tree-sitter-c = "0.20.1" 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/UserNobody14/tree-sitter-dart", rev = "f71e310a93010863f4b17a2a501ea8e2032c345b" } +tree-sitter-dart = { git = "https://github.com/agent3bood/tree-sitter-dart", rev = "8fafcc4d5009e8e037b0a3d7552deac5de0e9c85" } 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" From e802dc13392ca0f94efd90399e600e0f342bbf78 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Tue, 6 Feb 2024 20:55:09 +0300 Subject: [PATCH 10/16] Cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 04f02833a45647..ab978c70028b13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8778,7 +8778,7 @@ dependencies = [ [[package]] name = "tree-sitter-dart" version = "0.0.1" -source = "git+https://github.com/UserNobody14/tree-sitter-dart?rev=f71e310a93010863f4b17a2a501ea8e2032c345b#f71e310a93010863f4b17a2a501ea8e2032c345b" +source = "git+https://github.com/agent3bood/tree-sitter-dart?rev=8fafcc4d5009e8e037b0a3d7552deac5de0e9c85#8fafcc4d5009e8e037b0a3d7552deac5de0e9c85" dependencies = [ "cc", "tree-sitter", From a0520b6844f3fae3d05948ceee58ea20fbed6d73 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Tue, 6 Feb 2024 21:14:07 +0300 Subject: [PATCH 11/16] tree-sitter-dart version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab978c70028b13..272705a406f54f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8778,7 +8778,7 @@ dependencies = [ [[package]] name = "tree-sitter-dart" version = "0.0.1" -source = "git+https://github.com/agent3bood/tree-sitter-dart?rev=8fafcc4d5009e8e037b0a3d7552deac5de0e9c85#8fafcc4d5009e8e037b0a3d7552deac5de0e9c85" +source = "git+https://github.com/agent3bood/tree-sitter-dart?rev=6ea0e35bd9c6528eaa78eb9ebc466c96b77d34d4#6ea0e35bd9c6528eaa78eb9ebc466c96b77d34d4" dependencies = [ "cc", "tree-sitter", diff --git a/Cargo.toml b/Cargo.toml index 3db334a0efd985..4a2136cd94cb7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -146,7 +146,7 @@ tree-sitter-c = "0.20.1" 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 = "8fafcc4d5009e8e037b0a3d7552deac5de0e9c85" } +tree-sitter-dart = { git = "https://github.com/agent3bood/tree-sitter-dart", rev = "6ea0e35bd9c6528eaa78eb9ebc466c96b77d34d4" } 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" From e844351f8b4206ca0f28e116d0799cd1e7160c60 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Tue, 6 Feb 2024 21:21:42 +0300 Subject: [PATCH 12/16] tree-sitter-dart version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 272705a406f54f..2b601309c55a82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8778,7 +8778,7 @@ dependencies = [ [[package]] name = "tree-sitter-dart" version = "0.0.1" -source = "git+https://github.com/agent3bood/tree-sitter-dart?rev=6ea0e35bd9c6528eaa78eb9ebc466c96b77d34d4#6ea0e35bd9c6528eaa78eb9ebc466c96b77d34d4" +source = "git+https://github.com/agent3bood/tree-sitter-dart?rev=48934e3bf757a9b78f17bdfaa3e2b4284656fdc7#48934e3bf757a9b78f17bdfaa3e2b4284656fdc7" dependencies = [ "cc", "tree-sitter", diff --git a/Cargo.toml b/Cargo.toml index 4a2136cd94cb7f..8696d3dde3580e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -146,7 +146,7 @@ tree-sitter-c = "0.20.1" 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 = "6ea0e35bd9c6528eaa78eb9ebc466c96b77d34d4" } +tree-sitter-dart = { git = "https://github.com/agent3bood/tree-sitter-dart", rev = "48934e3bf757a9b78f17bdfaa3e2b4284656fdc7" } 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" From 1926a674ccdc9dda2fd733e330ced771c02d5e24 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Thu, 8 Feb 2024 21:45:29 +0300 Subject: [PATCH 13/16] refactor new syntax --- crates/zed/src/languages.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index b8bb0904332250..29539575303ed2 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -114,6 +114,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 = |name: &'static str, adapters| { @@ -290,11 +291,7 @@ pub fn init( language("terraform", vec![]); language("terraform-vars", vec![]); language("hcl", vec![]); - language( - "dart", - tree_sitter_dart::language(), - vec![Arc::new(dart::DartLanguageServer {})], - ); + language("dart", vec![Arc::new(dart::DartLanguageServer {})]); } #[cfg(any(test, feature = "test-support"))] From 4e9518e50b9aa06dcd4995236da717629c57e3af Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Thu, 8 Feb 2024 22:44:39 +0300 Subject: [PATCH 14/16] dart config --- crates/zed/src/languages/dart/config.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/zed/src/languages/dart/config.toml b/crates/zed/src/languages/dart/config.toml index db858cb63510eb..140e4822890e8c 100644 --- a/crates/zed/src/languages/dart/config.toml +++ b/crates/zed/src/languages/dart/config.toml @@ -1,4 +1,5 @@ name = "Dart" +grammar = "dart" path_suffixes = ["dart"] line_comments = ["// "] autoclose_before = ";:.,=}])>" From c14c08bf0f85b377ec16f4f1c2d7907908bdd485 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Mon, 12 Feb 2024 13:16:20 +0300 Subject: [PATCH 15/16] ast syntax --- crates/zed/src/languages/dart/highlights.scm | 5 ++--- crates/zed/src/languages/dart/outline.scm | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 crates/zed/src/languages/dart/outline.scm diff --git a/crates/zed/src/languages/dart/highlights.scm b/crates/zed/src/languages/dart/highlights.scm index ff5242c0ab4252..55fe37b83426d1 100644 --- a/crates/zed/src/languages/dart/highlights.scm +++ b/crates/zed/src/languages/dart/highlights.scm @@ -2,9 +2,8 @@ ; Methods ; -------------------- -;; TODO: does not work -;(function_type -;name: (identifier) @method) +(function_type + name: (identifier) @method) (super) @function ; Annotations diff --git a/crates/zed/src/languages/dart/outline.scm b/crates/zed/src/languages/dart/outline.scm new file mode 100644 index 00000000000000..c8c12eda27ec31 --- /dev/null +++ b/crates/zed/src/languages/dart/outline.scm @@ -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 From a7b9820b02354764e78bfb2b762216fcf0361396 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Tue, 13 Feb 2024 11:10:15 +0300 Subject: [PATCH 16/16] syntax --- crates/zed/src/languages/dart/highlights.scm | 32 ++++++-------------- crates/zed/src/languages/dart/outline.scm | 1 - 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/crates/zed/src/languages/dart/highlights.scm b/crates/zed/src/languages/dart/highlights.scm index 55fe37b83426d1..270b40ec2d19e8 100644 --- a/crates/zed/src/languages/dart/highlights.scm +++ b/crates/zed/src/languages/dart/highlights.scm @@ -3,7 +3,7 @@ ; Methods ; -------------------- (function_type - name: (identifier) @method) + name: (identifier) @function) (super) @function ; Annotations @@ -56,6 +56,8 @@ "]" "{" "}" + "<" + ">" ] @punctuation.bracket ; Delimiters @@ -72,17 +74,14 @@ 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) + name: (identifier) @function) (getter_signature - (identifier) @method) + (identifier) @function) (setter_signature - name: (identifier) @method) + name: (identifier) @function) (enum_declaration name: (identifier) @type) (enum_constant @@ -122,14 +121,6 @@ (this) @variable.builtin -; Parameters -; -------------------- -(formal_parameter - name: (identifier) @parameter) - -(named_argument - (label (identifier) @parameter)) - ; Literals ; -------------------- [ @@ -152,7 +143,7 @@ ; Keywords ; -------------------- -["import" "library" "export"] @include +["import" "library" "export"] @keyword.include ; Reserved words (cannot be used as identifiers) ; TODO: "rethrow" @keyword @@ -205,7 +196,7 @@ ((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 +["if" "else" "switch" "default"] @keyword [ "try" @@ -213,9 +204,6 @@ "catch" "finally" (break_statement) - ] @exception - -["do" "while" "continue" "for"] @repeat + ] @keyword -; Error -(ERROR) @error +["do" "while" "continue" "for"] @keyword diff --git a/crates/zed/src/languages/dart/outline.scm b/crates/zed/src/languages/dart/outline.scm index c8c12eda27ec31..4d6f8c1cb75b69 100644 --- a/crates/zed/src/languages/dart/outline.scm +++ b/crates/zed/src/languages/dart/outline.scm @@ -1,4 +1,3 @@ - (class_definition "class" @context name: (_) @name) @item