jazzband / Watson

:watch: A wonderful CLI to track your time!
http://tailordev.github.io/Watson/
MIT License
2.46k stars 240 forks source link

Fix completions broken since click>=8 #473

Open voidus opened 2 years ago

voidus commented 2 years ago

Quoting click changelog for 8.0.0

The env var values used to start completion have changed order. The shell now comes first, such as {shell}source rather than > source{shell}, and is always required.

I think this fix warrants a 2.1.1 release, since missing completions are kind of a big deal for a lot of people. (Shamelessly generalizing from my experience)

voidus commented 2 years ago

Having some other issues with completion:

    from watson.__main__ import cli
  File "/nix/store/0qj8zhf7pklvwcq3ix60pa3cb9vcdcly-watson-2.1.0/lib/python3.9/site-packages/watson/__main__.py", line 3, in <module>
    cli.cli()
  File "/nix/store/ali8g6rx2lj3kb15lwxkp0d2ny0dihmz-python3.9-click-8.1.3/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/nix/store/ali8g6rx2lj3kb15lwxkp0d2ny0dihmz-python3.9-click-8.1.3/lib/python3.9/site-packages/click/core.py", line 1050, in main
    self._main_shell_completion(extra, prog_name, complete_var)
  File "/nix/store/ali8g6rx2lj3kb15lwxkp0d2ny0dihmz-python3.9-click-8.1.3/lib/python3.9/site-packages/click/core.py", line 1125, in _main_shell_completion
    rv = shell_complete(self, ctx_args, prog_name, complete_var, instruction)
  File "/nix/store/ali8g6rx2lj3kb15lwxkp0d2ny0dihmz-python3.9-click-8.1.3/lib/python3.9/site-packages/click/shell_completion.py", line 49, in shell_complete
    echo(comp.complete())
  File "/nix/store/ali8g6rx2lj3kb15lwxkp0d2ny0dihmz-python3.9-click-8.1.3/lib/python3.9/site-packages/click/shell_completion.py", line 291, in complete
    completions = self.get_completions(args, incomplete)
  File "/nix/store/ali8g6rx2lj3kb15lwxkp0d2ny0dihmz-python3.9-click-8.1.3/lib/python3.9/site-packages/click/shell_completion.py", line 273, in get_completions
    return obj.shell_complete(ctx, incomplete)
  File "/nix/store/ali8g6rx2lj3kb15lwxkp0d2ny0dihmz-python3.9-click-8.1.3/lib/python3.9/site-packages/click/core.py", line 2397, in shell_complete
    results = self._custom_shell_complete(ctx, self, incomplete)
  File "/nix/store/0qj8zhf7pklvwcq3ix60pa3cb9vcdcly-watson-2.1.0/lib/python3.9/site-packages/watson/autocompletion.py", line 51, in get_project_or_task_completion
    tok.startswith("+") for tok in args + [incomplete]
TypeError: unsupported operand type(s) for +: 'Argument' and 'list'

so I'll mark this WIP for now

jmaupetit commented 2 years ago

Thanks you for this @voidus :pray: Keep it up :muscle:

voidus commented 2 years ago

Okay this was a bit of a ride, I ended up mostly rewriting the completion.

I started implementing it while respecting the multi-word features (that is, being able to enter watson add my cool project +and a tag +another tag without putting quotes, but there are so many edge cases it's crazy.

Finally, I ended up ignoring it, because it was not consistently supported anyways. Both as a developer and a user, I would advise to officially drop that feature.

But that's not the point here. It would be great if you could have a look and let me know what you think, I ended up changing more than I planned.

voidus commented 2 years ago

squashed the two commits

voidus commented 2 years ago

@jmaupetit could you have a look please?

soltysh commented 1 year ago

@voidus @jmaupetit any chance to get this in?

voidus commented 1 year ago

I also added this patch to https://github.com/nixos/nixpkgs so I have it installed cleanly, so I'm not in a personal rush but I'm very much up to working in any requested changes.

voidus commented 1 year ago

Rebased on main, no change was needed

soltysh commented 1 year ago

I've just downloaded this locally and it looks like it's fixing the problems described in #477.

sluedecke commented 1 year ago

Works fine (and finally again) for me. Completions are hard, but very useful to me. Please include in upstream!

Igetin commented 1 year ago

@jmaupetit Any chance to review and merge this in?

voidus commented 1 year ago

If jmaupetit isn't available, maybe @willdurand could you have a look? This seems to affect multiple people.

amsesk commented 1 year ago

I will add myself to the list of affected people who would like to see this merged. Happy New Year!

ivan-volnov commented 1 year ago

@voidus Thank you very much! Used your version of watson.zsh-completion and the completion is working again!

Please finish the PR.

UPD: Works with errors. But works. Waiting for this PR

voidus commented 1 year ago

FYI, I've stopped using watson. I'd still be happy to tweak this PR if it needs additional work but I won't push for it to be merged.

Igetin commented 1 year ago

I’ve been using this branch directly, since it isn’t merged into master yet. I’ve done this for months now and noticed no problems with it.

FYI, I've stopped using watson. I'd still be happy to tweak this PR if it needs additional work but I won't push for it to be merged.

Off-topic, but I’m curious: did you switch to some other tool for time tracking? Watson does its job, but I’d rather use something that is actually maintained.