From e85d6c37d43be645e4dcf926a23b7b5c551145fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 18:25:22 -0500 Subject: [PATCH 01/13] build(deps): bump anyhow from 1.0.64 to 1.0.65 (#3907) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c8bf13bf..45ae315d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,9 +22,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.64" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9a8f622bcf6ff3df478e9deba3e03e4e04b300f8e6a139e192c05fa3490afc7" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "arc-swap" From 3acdf9fdf910f1bc67262bb587596139272a9458 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 18:26:18 -0500 Subject: [PATCH 02/13] build(deps): bump thiserror from 1.0.34 to 1.0.35 (#3905) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45ae315d..fdfc492a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1118,18 +1118,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1b05ca9d106ba7d2e31a9dab4a64e7be2cce415321966ea3132c49a656e252" +checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8f2591983642de85c921015f3f070c665a197ed69e417af436115e3a1407487" +checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" dependencies = [ "proc-macro2", "quote", From 24501669272b537302ea253c95abf487b0f21ead Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 18:27:04 -0500 Subject: [PATCH 03/13] build(deps): bump tokio from 1.21.0 to 1.21.1 (#3904) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdfc492a..144d63a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1171,9 +1171,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.21.0" +version = "1.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42" +checksum = "0020c875007ad96677dcc890298f4b942882c5d4eb7cc8f439fc3bf813dc9c95" dependencies = [ "autocfg", "bytes", From 674bfec9845c9ea3406b19639151e7882f5310bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 18:28:12 -0500 Subject: [PATCH 04/13] build(deps): bump unicode-width from 0.1.9 to 0.1.10 (#3902) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 144d63a6..c232f080 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1284,9 +1284,9 @@ checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "url" From 26c3c993302f6acd2cc0ed47bc2807d3b7e5e028 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 18:28:38 -0500 Subject: [PATCH 05/13] build(deps): bump unicode-segmentation from 1.9.0 to 1.10.0 (#3903) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- helix-core/Cargo.toml | 2 +- helix-tui/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c232f080..760efaff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1278,9 +1278,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" +checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" [[package]] name = "unicode-width" diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 3ea7235d..c63059a2 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -20,7 +20,7 @@ helix-loader = { version = "0.6", path = "../helix-loader" } ropey = { version = "1.5", default-features = false, features = ["simd"] } smallvec = "1.9" smartstring = "1.0.1" -unicode-segmentation = "1.9" +unicode-segmentation = "1.10" unicode-width = "0.1" unicode-general-category = "0.5" # slab = "0.4.2" diff --git a/helix-tui/Cargo.toml b/helix-tui/Cargo.toml index effad198..b220c64f 100644 --- a/helix-tui/Cargo.toml +++ b/helix-tui/Cargo.toml @@ -18,7 +18,7 @@ default = ["crossterm"] [dependencies] bitflags = "1.3" cassowary = "0.3" -unicode-segmentation = "1.9" +unicode-segmentation = "1.10" crossterm = { version = "0.25", optional = true } serde = { version = "1", "optional" = true, features = ["derive"]} helix-view = { version = "0.6", path = "../helix-view", features = ["term"] } From 947ff63e6d31d7926aff83ebb328e03a10deceb9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 18:29:00 -0500 Subject: [PATCH 06/13] build(deps): bump textwrap from 0.15.0 to 0.15.1 (#3906) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- helix-core/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 760efaff..a26c92e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1107,9 +1107,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" dependencies = [ "smawk", "unicode-linebreak", diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index c63059a2..0ec58af9 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -42,7 +42,7 @@ encoding_rs = "0.8" chrono = { version = "0.4", default-features = false, features = ["alloc", "std"] } etcetera = "0.4" -textwrap = "0.15.0" +textwrap = "0.15.1" [dev-dependencies] quickcheck = { version = "1", default-features = false } From 8988c1ecc757bb4d1c2372d8b8a78bae6a1fd85e Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 20 Sep 2022 02:08:58 -0500 Subject: [PATCH 07/13] Re-sort diagnostics after transaction transform (#3895) Applying document-change transactions to diagnostic ranges is not stable with respect to the ordering of diagnostics. This can cause diagnostics to become temporarily unordered with some edits to a document, which can eventually break some invariants/assumptions in syntax::merge. With this change, Document::diagnostics are always sorted. --- helix-view/src/document.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 8ebc9002..2ef99c6a 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -788,6 +788,8 @@ impl Document { diagnostic.range.end = changes.map_pos(diagnostic.range.end, Assoc::After); diagnostic.line = self.text.char_to_line(diagnostic.range.start); } + self.diagnostics + .sort_unstable_by_key(|diagnostic| diagnostic.range); // emit lsp notification if let Some(language_server) = self.language_server() { From 130793dfd06306d1f9d25c150c2dc456cda3f9ed Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 20 Sep 2022 09:11:30 +0200 Subject: [PATCH 08/13] Add command line parameter to specify log file (#3807) * Add command line parameter to specify log file I had the logs of my debug helix mixed in with the logs from the production helix. Add a `--log` command line argument to redirect any logs to other files, making my debugging easier :-) * Update completion files with `--log` argument --- contrib/completion/hx.bash | 2 +- contrib/completion/hx.elv | 8 +++++++- contrib/completion/hx.fish | 1 + contrib/completion/hx.zsh | 1 + helix-term/src/args.rs | 5 +++++ helix-term/src/main.rs | 2 ++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/contrib/completion/hx.bash b/contrib/completion/hx.bash index 8a2d9777..89f3283c 100644 --- a/contrib/completion/hx.bash +++ b/contrib/completion/hx.bash @@ -16,7 +16,7 @@ _hx() { COMPREPLY=($(compgen -W "$languages" -- $2)) ;; *) - COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit -c --config" -- $2)) + COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit -c --config --log" -- $2)) ;; esac } && complete -F _hx hx diff --git a/contrib/completion/hx.elv b/contrib/completion/hx.elv index d3d227bc..42c88585 100644 --- a/contrib/completion/hx.elv +++ b/contrib/completion/hx.elv @@ -36,6 +36,11 @@ set edit:completion:arg-completer[hx] = {|@args| edit:complete-filename $args[-1] | each { |v| put $v[stem] } return } + # When we have --log, we need a file + if (has-values "log" $args[-2]) { + edit:complete-filename $args[-1] | each { |v| put $v[stem] } + return + } } edit:complete-filename $args[-1] | each { |v| put $v[stem]} $candidate "--help" "(Prints help information)" @@ -46,4 +51,5 @@ set edit:completion:arg-completer[hx] = {|@args| $candidate "--vsplit" "(Splits all given files vertically)" $candidate "--hsplit" "(Splits all given files horizontally)" $candidate "--config" "(Specifies a file to use for configuration)" -} \ No newline at end of file + $candidate "--log" "(Specifies a file to write log data into)" +} diff --git a/contrib/completion/hx.fish b/contrib/completion/hx.fish index 65f248d4..71c74ab0 100644 --- a/contrib/completion/hx.fish +++ b/contrib/completion/hx.fish @@ -12,3 +12,4 @@ complete -c hx -s V -l version -d "Prints version information" complete -c hx -l vsplit -d "Splits all given files vertically into different windows" complete -c hx -l hsplit -d "Splits all given files horizontally into different windows" complete -c hx -s c -l config -d "Specifies a file to use for completion" +complete -c hx -s c -l log -d "Specifies a file to write log data into" diff --git a/contrib/completion/hx.zsh b/contrib/completion/hx.zsh index e3375656..aaad6f84 100644 --- a/contrib/completion/hx.zsh +++ b/contrib/completion/hx.zsh @@ -18,6 +18,7 @@ _hx() { "--hsplit[Splits all given files horizontally into different windows]" \ "-c[Specifies a file to use for configuration]" \ "--config[Specifies a file to use for configuration]" \ + "--log[Specifies a file to write log data into]" \ "*:file:_files" case "$state" in diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index d16d7dfd..48c86633 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -14,6 +14,7 @@ pub struct Args { pub build_grammars: bool, pub split: Option, pub verbosity: u64, + pub log_file: Option, pub config_file: Option, pub files: Vec<(PathBuf, Position)>, } @@ -48,6 +49,10 @@ impl Args { Some(path) => args.config_file = Some(path.into()), None => anyhow::bail!("--config must specify a path to read"), }, + "--log" => match argv.next().as_deref() { + Some(path) => args.log_file = Some(path.into()), + None => anyhow::bail!("--log must specify a path to write"), + }, arg if arg.starts_with("--") => { anyhow::bail!("unexpected double dash argument: {}", arg) } diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index d21d3e77..726bf9e3 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -67,6 +67,7 @@ FLAGS: -g, --grammar {{fetch|build}} Fetches or builds tree-sitter grammars listed in languages.toml -c, --config Specifies a file to use for configuration -v Increases logging verbosity each use for up to 3 times + --log Specifies a file to use for logging (default file: {}) -V, --version Prints version information --vsplit Splits all given files vertically into different windows @@ -114,6 +115,7 @@ FLAGS: return Ok(0); } + let logpath = args.log_file.as_ref().cloned().unwrap_or(logpath); setup_logging(logpath, args.verbosity).context("failed to initialize logging")?; let config_dir = helix_loader::config_dir(); From 64b074541363c72534dc86d00053ecbd5511a9ca Mon Sep 17 00:00:00 2001 From: Luke Cycon Date: Tue, 20 Sep 2022 00:21:15 -0700 Subject: [PATCH 09/13] Track source and tags in diagnostics (#3898) --- helix-core/src/diagnostic.rs | 8 ++++++++ helix-lsp/src/lib.rs | 22 ++++++++++++++++++++-- helix-term/src/application.rs | 19 +++++++++++++++++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/helix-core/src/diagnostic.rs b/helix-core/src/diagnostic.rs index 48a68dc0..da199ac9 100644 --- a/helix-core/src/diagnostic.rs +++ b/helix-core/src/diagnostic.rs @@ -29,6 +29,12 @@ pub enum NumberOrString { String(String), } +#[derive(Debug, Clone)] +pub enum DiagnosticTag { + Unnecessary, + Deprecated, +} + /// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html) #[derive(Debug, Clone)] pub struct Diagnostic { @@ -37,4 +43,6 @@ pub struct Diagnostic { pub message: String, pub severity: Option, pub code: Option, + pub tags: Option>, + pub source: Option, } diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index a39325fa..8c76c4a8 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -84,15 +84,33 @@ pub mod util { None => None, }; + let tags = if let Some(ref tags) = diag.tags { + let new_tags = tags + .iter() + .map(|tag| match tag { + helix_core::diagnostic::DiagnosticTag::Unnecessary => { + lsp::DiagnosticTag::UNNECESSARY + } + helix_core::diagnostic::DiagnosticTag::Deprecated => { + lsp::DiagnosticTag::DEPRECATED + } + }) + .collect(); + + Some(new_tags) + } else { + None + }; + // TODO: add support for Diagnostic.data lsp::Diagnostic::new( range_to_lsp_range(doc, range, offset_encoding), severity, code, - None, + diag.source.clone(), diag.message.to_owned(), None, - None, + tags, ) } diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 7ee5b7f1..496464f0 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -2,7 +2,7 @@ use arc_swap::{access::Map, ArcSwap}; use futures_util::Stream; use helix_core::{ config::{default_syntax_loader, user_syntax_loader}, - diagnostic::NumberOrString, + diagnostic::{DiagnosticTag, NumberOrString}, pos_at_coords, syntax, Selection, }; use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap}; @@ -605,13 +605,28 @@ impl Application { None => None, }; + let tags = if let Some(ref tags) = diagnostic.tags { + let new_tags = tags.iter().filter_map(|tag| { + match *tag { + lsp::DiagnosticTag::DEPRECATED => Some(DiagnosticTag::Deprecated), + lsp::DiagnosticTag::UNNECESSARY => Some(DiagnosticTag::Unnecessary), + _ => None + } + }).collect(); + + Some(new_tags) + } else { + None + }; + Some(Diagnostic { range: Range { start, end }, line: diagnostic.range.start.line as usize, message: diagnostic.message.clone(), severity, code, - // source + tags, + source: diagnostic.source.clone() }) }) .collect(); From 1df32c917c8a386947063403577098d1277380c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Tue, 20 Sep 2022 16:28:00 +0900 Subject: [PATCH 10/13] diagnostics: Use Vec instead of Option> --- helix-core/src/diagnostic.rs | 2 +- helix-lsp/src/lib.rs | 23 +++++++++++------------ helix-term/src/application.rs | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/helix-core/src/diagnostic.rs b/helix-core/src/diagnostic.rs index da199ac9..db1f2da9 100644 --- a/helix-core/src/diagnostic.rs +++ b/helix-core/src/diagnostic.rs @@ -43,6 +43,6 @@ pub struct Diagnostic { pub message: String, pub severity: Option, pub code: Option, - pub tags: Option>, + pub tags: Vec, pub source: Option, } diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 8c76c4a8..8d43410a 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -84,19 +84,18 @@ pub mod util { None => None, }; - let tags = if let Some(ref tags) = diag.tags { - let new_tags = tags - .iter() - .map(|tag| match tag { - helix_core::diagnostic::DiagnosticTag::Unnecessary => { - lsp::DiagnosticTag::UNNECESSARY - } - helix_core::diagnostic::DiagnosticTag::Deprecated => { - lsp::DiagnosticTag::DEPRECATED - } - }) - .collect(); + let new_tags: Vec<_> = diag + .tags + .iter() + .map(|tag| match tag { + helix_core::diagnostic::DiagnosticTag::Unnecessary => { + lsp::DiagnosticTag::UNNECESSARY + } + helix_core::diagnostic::DiagnosticTag::Deprecated => lsp::DiagnosticTag::DEPRECATED, + }) + .collect(); + let tags = if !new_tags.is_empty() { Some(new_tags) } else { None diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 496464f0..cd499f1c 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -614,9 +614,9 @@ impl Application { } }).collect(); - Some(new_tags) + new_tags } else { - None + Vec::new() }; Some(Diagnostic { From aa00a470f31514b792e219513ffb3806a5e5b53e Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 20 Sep 2022 03:40:48 -0400 Subject: [PATCH 11/13] Fix preview bug (#3644) * Fix preview bug * Add comment to empty case --- helix-term/src/commands/typed.rs | 5 ++++- helix-term/src/ui/prompt.rs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index c22f8712..f49fff30 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -715,7 +715,10 @@ fn theme( cx.editor.unset_theme_preview(); } PromptEvent::Update => { - if let Some(theme_name) = args.first() { + if args.is_empty() { + // Ensures that a preview theme gets cleaned up if the user backspaces until the prompt is empty. + cx.editor.unset_theme_preview(); + } else if let Some(theme_name) = args.first() { if let Ok(theme) = cx.editor.theme_loader.load(theme_name) { if !(true_color || theme.is_16_color()) { bail!("Unsupported theme: theme requires true color support"); diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index d66e32be..db3bd62d 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -293,6 +293,7 @@ impl Prompt { register: char, direction: CompletionDirection, ) { + (self.callback_fn)(cx, &self.line, PromptEvent::Abort); let register = cx.editor.registers.get_mut(register).read(); if register.is_empty() { @@ -314,6 +315,7 @@ impl Prompt { self.history_pos = Some(index); self.move_end(); + (self.callback_fn)(cx, &self.line, PromptEvent::Update); self.recalculate_completion(cx.editor); } @@ -564,13 +566,11 @@ impl Component for Prompt { ctrl!('p') | key!(Up) => { if let Some(register) = self.history_register { self.change_history(cx, register, CompletionDirection::Backward); - (self.callback_fn)(cx, &self.line, PromptEvent::Update); } } ctrl!('n') | key!(Down) => { if let Some(register) = self.history_register { self.change_history(cx, register, CompletionDirection::Forward); - (self.callback_fn)(cx, &self.line, PromptEvent::Update); } } key!(Tab) => { From 385ccdfc9c4f04cbe33c7cfdd668a1f694b6d870 Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Tue, 20 Sep 2022 08:44:36 +0100 Subject: [PATCH 12/13] add :lsp-restart command (#3435) --- book/src/generated/typable-cmd.md | 1 + helix-lsp/src/lib.rs | 118 ++++++++++++++++++++---------- helix-term/src/commands/typed.rs | 41 +++++++++++ 3 files changed, 123 insertions(+), 37 deletions(-) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 653acf60..4cbff306 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -44,6 +44,7 @@ | `:show-directory`, `:pwd` | Show the current working directory. | | `:encoding` | Set encoding. Based on `https://encoding.spec.whatwg.org`. | | `:reload` | Discard changes and reload from the source file. | +| `:lsp-restart` | Restarts the Language Server that is in use by the current doc | | `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. | | `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. | | `:debug-remote`, `:dbg-tcp` | Connect to a debug adapter by TCP address and start a debugging session from a given template with given parameters. | diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 8d43410a..cb234357 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -9,7 +9,8 @@ pub use lsp::{Position, Url}; pub use lsp_types as lsp; use futures_util::stream::select_all::SelectAll; -use helix_core::syntax::LanguageConfiguration; +use helix_core::syntax::{LanguageConfiguration, LanguageServerConfiguration}; +use tokio::sync::mpsc::UnboundedReceiver; use std::{ collections::{hash_map::Entry, HashMap}, @@ -335,6 +336,33 @@ impl Registry { .map(|(_, client)| client.as_ref()) } + pub fn restart( + &mut self, + language_config: &LanguageConfiguration, + ) -> Result>> { + let config = match &language_config.language_server { + Some(config) => config, + None => return Ok(None), + }; + + let scope = language_config.scope.clone(); + + match self.inner.entry(scope) { + Entry::Vacant(_) => Ok(None), + Entry::Occupied(mut entry) => { + // initialize a new client + let id = self.counter.fetch_add(1, Ordering::Relaxed); + + let NewClientResult(client, incoming) = start_client(id, language_config, config)?; + self.incoming.push(UnboundedReceiverStream::new(incoming)); + + entry.insert((id, client.clone())); + + Ok(Some(client)) + } + } + } + pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result>> { let config = match &language_config.language_server { Some(config) => config, @@ -346,43 +374,9 @@ impl Registry { Entry::Vacant(entry) => { // initialize a new client let id = self.counter.fetch_add(1, Ordering::Relaxed); - let (client, incoming, initialize_notify) = Client::start( - &config.command, - &config.args, - language_config.config.clone(), - &language_config.roots, - id, - config.timeout, - )?; + + let NewClientResult(client, incoming) = start_client(id, language_config, config)?; self.incoming.push(UnboundedReceiverStream::new(incoming)); - let client = Arc::new(client); - - // Initialize the client asynchronously - let _client = client.clone(); - tokio::spawn(async move { - use futures_util::TryFutureExt; - let value = _client - .capabilities - .get_or_try_init(|| { - _client - .initialize() - .map_ok(|response| response.capabilities) - }) - .await; - - if let Err(e) = value { - log::error!("failed to initialize language server: {}", e); - return; - } - - // next up, notify - _client - .notify::(lsp::InitializedParams {}) - .await - .unwrap(); - - initialize_notify.notify_one(); - }); entry.insert((id, client.clone())); Ok(Some(client)) @@ -473,6 +467,56 @@ impl LspProgressMap { } } +struct NewClientResult(Arc, UnboundedReceiver<(usize, Call)>); + +/// start_client takes both a LanguageConfiguration and a LanguageServerConfiguration to ensure that +/// it is only called when it makes sense. +fn start_client( + id: usize, + config: &LanguageConfiguration, + ls_config: &LanguageServerConfiguration, +) -> Result { + let (client, incoming, initialize_notify) = Client::start( + &ls_config.command, + &ls_config.args, + config.config.clone(), + &config.roots, + id, + ls_config.timeout, + )?; + + let client = Arc::new(client); + + // Initialize the client asynchronously + let _client = client.clone(); + tokio::spawn(async move { + use futures_util::TryFutureExt; + let value = _client + .capabilities + .get_or_try_init(|| { + _client + .initialize() + .map_ok(|response| response.capabilities) + }) + .await; + + if let Err(e) = value { + log::error!("failed to initialize language server: {}", e); + return; + } + + // next up, notify + _client + .notify::(lsp::InitializedParams {}) + .await + .unwrap(); + + initialize_notify.notify_one(); + }); + + Ok(NewClientResult(client, incoming)) +} + #[cfg(test)] mod tests { use super::{lsp, util::*, OffsetEncoding}; diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index f49fff30..6d0ced65 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -985,6 +985,40 @@ fn reload( }) } +fn lsp_restart( + cx: &mut compositor::Context, + _args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + + let (_view, doc) = current!(cx.editor); + let config = doc + .language_config() + .context("LSP not defined for the current document")?; + + let scope = config.scope.clone(); + cx.editor.language_servers.restart(config)?; + + // This collect is needed because refresh_language_server would need to re-borrow editor. + let document_ids_to_refresh: Vec = cx + .editor + .documents() + .filter_map(|doc| match doc.language_config() { + Some(config) if config.scope.eq(&scope) => Some(doc.id()), + _ => None, + }) + .collect(); + + for document_id in document_ids_to_refresh { + cx.editor.refresh_language_server(document_id); + } + + Ok(()) +} + fn tree_sitter_scopes( cx: &mut compositor::Context, _args: &[Cow], @@ -1837,6 +1871,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: reload, completer: None, }, + TypableCommand { + name: "lsp-restart", + aliases: &[], + doc: "Restarts the Language Server that is in use by the current doc", + fun: lsp_restart, + completer: None, + }, TypableCommand { name: "tree-sitter-scopes", aliases: &[], From 5467c65f8224049405498d65f54c3e3f8e4ec6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20M=C3=BCller?= Date: Tue, 20 Sep 2022 14:35:00 +0200 Subject: [PATCH 13/13] fix fish completions for --config & --log (#3912) --- contrib/completion/hx.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/completion/hx.fish b/contrib/completion/hx.fish index 71c74ab0..11977605 100644 --- a/contrib/completion/hx.fish +++ b/contrib/completion/hx.fish @@ -11,5 +11,5 @@ complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity" complete -c hx -s V -l version -d "Prints version information" complete -c hx -l vsplit -d "Splits all given files vertically into different windows" complete -c hx -l hsplit -d "Splits all given files horizontally into different windows" -complete -c hx -s c -l config -d "Specifies a file to use for completion" -complete -c hx -s c -l log -d "Specifies a file to write log data into" +complete -c hx -s c -l config -r -d "Specifies a file to use for completion" +complete -c hx -l log -r -d "Specifies a file to write log data into"