From 46c2bdd5e07398da7757547018b81e6390621bd6 Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Fri, 15 Nov 2024 00:26:44 +0900 Subject: [PATCH] wip --- src/file/toml.rs | 2 +- src/model/command.rs | 3 --- src/model/histories.rs | 18 +++++++++++++++--- src/usecase/tui/app.rs | 18 +++++++++++++----- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/file/toml.rs b/src/file/toml.rs index b5baa88..338a25b 100644 --- a/src/file/toml.rs +++ b/src/file/toml.rs @@ -30,7 +30,7 @@ impl Histories { #[serde(rename_all = "kebab-case")] struct History { path: String, - executed_targets: Vec, + executed_targets: Vec, } pub fn parse_history(content: String) -> Result)>> { diff --git a/src/model/command.rs b/src/model/command.rs index 49a6e7f..c73d8d9 100644 --- a/src/model/command.rs +++ b/src/model/command.rs @@ -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, diff --git a/src/model/histories.rs b/src/model/histories.rs index ecc8b7e..c91baf3 100644 --- a/src/model/histories.rs +++ b/src/model/histories.rs @@ -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 { @@ -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 } } @@ -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, // TODO: rename to executed_commands + path: PathBuf, // TODO: rename to working_directory + executed_targets: Vec, // TODO: rename to executed_commands } impl History { @@ -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; diff --git a/src/usecase/tui/app.rs b/src/usecase/tui/app.rs index 8d49e9f..c0670f3 100644 --- a/src/usecase/tui/app.rs +++ b/src/usecase/tui/app.rs @@ -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(); @@ -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)), }) @@ -428,6 +433,9 @@ impl SelectTargetState<'_> { } pub fn get_history(&self) -> Vec { + // MEMO: mainではhistoriesの中からmakefile_pathのhistoryを取得する関数。 + // cwdの履歴だけ取得するようにすればこの関数はいらなくなるかも。 + // // TODO(#321): この関数内で // historyにあるcommandをself.runnersから取得するよう(行数やファイル名を最新状態からとってこないとちゃんとプレビュー表示できないため)(e.g. ファイル行番号が変わってる場合プレビューがずれる) vec![]