Incorrect handling of quoted & escaped parameters for Fish completions

Completions for parameters in quotes, partially quoted or with escaped characters (e.g. whitespace) don't work properly for Fish shell.

I believe the issue is that for fish completion, the incomplete paramater is passed through the COMP_CWORD environment variable and it's expected that it will be contained in COMP_WORDS as the last parameter. However, before doing this match COMP_WORDS is parsed, which quotes and unescapes the parameters, while COMP_CWORD is not causing the match to fail. See code here.

How to replicate

Consider the following command

@click.command()
@click.argument('bar', type=click.Choice(('hello world',)))
def main(bar: str):
    pass

Trying to complete foo hello in Fish will correctly return completion for foo hello\ world.

The following incomplete commands will not return any completions

  • foo hello\
  • foo "hello
  • foo "hello"

Environment:

  • Python version: 3.13.5
  • Click version: 8.2.1