Shell completions for tasks in `deno task`?
Would it be possible to do shell completions for tasks in deno task? I'm unfamiliar with how shell completions work.
From #14036
it should be possible, i havent looked into this aspect of clap (and completions) yet
@mcornella, do you know if zsh (and friends), have the capability of "dynamic" completions?
@mcornella, do you know if zsh (and friends), have the capability of "dynamic" completions?
I use zsh and git seems to be having dynamic completions based on the current working directory:
git branch [tab] autocompletes with all the available branches.
I do wonder how that works though. Is the completion system given a specific command to run to get a list? as it cant just magically know, there must be some logic.
Shell completions scripts are just written as a bash script function, you can dynamically execute anything in that context to determine what the tab completion should be. The problem is clap doesn't have a feature which allows us to inject custom logic there (https://github.com/clap-rs/clap/issues/1232). It has https://docs.rs/clap/3.1.6/clap/enum.ValueHint.html for basic things like "complete with a file path here" but deno task <entry-in-deno.jsonc> would need something custom.
@nayeemrmn perfect, thats what i wanted to know. tbh, i'd be against doing something custom, we should rather wait for clap.
The main issue I mentioned in #14036 was paths not autocompleting after deno task. Completing from the list of tasks in the config would certainly be nice, but maybe it would be possible to add file path completions in the mean time?
i'd be against doing something custom, we should rather wait for clap.
To clarify by "custom" I didn't mean bypassing clap (no idea where we'd even start) I meant the clap feature to inject custom logic beyond the ValueHint presets.
Yea, I am aware, it doesnt seem ideal to go down that route
Yea, I am aware, it doesnt seem ideal to go down that route
The route of https://github.com/clap-rs/clap/issues/1232? Still not sure we're clear, that part is fundamental to implementing this (i.e. clap won't have an inbuilt feature to scan upwards for a deno.jsonc and look at the "tasks" field or something).
hm, yea i misunderstood something at one point, my bad (and yea, obviously clap itself wouldnt be able to do that scan for the tasks field)
npm has this functionality, so I'm pretty sure we'd be able to implement it too.
Refs:
- https://docs.npmjs.com/cli/v8/commands/npm-completion
- https://github.com/npm/cli/blob/latest/lib/utils/completion.sh
- https://github.com/npm/cli/blob/latest/lib/commands/completion.js
Yea, it is definitively doable
npmhas this functionality, so I'm pretty sure we'd be able to implement it too.
They maintain their own completion script generation, we would have to drop clap and do the same or wait a long time.
Adding this would definitely make my mission (which is "converting as many in-house teams as possible from node to deno") much easier. Folks working with npm are used to having this functionality, and consider not having it an adoption blocker.
Since there is clap_complete::engine::ArgValueCompleter, we can implement this feature!
Any update on this issue? This would greatly improve my day-to-day experience with Deno
+1
+1
+1