python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.76k stars 186 forks source link

Odd completion behavior within comments #411

Open efroemling opened 11 months ago

efroemling commented 11 months ago

I recently upgraded to Emacs 29 and got eglot wired up with python-lsp-server within python-ts-mode for my project. Everything is mostly super awesome compared to my old pure-flycheck setup. There's just one bit of odd behavior I'm seeing that I wanted to ask about:

Whenever I type a dot within a comment, I get a completion pop-up. Outside of comments a lone dot won't trigger a completion, and I get correct type based completions after other stuff.

Screenshot 2023-08-01 at 12 55 15 PM

Is this expected behavior? I tend to use complete sentences in my comments and this is leading to lots of comments accidentally ending in '.ArithmeticError' instead of '.' 😬

ccordoba12 commented 11 months ago

Dots are trigger characters for completions in Python, as declared here:

https://github.com/python-lsp/python-lsp-server/blob/714a5829192133f5fd7813a099741c580338c0bd/pylsp/python_lsp.py#L245

And in this case completions are requested because you have a dot right next to a # (I guess if it's separated by a space, then you shouldn't see that).

However, I think you need to report this error to the eglot maintainers so that completions are not requested in comments.

krassowski commented 11 months ago

Counter-point: when triggerKind is TriggerCharacter server should ideally only return completions if the context makes sense (i.e. not after a dot occurring just after a comment).

ccordoba12 commented 11 months ago

Sure, that's a good point. But my guess is that that is not the only scenario that triggers completions in eglot. I guess this should return them too:

foo = 1

# foo.

@efroemling, could you check that?

efroemling commented 10 months ago

@ccordoba12 Here you go: (apologies for the slow response; was out on vacation)

The 'foo' test above does give me the same global completion popup.

Screenshot 2023-08-23 at 5 01 39 PM

Perhaps interestingly, I'm also getting the same for simply a dot preceded by a space.

Screenshot 2023-08-23 at 5 03 17 PM

Though I'm not getting completions for a dot (with or without spaces) without the comment.

Screenshot 2023-08-23 at 5 04 55 PM

Does this seem like it would fall under the python-lsp-server umbrella or should I ping the eglot folks?

efroemling commented 3 months ago

Just shaking the tree here, as this is still happening for me as of Emacs 29.3 with python-lsp-server 1.11.0 running through eglot.

TLDR: If I type # This is a comment. or even just #. I always get a completion pop-up for the period. That doesn't seem right.

Typing This is not a comment. does not give me a completion pop-up for the period unless 'comment' has been defined as a variable. That seems right.

Any other Emacs folks out there experiencing the same behavior? And is this something that should be fixed here or on the eglot end?