davraamides / todotxt-mode

MIT License
59 stars 12 forks source link

Feature request: Task prerequisites using id: and p: #36

Closed muteboy closed 2 years ago

muteboy commented 3 years ago

In another todo.txt tool (topydo) I've seen the ability to set a dependency between one task and another. This was really great and very useful. It was done by adding an id:[num] tag in the task that must come first, and a p:[num] tag in the second task, referring to the prerequisite.

I know this is not built-in to todo.txt, but I think I saw it somewhere as a possible future feature.

I much prefer working in VSCode. It would be GREAT if this could be added. I only dabble in coding, and I don't know TS at all, or I'd try something myself.

Here's how it might work:

  1. In topydo, tasks are given id: tags only when the dependency is defined. Maybe all tasks could be assigned a unique id: on creation? Just the next available integer in the file? Once a task is archived to done.txt, its number is freed up.
  2. User could manually add a p: tag to a task, referring to the id: of the task it depends on. Other ways to identify a prerequisite?
  3. Add a Sort by Prerequisite function so that tasks appearing in other tasks p: tags would come first. I think that would be a bubble sort - it would have to check each pair and make sure that the prerequisite appeared before the task that needs it.

Example:

task 1 @Home
task 2 @Home
task 3 @Home

Add ids:

task 1 @Home id:1
task 2 @Home id:2
task 3 @Home id:3

Set precedence:

task 1 @Home id:1 p:2
task 2 @Home id:2 p:3
task 3 @Home id:3

Sort by Prerequisite:

task 3 @Home id:3
task 2 @Home id:2 p:3
task 1 @Home id:1 p:2

Any chance this could be implemented? Happy to discuss further.

davraamides commented 2 years ago

Hi @muteboy. Apologies for taking so long to respond. I've thought about this a bit but I do see some challenges with implementing it. It would be hard to auto-add an id:x tag at creation time because new tasks are not created through the extension. The user just types a new line and the extension simply decorates it accordingly. There could be an additional command that would scan the file for the highest id and then add incrementally to the current task, the selected tasks, or the entire file, I suppose.

Sorting would be difficult since this is just text. While I do offer sorting by certain task attributes, none of them depend on the value of an attribute on another task so that would take some work.

Additionally, there is a potential data integrity issue - it would be easy to create a file that has invalid references. For example, task 1 depends on 2 and task 2 depends on 1, or task 1 depends on 3 but 3 doesn’t exist, or two tasks with the same id are created.

This feature would add a fair amount of complexity to the extension for a non-standard feature so it's not going to be very high on my list, but I will think about it some more.

muteboy commented 2 years ago

Hi, Yes, I agree with all that. It would add a lot of hacky complexity! Thanks for thinking about it.