Difficulty of autocomplete generation? #189
Replies: 2 comments
-
Glad to hear you're enjoying the source generator addition.
Not at all and to be perfectly honest, I have never really investigated how that's accomplished for various shells. It's also not an itch I have to do scratch so far.
I wasn't either when I added the source generator piece and it took many sittings spread throughout a year! I had to get familiar with the existing code and then figure out a way to add the source generator version without breaking any existing code relying on previous versions. It wasn't easy and required a careful set of refactorings so I wouldn't underestimate the effort. Since the C# version was a pretty mechanical port of the Python version, I sometimes even consulted the latter since everything didn't translate over idiomatically. That said, I am a lot more familiar with the code and I can try guide a bit, but I am not sure if that's what you're looking for here. In essence, the parser builds a tree of branch patterns that lead to leaf nodes like command, option and argument. The branch nodes are rules like required, optional and so on: docopt.net/src/DocoptNet/Internals/BranchPatterns.cs Lines 109 to 135 in 1428fff From this, you can try and prototype what the code for completion could look like to get an idea of the effort. Taking the canonical Naval Fate example:
The parsed tree for the above docopt looks like the following pseudo object representation in memory:
During parsing of actual command-line arguments, matchers are used to execute the branch node rules until the leaves are encountered and value(s) established. I guess in the case of completion, you'd see how far you got into the tree and what are possible set of suggestions to offer. Hope this helps as a starting point. |
Beta Was this translation helpful? Give feedback.
-
Thank you for this detailed help, this is a great head start. :) |
Beta Was this translation helpful? Give feedback.
-
Hi @atifaziz - I've been loving this library and especially the new sourcegen you added. Works great, thank you. :)
Have you considered what it might take to have an autocomplete feature?
I've seen two styles so far - something like starship where you give an
init
command and a shell type and it feeds back code to add to the session. The other style is like dotnet where you run acomplete
command with the command line so far and it does all the work.I'd like to support autocomplete for powershell and bash/zsh in my own cli app, and am considering the best way to do it. Seems like integrating into the docopt parsing would be best, though I'm totally unfamiliar with that code.
Beta Was this translation helpful? Give feedback.
All reactions