diff --git a/Cargo.lock b/Cargo.lock index f69d0dea9f91f..3a9a5f7a2b0f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1116,6 +1116,7 @@ dependencies = [ "unicode-general-category", "unicode-segmentation", "unicode-width", + "url", ] [[package]] @@ -1201,6 +1202,7 @@ dependencies = [ "libc", "log", "once_cell", + "open", "pulldown-cmark", "serde", "serde_json", @@ -1272,7 +1274,6 @@ dependencies = [ "tokio", "tokio-stream", "toml", - "url", "which", ] @@ -1602,6 +1603,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 0.42.0", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -1625,6 +1636,12 @@ dependencies = [ "windows-sys 0.45.0", ] +[[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" @@ -2406,6 +2423,21 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-sys" version = "0.45.0" diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 244cfbc10a004..9933416344c11 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -38,6 +38,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 14abf0162079f..c03a2b3f82267 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 f7496087a68e7..e892e0a24a57e 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -55,6 +55,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 116c637879ee3..8d5e366859666 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -28,6 +28,7 @@ use helix_core::{ textobject, tree_sitter::Node, unicode::width::UnicodeWidthChar, + url::Url, visual_offset_from_block, Deletion, LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril, Transaction, }; @@ -328,7 +329,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", @@ -1177,6 +1178,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 9ffef00ef8f06..3906dd4b6982c 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 bd3c465d41dde..35d6e90ae314a 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -581,7 +581,7 @@ where } use helix_lsp::{lsp, Client, LanguageServerName}; -use url::Url; +use helix_core::url::Url; impl Document { pub fn from(