pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Dictionary Intellisense only works with two sets of brackets in Jupyter Notebooks

Open sharkweek opened this issue 3 years ago • 7 comments

Description

Intellisense seems to require a second set of brackets to autocomplete Python dictionary keys. The issue is only happening for me in Jupyter Notebooks. Autocomplete works as intended if editing a standard py file.

Expected behaviour

The Intellisense autocomplete should kick in as soon as the opening bracket of a dictionary indexer is typed.

Actual behaviour

Autocomplete will only trigger when a second bracket is typed. This would, unfortunately, produce a TypeError for passing a list to the indexer.

Screen Shot 2022-02-14 at 5 01 09 PM

Screen Shot 2022-02-14 at 5 00 10 PM

Environment data

VS Code

  • Version: 1.64.2
  • Commit: f80445acd5a3dadef24aa209168452a3d97cc326
  • Electron: 13.5.2
  • Chromium: 91.0.4472.164
  • Node.js: 14.16.0
  • V8: 9.1.269.39-electron.0
  • OS: Darwin x64 21.1.0

Jupyter/Python

  • Language Server: Pylance
  • Jupyter Extension version: v2022.1.1201831736
  • Python Extension version: v2022.0.1814523869
  • OS and version: MacOSX 12.0.1
  • Python and/or Anaconda version: 3.9.7
  • Type of virtual environment used: conda
  • Jupyter server running: Local

sharkweek avatar Feb 15 '22 01:02 sharkweek

I believe this would be entirely handled by pylance?

rchiodo avatar Feb 15 '22 01:02 rchiodo

When you type the first square bracket character (after the x) do you see the following completion suggestions? Or are you seeing something different?

Screen Shot 2022-02-14 at 5 28 53 PM

If the completion suggestion popup doesn't appear for you automatically after typing the square bracket, what happens if you manually trigger it to appear by pressing control-space?

erictraut avatar Feb 15 '22 01:02 erictraut

A single square bracket does nothing and ctrl+space only brings up the list of global variables.

This only occurs in notebooks, though. Python files work just like your screenshot. This is why I am unsure that it is Pylance. I assume I should expect the same behavior in both py files and Jupiter notebooks if so.

sharkweek avatar Feb 15 '22 01:02 sharkweek

Has there been any movement on this?

sharkweek avatar Mar 10 '22 18:03 sharkweek

Commenting out the set of completionItem.textEdit in _addStringLiteralToCompletions causes the completions to appear. I'm not sure why or if that's the correct fix. Figured this out by comparing _addStringLiteralToCompletions against _addNameToCompletions which is the code path used in the double bracket part of the repro steps.

debonte avatar Apr 06 '22 23:04 debonte

Hi, are there any updates?

Kind of the only thing needed for me to switch to VSCode completely...

pukhov avatar May 29 '22 15:05 pukhov

@sharkweek @pukhov, looks like this works correctly after opting into the notebooks experiment that we shipped in Pylance 2022.5.3.

Give it a try:

  1. Use VS Code Insiders
  2. Install the latest Pre-Release builds of the Python and Jupyter extensions.
  3. Install latest Pylance build. Either stable or insiders, your choice.
  4. Set "python.pylanceLspNotebooksEnabled": true
  5. Reload VS Code.

cc: @luabud

debonte avatar May 31 '22 17:05 debonte

We're closing this issue since it is fixed when python.pylanceLspNotebooksEnabled is set to true and as of Python extension version 2022.14.0 that is now the default.

If you are setting python.pylanceLspNotebooksEnabled to false, we would like to understand why. Please file an issue.

debonte avatar Sep 08 '22 05:09 debonte