Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way for third-party plugins to parse and modify Tasks #1389

Open
2 tasks done
davish opened this issue Dec 11, 2022 · 16 comments
Open
2 tasks done

Add a way for third-party plugins to parse and modify Tasks #1389

davish opened this issue Dec 11, 2022 · 16 comments
Labels
scope: for plugin developers Tools for use by plugin developers, including the Tasks API type: enhancement New feature or request

Comments

@davish
Copy link

davish commented Dec 11, 2022

⚠️ Please check that this feature request hasn't been suggested before.

  • I searched previous Ideas in Discussions didn't find any similar feature requests.
  • I searched previous Issues didn't find any similar feature requests.

🔖 Feature description

I am a plugin developer and would like to allow users of my plugin who also use Tasks to be able to toggle events as completed from a custom view in my plugin. I've suggested one way to do this below with Obsidian events, but happy to discuss more about what the best way to do this is.

✔️ Solution

Some core plugins provide actions that 3rd-party plugins can trigger in order to perform actions that are normally handled by the core plugin. For example, the Page preview plugin exposes an event hover-link that lets other plugins trigger hover previews over any element. It is triggered with a call like so:

// `jsEvent` is the JavaScript mouse event that shows where the mouse currently is.
this.app.workspace.trigger("hover-link", {
	event: jsEvent,
	source: "MY_PLUGIN_SLUG",
	hoverParent: parentElement,
	targetEl: jsEvent.target,
	linktext: "path/to/file",
	sourcePath: "path/to/file",
});

New actions can be created by listening with this.app.workspace.on().

Tasks could provide an action that plugins would be able to call with something like:

this.app.workspace.trigger("toggle-task", {
	source: "MY_PLUGIN_SLUG"
	path: "path/to/file",
        lineNumber: <line number for Task>
});

There are other objects that implement the Events interface (see here), in case you think there's one that's a better fit for registering this than app.workspace.

There could also be another Event that gets triggered when the Cache gets updated, so that plugins listening to that Event can keep track of tasks without having to parse them themselves.

❓ Alternatives

An alternative way to allow other plugins to modify tasks is to factor out all of the Task parsing and printing code into a separate library published on NPM that can be included in the Tasks plugin as well as any other plugin that would like to modify tasks. This is the approach taken by [@]liamcain with obsidian-daily-notes-interface, which they use for Calendar to create and navigate between a user's daily notes.

Downsides of this alternative:

  • A lot of work to pull the required functionality out of the plugin into a library.
  • Third-party plugin authors who use the library will need to keep it up-to-date with the Tasks plugin. If a plugin that uses the library hasn't been updated in a while, modifications to Tasks code through that plugin will use the old code.

📝 Additional Context

I'm the developer of the Obsidian Full Calendar plugin which supports basic task lists, and am starting to investigate adding Tasks support to the plugin (obsidian-community/obsidian-full-calendar#219).

@davish davish added the type: enhancement New feature or request label Dec 11, 2022
@claremacrae
Copy link
Collaborator

Hi @davish, Wow, thank you for a very helpful message.

There's a lot to take in there.

I'm very keen to seen this happen, but It's unlikely something that I would work on on my own, as I would need to learn about the innards of a second plugin to be able to test it.

Would you be willing to pair on this? (By which I mean, communicating verbally and screen sharing, rather than typing via GitHub)
I would certainly to make time to pair with you, to get a skeleton version working to start with, and evolve from there.

@BluBloos
Copy link
Contributor

BluBloos commented Feb 4, 2023

re: the alternative method, wouldn't this be quite slow for end users of Obsidian? To have the parsing logic be performed by both (or X) plugins?

@BluBloos
Copy link
Contributor

BluBloos commented Feb 4, 2023

My general comment for this issue is: awesome idea!

What I would personally like to see from the Tasks plugin is it becoming a database for user tasks. It is already such a database, but only the Tasks plugin has read access.

