jupyter-lsp / jupyterlab-lsp

Coding assistance for JupyterLab (code navigation + hover suggestions + linters + autocompletion + rename) using Language Server Protocol
https://jupyterlab-lsp.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.81k stars 149 forks source link

Handling Kernel completion items #603

Open lsopotnitskiy opened 3 years ago

lsopotnitskiy commented 3 years ago

Hi Michał, this is a great extension, thank you very much for creating it. I was unable to find any thread here that would explicitly suggest how to set rules for the code completion of kernel items. The issue described here results in a problematic UX scenario.

Consider this problem. The kernel completion is enabled, and I am using continuous hinting. Now if I try importing pandas via the statement as shown in the screenshot, the resulting UX is not seamless: image

As you can see, in this instance I am trying to call the imported pandas module "pd", but the completion suggests some magic function %pdb, in which case if I hit the "return" key, it will override my variable name.

I do not want to turn off kernel completion, as it does have many useful features, like looking into DataFrame columns, etc. But is there a way to manipulate the suggestion priority, ignore certain entity types (e.g. exclude files from the suggested results)? Any advice would be very welcome!

krassowski commented 3 years ago

Thank you for bringing it up, it is a very good timing - we are just thinking about improving completion and making it more customisable. This is a difficult one because we are language agnostic and the editor's (CodeMirror) tokenizer does not treat the "pd" part as anything special (it tags it ust as a "variable") so we cannot just filter out kernel completions conditionally.

It should be possible to modify IPython's completer to teach it that suggesting magics and file names in this place is not appropriate and it should not do it; it has means to do that. I think that it would be best addressed upstream, because it does also happen when this extension is not installed (and completion is triggered by tab), CC @Carreau:

Screenshot from 2021-05-20 13-28-47

Obviously it is more apparent when you use this extension because we provide continuous hinting feature; I fully appreciate how annoying it can be in the result.

Would making a PR upstream to IPython (or opening issue) be something that you would be interested in @lsopotnitskiy?

Cross-ref: https://github.com/krassowski/jupyterlab-lsp/issues/495

lsopotnitskiy commented 3 years ago

Thanks for your prompt reply. Sure, I can share this issue with IPython.

lsopotnitskiy commented 3 years ago

Adding one more scenario for your consideration: image

FYI, I have shared the issue on IPython, given the amount of other posts that are made there, not sure if this one will even get noticed.

By the way, for the 1st issue with importing, would your Completion settings items "suppressContinuousHintingIn" or "suppressTriggerCharacterIn" be of any use here? Is there a way to reference the "as" keyword somehow?

krassowski commented 3 years ago

FYI, I have shared the issue on IPython, given the amount of other posts that are made there, not sure if this one will even get noticed.

Could you post a link here please?

By the way, for the 1st issue with importing, would your Completion settings items "suppressContinuousHintingIn" or "suppressTriggerCharacterIn" be of any use here? Is there a way to reference the "as" keyword somehow?

Sadly not in this particular case because the CodeMirror tokenizer labels y in import x as y as "variable". If it labelled it as something specific, like "as_import_variable" (which it does not) then it would be an option. I originally hoped it would be so easy but it is not.

lsopotnitskiy commented 3 years ago

Thank you the reply! Sure, here it is: https://github.com/ipython/ipython/issues/12987