diff --git a/Cargo.lock b/Cargo.lock index b7f5255..885c7e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1289,6 +1289,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-bigint" version = "0.4.3" @@ -1362,6 +1372,12 @@ version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking" version = "2.0.0" @@ -1733,6 +1749,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook" version = "0.3.14" @@ -1920,6 +1945,15 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + [[package]] name = "time" version = "0.1.44" @@ -2078,11 +2112,37 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", ] [[package]] @@ -2130,6 +2190,7 @@ dependencies = [ "tower", "tower-lsp", "tower-test", + "tracing-subscriber", "tremor-script", ] @@ -2254,6 +2315,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "value-bag" version = "1.0.0-alpha.9" diff --git a/Cargo.toml b/Cargo.toml index c818356..631ef2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ tremor-script = { version = "0.13.0-rc.11", features = [ "arena-delete", "allow-non-simd", ] } +tracing-subscriber="0.3.16" [dev-dependencies] tower-test = "0.4.0" diff --git a/src/backend.rs b/src/backend.rs index 4638a17..5fbdab8 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -227,6 +227,7 @@ impl LanguageServer for Backend { async fn initialized(&self, _: InitializedParams) { file_dbg("initialized", "initialized"); + // TODO check this from clients //self.client.show_message(MessageType::Info, "Initialized Trill!").await; self.client @@ -357,6 +358,7 @@ pub(crate) fn file_dbg(name: &str, content: &str) { #[cfg(test)] mod tests { + use async_std::prelude::{FutureExt, StreamExt}; use serde_json::json; use tower::Service; use tower_lsp::jsonrpc::{Id, Request}; @@ -405,4 +407,76 @@ mod tests { ); Ok(()) } + + #[async_std::test] + async fn warning_class() { + tracing_subscriber::fmt::init(); + + let lang = language::lookup("tremor-deploy").unwrap(); + let (mut service, mut socket) = LspService::new(|client| Backend::new(client, lang)); + + let join_handle = async_std::task::spawn(async move { + while let Some(x) = socket.next().await { + if x.method() == "textDocument/publishDiagnostics" { + let params = x.params(); + + if let Some(params) = params { + let message = params.get("diagnostics").unwrap().as_array().unwrap()[0] + .get("message") + .unwrap() + .as_str() + .unwrap() + .to_string(); + + return Some(message); + } + } + } + + return None; + }); + + let initialize_req = Request::build("initialize") + .params(json!({"capabilities":{ + "textDocument": { + "synchronization": { + "dynamicRegistration": true, + } + }}})) + .id(1) + .finish(); + + let _initialize_res = service + .call(initialize_req) + .await + .expect("Expect request to be executed"); + + let initialized_req = Request::build("initialized").params(json!({})).finish(); + let _initialized_res = service + .call(initialized_req) + .await + .expect("Expect request to be executed"); + + let req = Request::build("textDocument/didOpen") + .params(json!({"textDocument": { + "uri": format!("file://{}/{}", env!("CARGO_MANIFEST_DIR"), "tests/warning_class.tremor"), + "languageId": "tremor-deploy", + "version": 1, + "text": "" + }})) + .finish(); + let _res = service + .call(req) + .await + .expect("Expect request to be executed"); + + let result = join_handle.timeout(std::time::Duration::from_secs(5)).await; + + assert_eq!( + result, + Ok(Some( + "consistency: const's are canonically written in UPPER_CASE".to_string() + )) + ); + } } diff --git a/src/lsp_utils.rs b/src/lsp_utils.rs index 193401d..2c16e33 100644 --- a/src/lsp_utils.rs +++ b/src/lsp_utils.rs @@ -36,14 +36,9 @@ pub(crate) fn get_token(tokens: &[language::TokenSpan], position: Position) -> O let line = position.line as usize; let column = position.character as usize; - //file_dbg("get_token_location_line", &location.line.to_string()); - //file_dbg("get_token_location_column", &location.column.to_string()); - let mut token = None; for (i, t) in tokens.iter().enumerate() { if t.span.end().line() == line && t.span.end().column() > column { - //file_dbg("get_token_span_end", &token.span.end.line.to_string()); - //file_dbg("get_token_location_end", &location.line.to_string()); file_dbg("get_token_t_value", &t.value.to_string()); token = match t.value { @@ -87,6 +82,6 @@ pub(crate) fn get_token(tokens: &[language::TokenSpan], position: Position) -> O break; } } - //file_dbg("get_token_return", &token.clone().unwrap_or_default()); + token } diff --git a/tests/warning_class.tremor b/tests/warning_class.tremor new file mode 100644 index 0000000..0bfe89d --- /dev/null +++ b/tests/warning_class.tremor @@ -0,0 +1,11 @@ +define flow test +flow + define pipeline test_pline + pipeline + define script test_scr + script + const a = ""; + end + end + +end \ No newline at end of file