Shell completion fails for option values that start with symbols

Running into the same case as #1929, except specific to option values that may start with symbols such as '+', '~', and '!'. Shell completion treats these values as the start of new options, so doesn't complete them.

Reproduction script with the cli command referenced by setuptools:

@command()
@option("-c", type=Choice(["+1", "+2", "!1", "!2"]))
def cli(c):
    echo(f"Value is {c}")

With shell completion enabled:

$ click-bug -c <TAB><TAB>
+1 +2  !1 !2
$ click-bug -c +<TAB><TAB>
# Nothing happens

I was looking at the discussion on #1930, and it makes sense that '+' may be considered the start of an option. I'm wondering if it would be valid for completion to prioritize option values over new option names. As in, within shell_completion.py's _resolve_incomplete function, moving the _is_incomplete_option check above the if "--" not in args and _start_of_option(incomplete) call allows the tab completion in this example to work as expected:

$ click-bug -c +<TAB><TAB>
+1 +2

I can look into putting up a PR to do that if it seems valid.

Environment:

  • Python version: 3.6.9
  • Click version: 8.0.1