Other plugins need to get read access too!

@BluBloos
Copy link
Contributor

BluBloos commented Feb 4, 2023

I'd like to know what progress has been made on this issue?

@claremacrae
Copy link
Collaborator

I'd like to know what progress has been made on this issue?

Sure. For what context?

@claremacrae
Copy link
Collaborator

I'd like to know what progress has been made on this issue?

I am really uncomfortable with questions like this, as it feels to me like they are demanding why no progress has been recorded.

I realise that this is probably not your intention, @BluBloos, but that's what it feels like, as someone with unpaid responsibility for all aspects of a project with many users requesting changes.

If you were asking in order to offer help, I would say let's set up a pairing session to get you started, share what you would need to know for a successful PR in this area - and the details of what has happened so far.

But in any case, define progress.

I have spent many hours in discussion with other plugin developers. No actual development has yet has come out of this. Trying to find overlapping free time between pairs of people responsible for large open source projects in their free time, in different time zones, is difficult.

There are a tiny number of PRs that make changes towards this direction, but they all expose the innards of Task class interfaces, which would tie my hands and prevent future refactoring and improving of the internals of the code, which would seriously hamper future development. So none have been accepted. Feel free to read the discussion in #1421 to get a flavour of the concerns.

@aubreyz
Copy link

aubreyz commented Feb 4, 2023

My general comment for this issue is: awesome idea!

What I would personally like to see from the Tasks plugin is it becoming a database for user tasks. It is already such a database, but only the Tasks plugin has read access.

Other plugins need to get read access too!

That does not seem correct at all in any case as a conception. Obsidian is the database. Tasks is one possible interface to those data. Nothing at all stopping anything else reading the raw data.

@claremacrae
Copy link
Collaborator

That does not seem correct at all in any case as a conception. Obsidian is the database. Tasks is one possible interface to those data. Nothing at all stopping anything else reading the raw data.

Oooh. I like that.

Also, on reflection, I really want to keep Tasks just focussed on - erm - tasks.

I greatly underestimated how much of my time it would take up, when I took it over last May-ish. I could not agree any changes in scope that would increase the very significant user support workload nor the maintenance workload.

@aubreyz
Copy link

aubreyz commented Feb 4, 2023

Can I make a meta-suggestion @claremacrae - it sort of fits with this thread but could be moved elsewhere. It fits with my conception that you are getting stressed, and are wondering about correct allocation of time. My suggestion also addresses a host of others about formatting output (like "I hate icons") and also questions about interchange with other systems ("can you please read or write todo.txt type data") and the issues of concerns about being locked into a system (everything that markdown is not about).

My suggestion is:

a) Regard the current specification of the formatting of a task as fixed/finalised at least for the long-term future. You are not going to change that. Publish that specification formally.
b) Do something that is along the lines slightly of what @BluBloos is suggesting and share a single function that reads a line of text that fits specification (a) and spits out an array. Some of the elements could be mapped (e.g Priority High = 3). This could be as a csv type string line for example (or maybe json). Something like:
status, description, date1, date2, date3,tag1,tag2,tag3,tag4,tag5
c) Then use that function as a completely alternative form of output using all the usual mechanisms

For example

 ```tasks
 csv
 ```

Will spit out a csv file instead of the usual output using the function in (b) most of which will already be written

d) Also have a reverse of the Function in (b) that takes a single csv type string and spits out a task in markdown format. This could be user modifiable - at least by a programmer (so if you want a due: instead of an icon, you can bloody well do that yourself).

That would seem to open things up for quite a lot of stuff

  • Future proofing
  • An interface to any format change
  • Someone who wants to move to todo.txt can read in the csv file and to it by themselves (in Excel), or someone who wants to write an interface/plugin to caldav can do that too.
  • Takes a lot of the endless and infinite potential tweaks out of the tasks plugin completely

@BluBloos
Copy link
Contributor

BluBloos commented Feb 4, 2023

