2020-06-02 09:57:01 +08:00
|
|
|
#![allow(unused)]
|
2021-03-22 11:18:48 +08:00
|
|
|
pub mod auto_pairs;
|
2021-06-14 10:13:31 +08:00
|
|
|
pub mod chars;
|
2021-02-18 17:35:39 +08:00
|
|
|
pub mod comment;
|
2021-03-11 15:31:49 +08:00
|
|
|
pub mod diagnostic;
|
2020-09-10 12:55:18 +08:00
|
|
|
pub mod graphemes;
|
2021-06-11 21:06:13 +08:00
|
|
|
pub mod history;
|
2020-10-14 11:01:41 +08:00
|
|
|
pub mod indent;
|
2020-09-21 17:24:16 +08:00
|
|
|
pub mod macros;
|
2021-03-22 16:58:49 +08:00
|
|
|
pub mod match_brackets;
|
2021-03-18 12:39:34 +08:00
|
|
|
pub mod movement;
|
2021-02-22 14:50:41 +08:00
|
|
|
pub mod object;
|
2020-09-17 13:57:49 +08:00
|
|
|
mod position;
|
2020-10-06 15:00:23 +08:00
|
|
|
pub mod register;
|
2021-03-11 09:44:38 +08:00
|
|
|
pub mod search;
|
2020-09-29 00:01:27 +08:00
|
|
|
pub mod selection;
|
2021-05-30 16:52:46 +08:00
|
|
|
mod state;
|
2020-09-12 18:36:49 +08:00
|
|
|
pub mod syntax;
|
2020-05-25 12:02:21 +08:00
|
|
|
mod transaction;
|
2020-05-20 17:14:51 +08:00
|
|
|
|
2021-06-12 14:30:55 +08:00
|
|
|
static RUNTIME_DIR: once_cell::sync::Lazy<std::path::PathBuf> =
|
|
|
|
once_cell::sync::Lazy::new(runtime_dir);
|
|
|
|
|
2021-06-08 15:11:45 +08:00
|
|
|
pub fn find_first_non_whitespace_char(line: RopeSlice) -> Option<usize> {
|
2021-06-08 14:25:55 +08:00
|
|
|
line.chars().position(|ch| !ch.is_whitespace())
|
2021-02-18 17:34:22 +08:00
|
|
|
}
|
|
|
|
|
2021-06-07 20:32:01 +08:00
|
|
|
pub fn find_root(root: Option<&str>) -> Option<std::path::PathBuf> {
|
|
|
|
let current_dir = std::env::current_dir().expect("unable to determine current directory");
|
|
|
|
|
|
|
|
let root = match root {
|
|
|
|
Some(root) => {
|
|
|
|
let root = std::path::Path::new(root);
|
|
|
|
if root.is_absolute() {
|
|
|
|
root.to_path_buf()
|
|
|
|
} else {
|
|
|
|
current_dir.join(root)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => current_dir,
|
|
|
|
};
|
|
|
|
|
|
|
|
for ancestor in root.ancestors() {
|
|
|
|
// TODO: also use defined roots if git isn't found
|
|
|
|
if ancestor.join(".git").is_dir() {
|
|
|
|
return Some(ancestor.to_path_buf());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2021-06-04 04:46:56 +08:00
|
|
|
#[cfg(not(embed_runtime))]
|
2021-06-12 14:59:50 +08:00
|
|
|
fn runtime_dir() -> std::path::PathBuf {
|
2021-06-12 14:30:55 +08:00
|
|
|
if let Ok(dir) = std::env::var("HELIX_RUNTIME") {
|
|
|
|
return dir.into();
|
|
|
|
}
|
|
|
|
|
|
|
|
const RT_DIR: &str = "runtime";
|
|
|
|
let conf_dir = config_dir().join(RT_DIR);
|
|
|
|
if conf_dir.exists() {
|
|
|
|
return conf_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Ok(dir) = std::env::var("CARGO_MANIFEST_DIR") {
|
|
|
|
// this is the directory of the crate being run by cargo, we need the workspace path so we take the parent
|
|
|
|
return std::path::PathBuf::from(dir).parent().unwrap().join(RT_DIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
// fallback to location of the executable being run
|
|
|
|
std::env::current_exe()
|
|
|
|
.ok()
|
2021-06-12 16:20:03 +08:00
|
|
|
.and_then(|path| path.parent().map(|path| path.to_path_buf().join(RT_DIR)))
|
2021-06-12 14:30:55 +08:00
|
|
|
.unwrap()
|
2021-05-10 00:02:53 +08:00
|
|
|
}
|
|
|
|
|
2021-04-07 22:56:20 +08:00
|
|
|
pub fn config_dir() -> std::path::PathBuf {
|
|
|
|
// TODO: allow env var override
|
2021-05-10 15:21:55 +08:00
|
|
|
let strategy = choose_base_strategy().expect("Unable to find the config directory!");
|
|
|
|
let mut path = strategy.config_dir();
|
|
|
|
path.push("helix");
|
|
|
|
path
|
2021-04-07 22:56:20 +08:00
|
|
|
}
|
|
|
|
|
2021-06-03 00:19:56 +08:00
|
|
|
pub fn cache_dir() -> std::path::PathBuf {
|
|
|
|
// TODO: allow env var override
|
|
|
|
let strategy = choose_base_strategy().expect("Unable to find the config directory!");
|
|
|
|
let mut path = strategy.cache_dir();
|
|
|
|
path.push("helix");
|
|
|
|
path
|
|
|
|
}
|
|
|
|
|
|
|
|
use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
|
|
|
|
|
2020-06-05 13:02:10 +08:00
|
|
|
pub use ropey::{Rope, RopeSlice};
|
2020-09-29 00:00:35 +08:00
|
|
|
|
2020-05-28 13:45:44 +08:00
|
|
|
pub use tendril::StrTendril as Tendril;
|
|
|
|
|
2021-06-13 01:00:50 +08:00
|
|
|
pub use unicode_general_category::get_general_category;
|
|
|
|
|
2020-09-29 00:01:27 +08:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use {regex, tree_sitter};
|
|
|
|
|
2021-03-18 12:39:34 +08:00
|
|
|
pub use position::{coords_at_pos, pos_at_coords, Position};
|
2021-03-22 11:40:07 +08:00
|
|
|
pub use selection::{Range, Selection};
|
2021-04-01 10:01:11 +08:00
|
|
|
pub use smallvec::SmallVec;
|
2020-09-17 13:57:49 +08:00
|
|
|
pub use syntax::Syntax;
|
2021-06-16 23:00:21 +08:00
|
|
|
pub use graphemes::RopeGraphemes;
|
2020-05-25 12:02:21 +08:00
|
|
|
|
2020-10-20 12:58:34 +08:00
|
|
|
pub use diagnostic::Diagnostic;
|
2020-05-25 12:02:21 +08:00
|
|
|
pub use state::State;
|
|
|
|
|
2020-10-23 17:48:03 +08:00
|
|
|
pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction};
|