Skip to content

Commit

Permalink
update paths
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Jan 18, 2023
1 parent 778d96f commit 7c80092
Show file tree
Hide file tree
Showing 28 changed files with 241 additions and 220 deletions.
13 changes: 7 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions helix-core/src/path.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use etcetera::home_dir;
use std::path::{Component, Path, PathBuf};

use crate::Position;

/// Replaces users home directory from `path` with tilde `~` if the directory
/// is available, otherwise returns the path unchanged.
pub fn fold_home_dir(path: &Path) -> PathBuf {
Expand Down Expand Up @@ -141,3 +143,37 @@ pub fn get_truncated_path<P: AsRef<Path>>(path: P) -> PathBuf {
ret.push(file);
ret
}

/// Parse arg into [`PathBuf`] and position.
pub fn parse_file(s: &str) -> (PathBuf, Position) {
let def = || (PathBuf::from(s), Position::default());
if Path::new(s).exists() {
return def();
}
split_path_row_col(s)
.or_else(|| split_path_row(s))
.unwrap_or_else(def)
}

/// Split file.rs:10:2 into [`PathBuf`], row and col.
///
/// Does not validate if file.rs is a file or directory.
fn split_path_row_col(s: &str) -> Option<(PathBuf, Position)> {
let mut s = s.rsplitn(3, ':');
let col: usize = s.next()?.parse().ok()?;
let row: usize = s.next()?.parse().ok()?;
let path = s.next()?.into();
let pos = Position::new(row.saturating_sub(1), col.saturating_sub(1));
Some((path, pos))
}

/// Split file.rs:10 into [`PathBuf`] and row.
///
/// Does not validate if file.rs is a file or directory.
fn split_path_row(s: &str) -> Option<(PathBuf, Position)> {
let (path, row) = s.rsplit_once(':')?;
let row: usize = row.parse().ok()?;
let path = path.into();
let pos = Position::new(row.saturating_sub(1), 0);
Some((path, pos))
}
11 changes: 0 additions & 11 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,12 @@ fern = "0.6"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
log = "0.4"

# File picker
fuzzy-matcher = "0.3"
ignore = "0.4"
# markdown doc rendering
pulldown-cmark = { version = "0.9", default-features = false }
# file type detection
content_inspector = "0.2.4"

# config
toml = "0.5"

serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }

# ripgrep for global search
grep-regex = "0.1.10"
grep-searcher = "0.1.10"