@claremacrae

I am really uncomfortable with questions like this, as it feels to me like they are demanding why no progress has been recorded.

I am so sorry for not being more clear! I asked what progress has been made thus far because I am about to step into a bout of work to make some forward movement. I asked pretty much just to make sure I wasn't wasting my time in case some substantial work has been done, and I took a completely different approach to whatever work was already done.

But in any case, define progress.

Any code that has been written.

Feel free to read the discussion in #1421 to get a flavour of the concerns.

I'll take a read!


I'll leave with this. Please, please, please know that I wish to put no additional stress and work on you. I'm going to do this work regardless for the sake of linking with a plugin that I plan to write, and I just thought that if I was going to do it, sharing the work might potentially be useful.

@BluBloos
Copy link
Contributor

BluBloos commented Feb 4, 2023

@aubreyz

That does not seem correct at all in any case as a conception. Obsidian is the database. Tasks is one possible interface to those data. Nothing at all stopping anything else reading the raw data.

I understand this viewpoint.

For what it's worth, I'll let you know what thoughts led me to make the statement that I did.

  1. Obsidian is a database.
  2. Tasks does a whole bunch of work to distill the data in Obsidian into a more useful form.
  3. Therefore Tasks is in its own right a database.
  4. While other parties also have access to the Obsidian database, they are lazy and probably wouldn't want to do that same work.

@claremacrae
Copy link
Collaborator

@BluBloos

I am really uncomfortable with questions like this, as it feels to me like they are demanding why no progress has been recorded.

I am so sorry for not being more clear! I asked what progress has been made thus far because I am about to step into a bout of work to make some forward movement. I asked pretty much just to make sure I wasn't wasting my time in case some substantial work has been done, and I took a completely different approach to whatever work was already done.

Oh wow - now I am feeling super guilty and super happy!

There is far too much to talk about by typing in GitHub, and I would much rather brief you, and understand what you have in mind, before you do work on it...

I do have a lot of notes about this, and a lot of info from other plugin developers...

And also a little code in a personal fork of Tasks...

My email address is in my GitHub profile - could we set up a chance to chat please?

I'll leave with this. Please, please, please know that I wish to put no additional stress and work on you. I'm going to do this work regardless for the sake of linking with a plugin that I plan to write, and I just thought that if I was going to do it, sharing the work might potentially be useful.

🎉 🚀 That is tremendous. Very many thanks indeed!

@claremacrae
Copy link
Collaborator

Hi @aubreyz,

Can I make a meta-suggestion @claremacrae - it sort of fits with this thread but could be moved elsewhere. It fits with my conception that you are getting stressed, and are wondering about correct allocation of time.

Gosh, thank you very much for the care, and for the suggestion. Much appreciated.

@ilandikov
Copy link
Collaborator

Hey guys, if I may, since the potential API scope is to access the tasks eg - [ ]... stuff and toggle them and not the Tasks functionalities like an API to call query happens before 2023-02-07, why not using dataview API? It can collect tasks, toggle them etc. That API seems more interesting for another plugin developer than a potential Tasks API since it has more capabilities - showing tasks is just a part of what dataview can do. And the best of it - it is already there =)

PS this is not to advertise dataview against Tasks. It is just that the described feature seems to be already implemented elsewhere.

@claremacrae
Copy link
Collaborator

I have written up some thoughts on this in #1646

If discussion could go there for now, that would keep all the comments in one place. Thanks.

@claremacrae
Copy link
Collaborator

Related: from the Tasks 2.0.0 release note:

🌟 Added new public API to retrieve markdown string for a new task via the 'Add or edit task' modal - thanks @3bit
Authors of other plugins can now use the Tasks modal to prompt users for data for a new task.
Feedback appreciated on this feature!
📖 https://obsidian-tasks-group.github.io/obsidian-tasks/advanced/api/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: for plugin developers Tools for use by plugin developers, including the Tasks API type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants