Skip to content

Autocompletion of Plotly code not working in Visual Studios #3563

Closed
@Coding-with-Adam

Description

@Coding-with-Adam

This issue is regarding autocompletion of Plotly code not working in Visual Studios. This was reported to [email protected] by @yankee on the Plotly Forum.

Just to get it out of the way, here are my list of installed packages in the virtual environment I use for data analysis:

$ pip freeze
altair==4.2.0
ansi2html==1.6.0
anyio==3.4.0
appdirs==1.4.4
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
astroid==2.9.1
asttokens==2.0.5
attrs==21.2.0
autopep8==1.6.0
Babel==2.9.1
backcall==0.2.0
black==21.12b0
bleach==4.1.0
Brotli==1.0.9
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.9
chart-studio==1.1.0
click==8.0.3
colorlover==0.3.0
cufflinks==0.17.3
cycler==0.11.0
dash==2.0.0
dash-core-components==2.0.0
dash-html-components==2.0.0
dash-table==5.0.0
dataclasses==0.6
DateTime==4.3
debugpy==1.5.1
decorator==5.1.0
defusedxml==0.7.1
dparse==0.5.1
entrypoints==0.3
executing==0.8.2
flake8==4.0.1
Flask==2.0.2
Flask-Compress==1.10.1
fonttools==4.28.5
idna==3.3
importlib-metadata==4.10.0
ipykernel==6.6.0
ipython==8.0.1
ipython-genutils==0.2.0
ipywidgets==7.6.5
isort==5.10.1
itsdangerous==2.0.1
jedi==0.18.1
Jinja2==3.0.3
json5==0.9.6
jsonschema==4.3.2
jupyter-client==7.1.0
jupyter-contrib-core==0.3.3
jupyter-contrib-nbextensions==0.5.1
jupyter-core==4.9.1
jupyter-dash==0.4.0
jupyter-highlight-selected-word==0.2.0
jupyter-latex-envs==1.4.6
jupyter-nbextensions-configurator==0.4.1
jupyter-server==1.13.3
jupyterlab==3.2.8
jupyterlab-pygments==0.1.2
jupyterlab-server==2.9.0
jupyterlab-widgets==1.0.2
kiwisolver==1.3.2
lazy-object-proxy==1.7.1
lxml==4.7.1
MarkupSafe==2.0.1
matplotlib==3.5.1
matplotlib-inline==0.1.3
mccabe==0.6.1
mistune==0.8.4
mypy==0.931
mypy-extensions==0.4.3
nbclassic==0.3.4
nbclient==0.5.9
nbconvert==6.3.0
nbformat==5.1.3
nest-asyncio==1.5.4
notebook==6.4.6
notebook-as-pdf==0.5.0
numpy==1.22.1
packaging==21.3
pandas==1.3.5
pandocfilters==1.5.0
parso==0.8.3
pathspec==0.9.0
pexpect==4.8.0
pickleshare==0.7.5
Pillow==8.4.0
platformdirs==2.4.1
plotly==5.5.0
prometheus-client==0.12.0
prompt-toolkit==3.0.24
ptyprocess==0.7.0
pure-eval==0.2.1
pycodestyle==2.8.0
pycparser==2.21
pyee==8.2.2
pyflakes==2.4.0
Pygments==2.10.0
pylint==2.12.2
Pympler==1.0.1
pyparsing==3.0.6
PyPDF2==1.26.0
pyppeteer==0.2.6
pyrsistent==0.18.0
python-dateutil==2.8.2
pytz==2021.3
PyYAML==6.0
pyzmq==22.3.0
requests==2.26.0
retrying==1.3.3
rope==0.22.0
safety==1.10.3
scipy==1.7.3
seaborn==0.11.2
Send2Trash==1.8.0
six==1.16.0
sniffio==1.2.0
stack-data==0.1.3
tabulate==0.8.9
tenacity==8.0.1
terminado==0.12.1
testpath==0.5.0
toml==0.10.2
tomli==1.2.3
toolz==0.11.2
tornado==6.1
tqdm==4.62.3
traitlets==5.1.1
typing==3.7.4.3
typing_extensions==4.0.1
urllib3==1.26.7
vega-datasets==0.9.0
wcwidth==0.2.5
webencodings==0.5.1
websocket-client==1.2.3
websockets==9.1
Werkzeug==2.0.2
widgetsnbextension==3.5.2
wrapt==1.13.3
zipp==3.7.0
zope.interface==5.4.0

