Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kyu08 committed Nov 14, 2024
1 parent 769f6d6 commit 46c2bdd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/file/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Histories {
#[serde(rename_all = "kebab-case")]
struct History {
path: String,
executed_targets: Vec<command::Command>,
executed_targets: Vec<Histories::>,
}

pub fn parse_history(content: String) -> Result<Vec<(PathBuf, Vec<command::Command>)>> {
Expand Down
3 changes: 0 additions & 3 deletions src/model/command.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use serde::{Deserialize, Serialize};
use std::{fmt, path::PathBuf};

use super::runner_type;

#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Command {
pub runner_type: runner_type::RunnerType,
pub name: String,
Expand Down
18 changes: 15 additions & 3 deletions src/model/histories.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};
use simple_home_dir::home_dir;
use std::{env, path::PathBuf};

use super::command;
use super::{command, runner_type};

#[derive(Clone, PartialEq, Debug)]
pub struct Histories {
Expand Down Expand Up @@ -66,6 +67,7 @@ impl Histories {
}

pub fn default(path: PathBuf) -> Self {
// TODO: should receive cwd instead of makefile_path
let histories = vec![History::default(path)];
Self { histories }
}
Expand Down Expand Up @@ -111,8 +113,8 @@ pub fn history_file_path() -> Option<(PathBuf, String)> {

#[derive(Clone, PartialEq, Debug)]
struct History {
path: PathBuf, // TODO: rename to working_directory
executed_targets: Vec<command::Command>, // TODO: rename to executed_commands
path: PathBuf, // TODO: rename to working_directory
executed_targets: Vec<HistoryCommand>, // TODO: rename to executed_commands
}

impl History {
Expand Down Expand Up @@ -149,6 +151,16 @@ impl History {
}
}

/// In the history file, the command has only the name of the command and the runner type.
/// Because its file name where it's defined and file number is variable.
/// So we search them every time fzf-make is launched.
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
struct HistoryCommand {
runner_type: runner_type::RunnerType,
name: String,
}

#[cfg(test)]
mod test {
use crate::model::runner_type;
Expand Down
18 changes: 13 additions & 5 deletions src/usecase/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@ impl Model<'_> {
fn get_histories(makefile_path: PathBuf) -> Histories {
match history_file_path() {
Some((history_file_dir, history_file_name)) => {
let content = match path_to_content::path_to_content(
history_file_dir.join(history_file_name),
) {
Err(_) => return Histories::new(makefile_path, vec![]), // NOTE: Show error message on message pane https://github.com/kyu08/fzf-make/issues/152
Ok(c) => c,
let content = {
let content =
path_to_content::path_to_content(history_file_dir.join(history_file_name));
match content {
Err(_) => return Histories::new(makefile_path, vec![]), // NOTE: Show error message on message pane https://github.com/kyu08/fzf-make/issues/152
Ok(c) => c,
}
};

// TODO: Show error message on message pane if parsing history file failed. https://github.com/kyu08/fzf-make/issues/152
let histories = toml::parse_history(content.to_string()).unwrap_or_default();

Expand Down Expand Up @@ -327,6 +330,8 @@ impl SelectTargetState<'_> {
runners: vec![runner],
search_text_area: TextArea_(TextArea::default()),
targets_list_state: ListState::with_selected(ListState::default(), Some(0)),
// TODO:
// ここでHistoriesのうちすでに存在しないcommandをfilterする必要がありそう。その過程でcommand::Commandに変換するようにする。
histories: Model::get_histories(path),
histories_list_state: ListState::with_selected(ListState::default(), Some(0)),
})
Expand Down Expand Up @@ -428,6 +433,9 @@ impl SelectTargetState<'_> {
}

pub fn get_history(&self) -> Vec<command::Command> {
// MEMO: mainではhistoriesの中からmakefile_pathのhistoryを取得する関数。
// cwdの履歴だけ取得するようにすればこの関数はいらなくなるかも。
//
// TODO(#321): この関数内で
// historyにあるcommandをself.runnersから取得するよう(行数やファイル名を最新状態からとってこないとちゃんとプレビュー表示できないため)(e.g. ファイル行番号が変わってる場合プレビューがずれる)
vec![]
Expand Down

0 comments on commit 46c2bdd

Please sign in to comment.