mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
helix-view now builds on WASM
This commit is contained in:
parent
756b001030
commit
6f8bf67fa6
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -938,7 +938,6 @@ dependencies = [
|
|||||||
"helix-core",
|
"helix-core",
|
||||||
"helix-dap",
|
"helix-dap",
|
||||||
"helix-lsp",
|
"helix-lsp",
|
||||||
"helix-tui",
|
|
||||||
"log",
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -11,8 +11,9 @@ homepage = "https://helix-editor.com"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
# default = ["dap", "lsp"]
|
# default = ["dap", "lsp"]
|
||||||
lsp = ["helix-lsp"]
|
lsp = ["helix-lsp", "tokio-runtime"]
|
||||||
dap = ["helix-dap", "tokio-stream"]
|
dap = ["helix-dap", "tokio-stream", "tokio-runtime"]
|
||||||
|
tokio-runtime = ["tokio"]
|
||||||
term = ["crossterm"]
|
term = ["crossterm"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -22,6 +23,7 @@ helix-core = { version = "0.6", path = "../helix-core" }
|
|||||||
helix-lsp = { version = "0.6", path = "../helix-lsp", optional = true }
|
helix-lsp = { version = "0.6", path = "../helix-lsp", optional = true }
|
||||||
helix-dap = { version = "0.6", path = "../helix-dap", optional = true }
|
helix-dap = { version = "0.6", path = "../helix-dap", optional = true }
|
||||||
tokio-stream = { version = "0.1", optional = true }
|
tokio-stream = { version = "0.1", optional = true }
|
||||||
|
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"], optional = true }
|
||||||
|
|
||||||
crossterm = { version = "0.23", optional = true }
|
crossterm = { version = "0.23", optional = true }
|
||||||
|
|
||||||
@ -31,7 +33,6 @@ url = "2"
|
|||||||
|
|
||||||
arc-swap = { version = "1.5.0" }
|
arc-swap = { version = "1.5.0" }
|
||||||
|
|
||||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"] }
|
|
||||||
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
|
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
|
||||||
|
|
||||||
slotmap = "1"
|
slotmap = "1"
|
||||||
@ -43,10 +44,12 @@ serde_json = "1.0"
|
|||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
log = "~0.4"
|
log = "~0.4"
|
||||||
|
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
which = "4.2"
|
which = "4.2"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
clipboard-win = { version = "4.4", features = ["std"] }
|
clipboard-win = { version = "4.4", features = ["std"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
# TODO: graphics.rs tests rely on this, but we should remove that
|
||||||
helix-tui = { path = "../helix-tui" }
|
# [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
||||||
|
# helix-tui = { path = "../helix-tui" }
|
||||||
|
@ -14,6 +14,7 @@ pub trait ClipboardProvider: std::fmt::Debug {
|
|||||||
fn set_contents(&mut self, contents: String, clipboard_type: ClipboardType) -> Result<()>;
|
fn set_contents(&mut self, contents: String, clipboard_type: ClipboardType) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
macro_rules! command_provider {
|
macro_rules! command_provider {
|
||||||
(paste => $get_prg:literal $( , $get_arg:literal )* ; copy => $set_prg:literal $( , $set_arg:literal )* ; ) => {{
|
(paste => $get_prg:literal $( , $get_arg:literal )* ; copy => $set_prg:literal $( , $set_arg:literal )* ; ) => {{
|
||||||
Box::new(provider::command::Provider {
|
Box::new(provider::command::Provider {
|
||||||
@ -75,13 +76,13 @@ pub fn get_clipboard_provider() -> Box<dyn ClipboardProvider> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub fn get_clipboard_provider() -> Box<dyn ClipboardProvider> {
|
pub fn get_clipboard_provider() -> Box<dyn ClipboardProvider> {
|
||||||
// TODO:
|
// TODO:
|
||||||
Box::new(provider::NopProvider::new())
|
Box::new(provider::NopProvider::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(windows, target_os = "wasm32", target_os = "macos")))]
|
#[cfg(not(any(windows, target_os = "macos", target_arch = "wasm32")))]
|
||||||
pub fn get_clipboard_provider() -> Box<dyn ClipboardProvider> {
|
pub fn get_clipboard_provider() -> Box<dyn ClipboardProvider> {
|
||||||
use provider::command::{env_var_is_set, exists, is_exit_success};
|
use provider::command::{env_var_is_set, exists, is_exit_success};
|
||||||
// TODO: support for user-defined provider, probably when we have plugin support by setting a
|
// TODO: support for user-defined provider, probably when we have plugin support by setting a
|
||||||
|
@ -257,6 +257,7 @@ pub fn from_reader<R: std::io::Read + ?Sized>(
|
|||||||
Ok((rope, encoding))
|
Ok((rope, encoding))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
// The documentation and implementation of this function should be up-to-date with
|
// The documentation and implementation of this function should be up-to-date with
|
||||||
// its sibling function, `from_reader()`.
|
// its sibling function, `from_reader()`.
|
||||||
//
|
//
|
||||||
@ -474,11 +475,11 @@ fn save_impl<F: Future<Output = Transaction>>(
|
|||||||
// mark changes up to now as saved
|
// mark changes up to now as saved
|
||||||
self.reset_modified();
|
self.reset_modified();
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
let encoding = self.encoding;
|
let encoding = self.encoding;
|
||||||
|
|
||||||
// We encode the file according to the `Document`'s encoding.
|
// We encode the file according to the `Document`'s encoding.
|
||||||
async move {
|
async move {
|
||||||
use tokio::fs::File;
|
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent() {
|
||||||
// TODO: display a prompt asking the user if the directories should be created
|
// TODO: display a prompt asking the user if the directories should be created
|
||||||
if !parent.exists() {
|
if !parent.exists() {
|
||||||
@ -500,7 +501,9 @@ fn save_impl<F: Future<Output = Transaction>>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut file = File::create(path).await?;
|
#[cfg(feature = "tokio-runtime")]
|
||||||
|
let mut file = tokio::fs::File::create(path).await?;
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
to_writer(&mut file, encoding, &text).await?;
|
to_writer(&mut file, encoding, &text).await?;
|
||||||
|
|
||||||
#[cfg(feature = "lsp")]
|
#[cfg(feature = "lsp")]
|
||||||
@ -918,6 +921,7 @@ pub fn path(&self) -> Option<&PathBuf> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// File path as a URL.
|
/// File path as a URL.
|
||||||
|
#[cfg(feature = "lsp")]
|
||||||
pub fn url(&self) -> Option<Url> {
|
pub fn url(&self) -> Option<Url> {
|
||||||
Url::from_file_path(self.path()?).ok()
|
Url::from_file_path(self.path()?).ok()
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,19 @@
|
|||||||
io::stdin,
|
io::stdin,
|
||||||
num::NonZeroUsize,
|
num::NonZeroUsize,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
pin::Pin,
|
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
|
use std::pin::Pin;
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
||||||
time::{sleep, Duration, Instant, Sleep},
|
time::{sleep, Instant, Sleep},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
|
|
||||||
pub use helix_core::diagnostic::Severity;
|
pub use helix_core::diagnostic::Severity;
|
||||||
@ -459,6 +463,7 @@ pub struct Editor {
|
|||||||
pub config: Box<dyn DynAccess<Config>>,
|
pub config: Box<dyn DynAccess<Config>>,
|
||||||
pub auto_pairs: Option<AutoPairs>,
|
pub auto_pairs: Option<AutoPairs>,
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
pub idle_timer: Pin<Box<Sleep>>,
|
pub idle_timer: Pin<Box<Sleep>>,
|
||||||
pub last_motion: Option<Motion>,
|
pub last_motion: Option<Motion>,
|
||||||
pub pseudo_pending: Option<String>,
|
pub pseudo_pending: Option<String>,
|
||||||
@ -467,6 +472,8 @@ pub struct Editor {
|
|||||||
|
|
||||||
pub exit_code: i32,
|
pub exit_code: i32,
|
||||||
|
|
||||||
|
// TODO: do this via a signal flag instead
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
pub config_events: (UnboundedSender<ConfigEvent>, UnboundedReceiver<ConfigEvent>),
|
pub config_events: (UnboundedSender<ConfigEvent>, UnboundedReceiver<ConfigEvent>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -526,6 +533,7 @@ pub fn new(
|
|||||||
clipboard_provider: get_clipboard_provider(),
|
clipboard_provider: get_clipboard_provider(),
|
||||||
status_msg: None,
|
status_msg: None,
|
||||||
autoinfo: None,
|
autoinfo: None,
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
idle_timer: Box::pin(sleep(conf.idle_timeout)),
|
idle_timer: Box::pin(sleep(conf.idle_timeout)),
|
||||||
last_motion: None,
|
last_motion: None,
|
||||||
last_completion: None,
|
last_completion: None,
|
||||||
@ -533,6 +541,7 @@ pub fn new(
|
|||||||
config,
|
config,
|
||||||
auto_pairs,
|
auto_pairs,
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
config_events: unbounded_channel(),
|
config_events: unbounded_channel(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -541,6 +550,7 @@ pub fn config(&self) -> DynGuard<Config> {
|
|||||||
self.config.load()
|
self.config.load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
pub fn clear_idle_timer(&mut self) {
|
pub fn clear_idle_timer(&mut self) {
|
||||||
// equivalent to internal Instant::far_future() (30 years)
|
// equivalent to internal Instant::far_future() (30 years)
|
||||||
self.idle_timer
|
self.idle_timer
|
||||||
@ -548,6 +558,7 @@ pub fn clear_idle_timer(&mut self) {
|
|||||||
.reset(Instant::now() + Duration::from_secs(86400 * 365 * 30));
|
.reset(Instant::now() + Duration::from_secs(86400 * 365 * 30));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio-runtime")]
|
||||||
pub fn reset_idle_timer(&mut self) {
|
pub fn reset_idle_timer(&mut self) {
|
||||||
let config = self.config();
|
let config = self.config();
|
||||||
self.idle_timer
|
self.idle_timer
|
||||||
|
Loading…
Reference in New Issue
Block a user