wide-midnight-7859803/19/2023, 5:49 AM
time is just too slow.
Instead, for those who have
installed, I've tried yet more slightly different. I call
and cache the resulting JSON using the md5 of the pants.toml file. I then check that md5 on completion, and pull the giant json file back in to use
to parse. This won't work for nested
usage, unfortunately. Also, this ends up being too slow to use for parsing all the scoped options from all the keys in the JSON (at least, using a naive for loop approach - I think
has a syntax for what I'm trying to do, but I haven't dug into the manual yet). Either way, for this approach, it's probably worth just doing a one-time parse and caching all the results somewhere, until the pants.toml MD5 changes, and then it would be super fast (rather than re-parsing a huge JSON file all the time).
call or something, which could dynamically return appropriate values back to the completions.
Another option is keeping this generic-style completion file, and when Pants runs, it automatically exports a parsed help-all json to a Pants-controlled location per repo, and the bash script would know by convention to look there 🤷
fast-nail-5540003/19/2023, 10:04 AM
Either way, for this approach, it's probably worth just doing a one-time parse and caching all the results somewhere, until the pants.toml MD5 changes, and then it would be super fast (rather than re-parsing a huge JSON file all the time).Which was the approach taken by the Pants v1 shell completion support. The options config was converted to be shell code and then the shell completion function could just consult shell variables to determine what the completions were.
wide-midnight-7859803/19/2023, 1:29 PM
idea. I think that would be slick, and extensible, and not require any 3rd party tooling
at some point
proud-dentist-2284403/20/2023, 5:37 PM
wide-midnight-7859803/20/2023, 6:08 PM
witty-crayon-2278603/20/2023, 6:14 PM
Is there an API the completions stuff could use to query pantsd?`pantsd`’s only interface at the moment is CLI invokes. the actual runtime of: 1. starting the native client from https://github.com/pantsbuild/pants/pull/11922 2. connecting to a server … should be sub 50 ms though. most of the overhead when using 11922 is in options parsing and bootstrapping.
fast-nail-5540003/20/2023, 7:45 PM
`pantsd`’s only interface at the moment is CLI invokes.It need not be given the Build Server Protocol support demonstrates Pants can function as a request/response server as well.
witty-crayon-2278603/20/2023, 7:46 PM
fast-nail-5540003/20/2023, 7:46 PM
listens on a UNIX domain socket under BUILDROOT/.pants.d for requests and then invokes an uncached rule to get the result.
witty-crayon-2278603/20/2023, 7:48 PM
fast-nail-5540003/20/2023, 7:49 PM
and similar tools do
and completion support could just pick it up directly without any API or other extra stuff
wide-midnight-7859803/20/2023, 8:49 PM
- performance was perfectly adequate. The ideal world for that would be as you described, where
(or whatever) automatically writes out the completions, or caches help, whenever the pants.toml changes. I think that was the hope in one of the more recent tickets on this topic. I think back in the day, I also talked about the idea of the
script auto-sourcing a completions script as well - which was a bit more 🤷 .