diff options
author | Matouš Dzivjak | 2024-01-17 17:24:38 +0000 |
---|---|---|
committer | GitHub | 2024-01-17 17:24:38 +0000 |
commit | c60ba4ba04de56f37f4f4b19051bc4a1e68b3484 (patch) | |
tree | 724199349f239b9c646bc26639c60cbe18eb9b1b /helix-term/src/lib.rs | |
parent | 6754acd83ff0f6edf837611679c5f4424e14492e (diff) |
feat(lsp): implement show document request (#8865)
* feat(lsp): implement show document request
Implement [window.showDocument](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showDocument)
LSP server-sent request.
This PR builds on top of helix-editor#5820,
moves the external-URL opening functionality into shared crate-level
function that returns a callback that is now used by both the
`open_file` command as well as the window.showDocument handler if
the URL is marked as external.
* add return
* use vertical split
* refactor
---------
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-term/src/lib.rs')
-rw-r--r-- | helix-term/src/lib.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/helix-term/src/lib.rs b/helix-term/src/lib.rs index a94c5e49..a1d60329 100644 --- a/helix-term/src/lib.rs +++ b/helix-term/src/lib.rs @@ -12,7 +12,11 @@ pub mod keymap; pub mod ui; use std::path::Path; +use futures_util::Future; use ignore::DirEntry; +use url::Url; + +pub use keymap::macros::*; #[cfg(not(windows))] fn true_color() -> bool { @@ -46,3 +50,22 @@ fn filter_picker_entry(entry: &DirEntry, root: &Path, dedup_symlinks: bool) -> b true } + +/// Opens URL in external program. +fn open_external_url_callback( + url: Url, +) -> impl Future<Output = Result<job::Callback, anyhow::Error>> + Send + 'static { + let commands = open::commands(url.as_str()); + async { + for cmd in commands { + let mut command = tokio::process::Command::new(cmd.get_program()); + command.args(cmd.get_args()); + if command.output().await.is_ok() { + return Ok(job::Callback::Editor(Box::new(|_| {}))); + } + } + Ok(job::Callback::Editor(Box::new(move |editor| { + editor.set_error("Opening URL in external program failed") + }))) + } +} |