diff --git a/Cargo.lock b/Cargo.lock index 066af52830ade..5baf8b1326f25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1140,6 +1140,7 @@ dependencies = [ "unicode-general-category", "unicode-segmentation", "unicode-width", + "url", ] [[package]] @@ -1217,6 +1218,7 @@ dependencies = [ "indoc", "log", "once_cell", + "open", "pulldown-cmark", "serde", "serde_json", @@ -1283,7 +1285,6 @@ dependencies = [ "tokio", "tokio-stream", "toml", - "url", "which", ] @@ -1609,6 +1610,16 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +[[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-core/Cargo.toml b/helix-core/Cargo.toml index 10de738f80b8c..159adf5ca0e95 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -37,6 +37,7 @@ log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" toml = "0.7" +url = "2.3.1" imara-diff = "0.1.0" diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs index e3f862a6054c4..2fe9b23907147 100644 --- a/helix-core/src/lib.rs +++ b/helix-core/src/lib.rs @@ -1,4 +1,5 @@ pub use encoding_rs as encoding; +pub use url; pub mod auto_pairs; pub mod chars; diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index 603f37d39ab8f..2be366e78a9ea 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -59,6 +59,8 @@ ignore = "0.4" pulldown-cmark = { version = "0.9", default-features = false } # file type detection content_inspector = "0.2.4" +# openning URLs +open = "3.2.0" # config toml = "0.7" diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d1dc92236cf0a..07a0e20437ad6 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -26,6 +26,7 @@ use helix_core::{ textobject, tree_sitter::Node, unicode::width::UnicodeWidthChar, + url::Url, visual_offset_from_block, LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril, Transaction, }; @@ -302,7 +303,7 @@ impl MappableCommand { goto_implementation, "Goto implementation", goto_file_start, "Goto line number else file start", goto_file_end, "Goto file end", - goto_file, "Goto files in selection", + goto_file, "Goto files/URLs in selection", goto_file_hsplit, "Goto files in selection (hsplit)", goto_file_vsplit, "Goto files in selection (vsplit)", goto_reference, "Goto references", @@ -1134,6 +1135,16 @@ fn goto_file_impl(cx: &mut Context, action: Action) { for sel in paths { let p = sel.trim(); if !p.is_empty() { + if let Ok(url) = Url::parse(p) { + if let Err(e) = open::that(url.as_str()) { + cx.editor.set_error(format!( + "Open file failed for url '{}': {:?}", + url.as_str(), + e + )); + } + return; + } if let Err(e) = cx.editor.open(&PathBuf::from(p), action) { cx.editor.set_error(format!("Open file failed: {:?}", e)); } diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 17e07e9a2dd6a..658f9f6ed9a85 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -25,7 +25,6 @@ helix-vcs = { version = "0.6", path = "../helix-vcs" } # Conversion traits once_cell = "1.17" -url = "2" arc-swap = { version = "1.6.0" } diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 798b54006d97a..9d800f4251732 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -352,8 +352,8 @@ where *mut_ref = f(mem::take(mut_ref)); } +use helix_core::url::Url; use helix_lsp::lsp; -use url::Url; impl Document { pub fn from(