[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
Expand Down
37 changes: 2 additions & 35 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::Result;
use helix_core::path::parse_file;
use helix_core::Position;
use helix_view::tree::Layout;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

#[derive(Default)]
pub struct Args {
Expand Down Expand Up @@ -85,37 +86,3 @@ impl Args {
Ok(args)
}
}

/// Parse arg into [`PathBuf`] and position.
pub(crate) fn parse_file(s: &str) -> (PathBuf, Position) {
let def = || (PathBuf::from(s), Position::default());
if Path::new(s).exists() {
return def();
}
split_path_row_col(s)
.or_else(|| split_path_row(s))
.unwrap_or_else(def)
}

/// Split file.rs:10:2 into [`PathBuf`], row and col.
///
/// Does not validate if file.rs is a file or directory.
fn split_path_row_col(s: &str) -> Option<(PathBuf, Position)> {
let mut s = s.rsplitn(3, ':');
let col: usize = s.next()?.parse().ok()?;
let row: usize = s.next()?.parse().ok()?;
let path = s.next()?.into();
let pos = Position::new(row.saturating_sub(1), col.saturating_sub(1));
Some((path, pos))
}

/// Split file.rs:10 into [`PathBuf`] and row.
///
/// Does not validate if file.rs is a file or directory.
fn split_path_row(s: &str) -> Option<(PathBuf, Position)> {
let (path, row) = s.rsplit_once(':')?;
let row: usize = row.parse().ok()?;
let path = path.into();
let pos = Position::new(row.saturating_sub(1), 0);
Some((path, pos))
}
8 changes: 4 additions & 4 deletions helix-term/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ extern crate helix_view;

pub mod application;
pub mod args;
pub mod commands;
pub use helix_view::commands;
pub use helix_view::compositor;
pub mod config;
pub use helix_view::config;
pub mod health;
pub use helix_view::job;
pub mod keymap;
pub mod ui;
pub use helix_view::keymap;
pub use helix_view::ui;
pub use keymap::macros::*;

#[cfg(not(windows))]
Expand Down
13 changes: 13 additions & 0 deletions helix-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ log = "~0.4"

which = "4.2"

# File picker
fuzzy-matcher = "0.3"
ignore = "0.4"
# markdown doc rendering
pulldown-cmark = { version = "0.9", default-features = false }
# file type detection
content_inspector = "0.2.4"

# ripgrep for global search
grep-regex = "0.1.10"
grep-searcher = "0.1.10"

signal-hook = "0.3"

[target.'cfg(windows)'.dependencies]
clipboard-win = { version = "4.5", features = ["std"] }
Expand Down
33 changes: 16 additions & 17 deletions helix-view/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ pub(crate) mod lsp;
pub(crate) mod typed;

pub use dap::*;
use helix_tui::widgets::Row;
use helix_vcs::Hunk;
pub use lsp::*;
use tui::widgets::Row;
pub use typed::*;

use crate::{
apply_transaction,
clipboard::ClipboardType,
document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
editor::{Action, Motion},
info::Info,
input::KeyEvent,
keyboard::KeyCode,
tree,
view::View,
Document, DocumentId, Editor, ViewId,
};
use helix_core::{
comment, coords_at_pos, encoding, find_first_non_whitespace_char, find_root, graphemes,
history::UndoKind,
Expand All @@ -25,26 +37,13 @@ use helix_core::{
visual_coords_at_pos, LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection,
SmallVec, Tendril, Transaction,
};
use helix_view::{
apply_transaction,
clipboard::ClipboardType,
document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
editor::{Action, Motion},
info::Info,
input::KeyEvent,
keyboard::KeyCode,
tree,
view::View,
Document, DocumentId, Editor, ViewId,
};

use anyhow::{anyhow, bail, ensure, Context as _};
use fuzzy_matcher::FuzzyMatcher;
use insert::*;
use movement::Movement;

use crate::{
args,
compositor::{self, Component, Compositor},
job::Callback,
keymap::ReverseKeymap,
Expand Down Expand Up @@ -124,7 +123,7 @@ impl<'a> Context<'a> {
}
}

use helix_view::{align_view, Align};
use crate::{align_view, Align};

/// A MappableCommand is either a static command like "jump_view_up" or a Typable command like
/// :format. It causes a side-effect on the state (usually by creating and applying a transaction).
Expand Down Expand Up @@ -4878,7 +4877,7 @@ async fn shell_impl_async(
let output = if let Some(mut stdin) = process.stdin.take() {
let input_task = tokio::spawn(async move {
if let Some(input) = input {
helix_view::document::to_writer(&mut stdin, encoding::UTF_8, &input).await?;
crate::document::to_writer(&mut stdin, encoding::UTF_8, &input).await?;
}
Ok::<_, anyhow::Error>(())
});
Expand Down Expand Up @@ -5148,7 +5147,7 @@ fn replay_macro(cx: &mut Context) {
}

let keys: Vec<KeyEvent> = if let Some([keys_str]) = cx.editor.registers.read(reg) {
match helix_view::input::parse_macro(keys_str) {
match crate::input::parse_macro(keys_str) {
Ok(keys) => keys,
Err(err) => {
cx.editor.set_error(format!("Invalid macro: {}", err));
Expand Down
13 changes: 7 additions & 6 deletions helix-view/src/commands/dap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{Context, Editor};
use crate::editor::Breakpoint;
use crate::{
compositor::{self, Compositor},
job::{Callback, Jobs},
Expand All @@ -8,19 +9,19 @@ use dap::{StackFrame, Thread, ThreadStates};
use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate};
use helix_dap::{self as dap, Client};
use helix_lsp::block_on;
use helix_view::editor::Breakpoint;

use helix_tui::{text::Spans, widgets::Row};
use serde_json::{to_value, Value};
use tokio_stream::wrappers::UnboundedReceiverStream;
use tui::{text::Spans, widgets::Row};

use std::collections::HashMap;
use std::future::Future;
use std::path::PathBuf;

use anyhow::{anyhow, bail};

use helix_view::handlers::dap::{breakpoints_changed, jump_to_stack_frame, select_thread_id};
use crate::debugger;
use crate::handlers::dap::{breakpoints_changed, jump_to_stack_frame, select_thread_id};

impl ui::menu::Item for StackFrame {
type Data = ();
Expand Down Expand Up @@ -505,8 +506,8 @@ pub fn dap_variables(cx: &mut Context) {
let text_style = theme.get("ui.text.focus");

for scope in scopes.iter() {
// use helix_view::graphics::Style;
use tui::text::Span;
// use crate::graphics::Style;
use helix_tui::text::Span;
let response = block_on(debugger.variables(scope.variables_reference));

variables.push(Spans::from(Span::styled(
Expand All @@ -531,7 +532,7 @@ pub fn dap_variables(cx: &mut Context) {
}
}

let contents = Text::from(tui::text::Text::from(variables));
let contents = Text::from(helix_tui::text::Text::from(variables));
let popup = Popup::new("dap-variables", contents);
cx.push_layer(Box::new(popup));
}
Expand Down
4 changes: 2 additions & 2 deletions helix-view/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use helix_lsp::{
util::{diagnostic_to_lsp_diagnostic, lsp_pos_to_pos, lsp_range_to_range, range_to_lsp_range},
OffsetEncoding,
};
use tui::{
use helix_tui::{
text::{Span, Spans},
widgets::Row,
};

use super::{align_view, push_jump, Align, Context, Editor, Open};

use crate::{apply_transaction, document::Mode, editor::Action, theme::Style};
use helix_core::{path, Selection};
use helix_view::{apply_transaction, document::Mode, editor::Action, theme::Style};

use crate::{
compositor::{self, Compositor},
Expand Down
7 changes: 4 additions & 3 deletions helix-view/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use crate::job::Job;

use super::*;

use helix_view::{
use crate::{
apply_transaction,
editor::{Action, CloseError, ConfigEvent},
};
use helix_core::path::parse_file;
use ui::completers::{self, Completer};

#[derive(Clone)]
Expand Down Expand Up @@ -64,7 +65,7 @@ fn open(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) ->

ensure!(!args.is_empty(), "wrong argument count");
for arg in args {
let (path, pos) = args::parse_file(arg);
let (path, pos) = parse_file(arg);
let path = helix_core::path::expand_tilde(&path);
// If the path is a directory, open a file picker on that directory and update the status
// message
Expand Down Expand Up @@ -770,7 +771,7 @@ fn theme(
args: &[Cow<str>],
event: PromptEvent,
) -> anyhow::Result<()> {
let true_color = cx.editor.config.load().true_color || crate::true_color();
let true_color = cx.editor.config.load().true_color || crate::theme::true_color();
match event {
PromptEvent::Abort => {
cx.editor.unset_theme_preview();
Expand Down
Loading

0 comments on commit 7c80092

Please sign in to comment.