From ed98b14e1757ac3538e7c17f3d7f5bc76563374a Mon Sep 17 00:00:00 2001 From: MDeiml Date: Wed, 22 Feb 2023 17:10:14 +0100 Subject: [PATCH] Use `open` crate to implement showing external documents --- Cargo.lock | 17 +++++++++++++++++ helix-term/Cargo.toml | 1 + helix-term/src/application.rs | 13 +++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f8302e2873a9..99d3ab189abc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1217,6 +1217,7 @@ dependencies = [ "indoc", "log", "once_cell", + "open", "pulldown-cmark", "serde", "serde_json", @@ -1609,6 +1610,16 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "open" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2078c0039e6a54a0c42c28faa984e115fb4c2d5bf2208f77d1961002df8576f8" +dependencies = [ + "pathdiff", + "windows-sys", +] + [[package]] name = "parking_lot" version = "0.11.2" @@ -1657,6 +1668,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + [[package]] name = "percent-encoding" version = "2.2.0" diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index 2d4ba436e42cb..cff0ac59f0f65 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -34,6 +34,7 @@ anyhow = "1" once_cell = "1.17" which = "4.4" +open = "3.2.0" tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] } tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] } diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index c2b1bcdf5cb31..6c3ad2165324b 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -1045,8 +1045,17 @@ impl Application { use helix_view::editor::Action; if params.external.unwrap_or(false) { - // TODO: Implement this - Ok(json!(lsp::ShowDocumentResult { success: false })) + match open::that(params.uri.as_str()) { + Ok(_) => Ok(json!(lsp::ShowDocumentResult { success: true })), + Err(err) => { + let err = format!( + "failed to open path externally: {:?}: {:?}", + params.uri, err + ); + self.editor.set_error(err); + Ok(json!(lsp::ShowDocumentResult { success: false })) + } + } } else { match params.uri.to_file_path() { Err(_) => {