aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorMatouš Dzivjak2024-01-17 17:24:38 +0000
committerGitHub2024-01-17 17:24:38 +0000
commitc60ba4ba04de56f37f4f4b19051bc4a1e68b3484 (patch)
tree724199349f239b9c646bc26639c60cbe18eb9b1b /helix-term/src/commands.rs
parent6754acd83ff0f6edf837611679c5f4424e14492e (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/commands.rs')
-rw-r--r--helix-term/src/commands.rs23
1 files changed, 4 insertions, 19 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index c9593380..e436e1cf 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1227,7 +1227,7 @@ fn open_url(cx: &mut Context, url: Url, action: Action) {
.unwrap_or_default();
if url.scheme() != "file" {
- return open_external_url(cx, url);
+ return cx.jobs.callback(crate::open_external_url_callback(url));
}
let content_type = std::fs::File::open(url.path()).and_then(|file| {
@@ -1240,7 +1240,9 @@ fn open_url(cx: &mut Context, url: Url, action: Action) {
// we attempt to open binary files - files that can't be open in helix - using external
// program as well, e.g. pdf files or images
match content_type {
- Ok(content_inspector::ContentType::BINARY) => open_external_url(cx, url),
+ Ok(content_inspector::ContentType::BINARY) => {
+ cx.jobs.callback(crate::open_external_url_callback(url))
+ }
Ok(_) | Err(_) => {
let path = &rel_path.join(url.path());
if path.is_dir() {
@@ -1253,23 +1255,6 @@ fn open_url(cx: &mut Context, url: Url, action: Action) {
}
}
-/// Opens URL in external program.
-fn open_external_url(cx: &mut Context, url: Url) {
- let commands = open::commands(url.as_str());
- cx.jobs.callback(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")
- })))
- });
-}
-
fn extend_word_impl<F>(cx: &mut Context, extend_fn: F)
where
F: Fn(RopeSlice, Range, usize) -> Range,