Before capturing any gif images for you to pass on to your team, I wanted to experiment a bit with my IDE settings and extensions to rule out any issues they might be causing. Basically make sure that I have a coherent development environment.

There are 2 extensions I uninstalled so that they wouldn't interfere with the built-in code completion feature:

Tabnine especially was interfering with the code completion, because it uses algorithms that provide code completion suggestions based on code you've already typed. So it artificially makes it seem like code completion is working, when actually it is not.

So in the end, here is the complete list of extensions I have installed:

$ code --list-extensions 
batisteo.vscode-django
donjayamanne.python-environment-manager
donjayamanne.python-extension-pack
James-Yu.latex-workshop
janisdd.vscode-edit-csv
KevinRose.vsc-python-indent
mechatroner.rainbow-csv
ms-azuretools.vscode-docker
ms-python.python
ms-python.vscode-pylance
ms-toolsai.jupyter
ms-toolsai.jupyter-keymap
ms-toolsai.jupyter-renderers
ms-vscode-remote.remote-containers
ms-vscode.cpptools
njpwerner.autodocstring
qwtel.sqlite-viewer
vscode-icons-team.vscode-icons
wholroyd.jinja

I suspect that the only extensions in this list which could/should ever have an impact on code completion are

ms-python.python
ms-python.vscode-pylance

Here are my userspace settings:

{
    "python.pythonPath": "/home/ed/.venv/data_analysis3.10.1/bin/python",
    "python.formatting.provider": "autopep8",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    },
    "python.linting.enabled": true,
    "python.linting.mypyEnabled": true,
    "python.linting.mypyArgs": [
        "--follow-imports=silent",
        "--ignore-missing-imports",
        "--show-column-numbers",
        "--no-pretty",
        "--show-error-codes"
    ],
    "python.linting.flake8Enabled": true,
    "python.linting.flake8CategorySeverity.F": "Warning",
    "python.linting.flake8Args": [
        "--ignore=E501,W503"
    ],
    "python.linting.pylintEnabled": true,
    "python.languageServer": "Pylance"
}

Especially on the last line, the language server is a setting I wanted to play with. I think this setting has a strong impact on the way code completion behaves, because I think it is the language server that does the parsing of the pip package stubs and actually displays your code completion suggestions. But I'm not 100% sure on that.

vscode lets you choose from the following list of language servers:
image

I am going to compare Pylance's behavior with Jedi.

Pylance (the default in vscode) is the one I was using when I complained to you about this code completion issue. Code completion works well for code and classes/modules I've written, default Python libraries, and pip installed Python libraries--except for Plotly.

Here it is completing a list of member methods and attributes for a class I wrote.
image
If I add a docstring to these functions, it also autocompletes for that:
image

It auto completes well for some essential pip-installed packages as well, even when you don't use type hinting to help the IDE understand the type:
image

However, it does not autocomplete for Plotly basically at all, or at least not with the classes I'm trying to use, even when using type hinting:
image

I'm out of time for now, but will explore Jedi later to see if that language server behaves any better. Who knows, maybe this is a Pylance problem? But I wouldn't think so since it works fine with everything else. Hopefully I've documented this thoroughly enough to be useful to your team.

EDIT: If I had to guess, maybe Pylance language server cannot provide suggestions, because it cannot resolve the type of this fig object? If I hover over the type hint I wrote when I declared and defined fig, you can see that it can be one of several types:
image

So fig can wind up being of type Any, of type ModuleType, or of type Type[FigureWidget]. Perhaps Pylance just does not know what to do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions