Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev_docs/project_plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This plan outlines the major development phases and tasks for building `dela`, a
- [x] [DTKT-6] Implement parser for `pyproject.toml` scripts (`pyproject-toml`).
- [x] [DTKT-106] For `package.json`, detect if there is a lock file `pnpm` or `npm` or `yarn` or `bun` use that to run tasks.
- [x] [DTKT-104] Update makefile-lossless to new version supporting trailing text.
- [x] [DTKT-200] Refactor `src/task_discovery.rs` into a registry-based `TaskDiscovery` trait with per-runner modules under `src/task_discovery/`.

- [ ] **Structs and Runners**
- [x] [DTKT-7] Define `Task` and `TaskRunner` enums in `types.rs`.
Expand Down
72 changes: 59 additions & 13 deletions src/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,13 @@ pub fn execute(verbose: bool) -> Result<(), String> {

let runner_paths: HashSet<_> =
sorted_tasks.iter().map(|task| &task.file_path).collect();
let display_path = if runner_paths.len() == 1 {
format_runner_path_for_display(&runner, &sorted_tasks[0].file_path, &current_dir)
let section_runner_path =
(runner_paths.len() == 1).then_some(sorted_tasks[0].file_path.as_path());
let display_path = if let Some(runner_path) = section_runner_path {
format_runner_path_for_display(&runner, runner_path, &current_dir)
} else {
"multiple files".to_string()
};
let show_task_sources = sorted_tasks
.iter()
.map(|task| task.definition_path().to_path_buf())
.collect::<HashSet<_>>()
.len()
> 1;

// Write section header
let colored_runner = if tool_not_installed {
Expand All @@ -290,8 +286,8 @@ pub fn execute(verbose: bool) -> Result<(), String> {
used_footnotes.insert('‖', true);
}

if task.shadowed_by.is_some() {
match task.shadowed_by.as_ref().unwrap() {
if let Some(shadowed_by) = &task.shadowed_by {
match shadowed_by {
ShadowType::ShellBuiltin(_) => {
used_footnotes.insert('†', true);
}
Expand All @@ -303,9 +299,7 @@ pub fn execute(verbose: bool) -> Result<(), String> {

// Format the task entry
let formatted_task = format_task_entry(task, is_ambiguous, display_width);
let source_label = show_task_sources.then(|| {
format_definition_path_for_display(task.definition_path(), &current_dir)
});
let source_label = task_source_label(task, section_runner_path, &current_dir);
let formatted_task =
format_task_entry_with_source(formatted_task, source_label.as_deref());
write_line(&format!(" {}", formatted_task))?;
Expand Down Expand Up @@ -455,6 +449,20 @@ fn format_task_entry_with_source(formatted_task: String, source_label: Option<&s
}
}

fn task_source_label(
task: &Task,
section_runner_path: Option<&Path>,
current_dir: &Path,
) -> Option<String> {
match section_runner_path {
Some(runner_path) if task.definition_path() == runner_path => None,
_ => Some(format_definition_path_for_display(
task.definition_path(),
current_dir,
)),
}
}

fn format_definition_path_for_display(path: &Path, current_dir: &Path) -> String {
if let Ok(relative_path) = path.strip_prefix(current_dir) {
relative_path.to_string_lossy().to_string()
Expand Down Expand Up @@ -1016,4 +1024,42 @@ mod tests {
assert!(formatted.contains("Included task"));
assert!(formatted.contains("[mk/common.mk]"));
}

#[test]
fn test_task_source_label_omits_section_runner_path_and_keeps_composed_source() {
let current_dir = Path::new("/project");
let runner_path = Path::new("/project/Makefile");

let root_task = Task {
name: "build".to_string(),
file_path: runner_path.to_path_buf(),
definition_path: None,
definition_type: TaskDefinitionType::Makefile,
runner: TaskRunner::Make,
source_name: "build".to_string(),
description: Some("Build task".to_string()),
shadowed_by: None,
disambiguated_name: None,
};
let included_task = Task {
name: "release_notes".to_string(),
file_path: runner_path.to_path_buf(),
definition_path: Some(PathBuf::from("/project/mk/common.mk")),
definition_type: TaskDefinitionType::Makefile,
runner: TaskRunner::Make,
source_name: "release_notes".to_string(),
description: Some("Release task".to_string()),
shadowed_by: None,
disambiguated_name: None,
};

assert_eq!(
task_source_label(&root_task, Some(runner_path), current_dir),
None
);
assert_eq!(
task_source_label(&included_task, Some(runner_path), current_dir),
Some("mk/common.mk".to_string())
);
}
}
Loading