on 376c19e help sign in
113 lines 3.1 kB history raw
1pub use encoding_rs as encoding;
3pub mod auto_pairs;
4pub mod chars;
5pub mod comment;
6pub mod config;
7pub mod diagnostic;
8pub mod diff;
9pub mod doc_formatter;
10pub mod graphemes;
11pub mod history;
12pub mod increment;
13pub mod indent;
14pub mod line_ending;
15pub mod macros;
16pub mod match_brackets;
17pub mod movement;
18pub mod object;
19pub mod path;
20mod position;
21pub mod register;
22pub mod search;
23pub mod selection;
24pub mod shellwords;
25pub mod surround;
26pub mod syntax;
27pub mod test;
28pub mod text_annotations;
29pub mod textobject;
30mod transaction;
31pub mod wrap;
33pub mod unicode {
34 pub use unicode_general_category as category;
35 pub use unicode_segmentation as segmentation;
36 pub use unicode_width as width;
39pub fn find_first_non_whitespace_char(line: RopeSlice) -> Option<usize> {
40 line.chars().position(|ch| !ch.is_whitespace())
43/// Find project root.
44///
45/// Order of detection:
46/// * Top-most folder containing a root marker in current git repository
47/// * Git repository root if no marker detected
48/// * Top-most folder containing a root marker if not git repository detected
49/// * Current working directory as fallback
50pub fn find_root(root: Option<&str>, root_markers: &[String]) -> std::path::PathBuf {
51 let current_dir = std::env::current_dir().expect("unable to determine current directory");
53 let root = match root {
54 Some(root) => {
55 let root = std::path::Path::new(root);
56 if root.is_absolute() {
57 root.to_path_buf()
58 } else {
59 current_dir.join(root)
60 }
61 }
62 None => current_dir.clone(),
63 };
65 let mut top_marker = None;
66 for ancestor in root.ancestors() {
67 if root_markers
68 .iter()
69 .any(|marker| ancestor.join(marker).exists())
70 {
71 top_marker = Some(ancestor);
72 }
74 if ancestor.join(".git").exists() {
75 // Top marker is repo root if not root marker was detected yet
76 if top_marker.is_none() {
77 top_marker = Some(ancestor);
78 }
79 // Don't go higher than repo if we're in one
80 break;
81 }
82 }
84 // Return the found top marker or the current_dir as fallback
85 top_marker.map_or(current_dir, |a| a.to_path_buf())
88pub use ropey::{self, str_utils, Rope, RopeBuilder, RopeSlice};
90// pub use tendril::StrTendril as Tendril;
91pub use smartstring::SmartString;
93pub type Tendril = SmartString<smartstring::LazyCompact>;
95#[doc(inline)]
96pub use {regex, tree_sitter};
98pub use graphemes::RopeGraphemes;
99pub use position::{
100 char_idx_at_visual_offset, coords_at_pos, pos_at_coords, visual_offset_from_anchor,
101 visual_offset_from_block, Position,
102};
103#[allow(deprecated)]
104pub use position::{pos_at_visual_coords, visual_coords_at_pos};
106pub use selection::{Range, Selection};
107pub use smallvec::{smallvec, SmallVec};
108pub use syntax::Syntax;
110pub use diagnostic::Diagnostic;
112pub use line_ending::{LineEnding, DEFAULT_LINE_ENDING};
113pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction};