Skip to content

No code completion or signature suggestions for %run file.py magic #798

Open
@ianhellstrom

Description

@ianhellstrom

Description

When using an external file that is executed within a notebook with %run file.py, its imports and definitions are not available to the LSP for code completion or signature suggestions. This means that if common functionality is extracted into a common file and included in the notebook, the LSP's features are not as useful as they could be.

Reproduce

  1. Check that signature suggestions work out of the box in a notebook:

Screenshot 2022-05-04 at 10 07 59

  1. Create file two.py with the following contents:
import pandas as pd

def addtwo(i: int) -> int:
    return i + 2
  1. Execute the two.py file and notice that signature suggestions do not work for either the import or the function:

image

Expected behavior

If code is run inside a notebook, I expect code completion and signature suggestions to work. It is after all available to the notebook server.

Context

  • Operating System and version: MacOs 12.2
  • Browser and version: Chrome 100.0.4896.127
  • JupyterLab version: 3.3.4
  • Language server and version: 1.5.1 with jupyterlab-lsp 3.10.1
Required: installed server extensions
config dir: /Users/XXX/etc/jupyter
    jupyter_lsp  enabled
    - Validating...
      jupyter_lsp 1.5.1 OK
    jupyterlab  enabled
    - Validating...
      jupyterlab 3.3.4 OK
    jupyterlab_git  enabled
    - Validating...
      jupyterlab_git 0.37.1 OK
    nbdime  enabled
    - Validating...
      nbdime 3.1.1 OK
Required: installed lab extensions
JupyterLab v3.3.4
/Users/XXX/share/jupyter/labextensions
        jupyterlab_pygments v0.2.2 enabled OK (python, jupyterlab_pygments)
        nbdime-jupyterlab v2.1.1 enabled OK
        @krassowski/jupyterlab-lsp v3.10.1 enabled OK (python, jupyterlab-lsp)
        @jupyterlab/git v0.37.1 enabled OK (python, jupyterlab-git)

Other labextensions (built into JupyterLab)
app dir: /Users/XXX/share/jupyter/lab
@jupyterlab/celltags v3.3.4 enabled OK

Troubleshoot Output
$PATH:
	/Users/XXX/bin
	/usr/local/bin
	/usr/bin
	/bin
	/usr/sbin
	/sbin

sys.path:
/Users/XXX/bin
/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python39.zip
/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9
/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload
/Users/XXX/lib/python3.9/site-packages

sys.executable:
/Users/XXX/bin/python3.9

sys.version:
3.9.12 (main, Mar 26 2022, 15:51:15)
[Clang 13.1.6 (clang-1316.0.21.2)]

platform.platform():
macOS-12.3-x86_64-i386-64bit

which -a jupyter:
/Users/XXX/bin/jupyter

pip list:
Package Version
----------------------------- -----------
anyio 3.5.0
appdirs 1.4.4
appnope 0.1.3
argon2-cffi 21.3.0
argon2-cffi-bindings 21.2.0
astroid 2.11.3
asttokens 2.0.5
attrs 21.4.0
Automat 20.2.0
autopep8 1.6.0
Babel 2.10.1
backcall 0.2.0
beautifulsoup4 4.9.3
black 21.7b0
bleach 5.0.0
blis 0.7.7
cachetools 4.2.4
catalogue 2.0.7
certifi 2021.10.8
cffi 1.15.0
charset-normalizer 2.0.12
click 7.1.2
colorama 0.4.4
constantly 15.1.0
cryptography 37.0.0
cssselect 1.1.0
cycler 0.11.0
cymem 2.0.6
debugpy 1.6.0
decorator 5.1.1
defusedxml 0.7.1
dill 0.3.4
docker 5.0.3
english 2020.7.0
entrypoints 0.4
et-xmlfile 1.1.0
executing 0.8.3
fastjsonschema 2.15.3
flake8 4.0.1
gitdb 4.0.9
GitPython 3.1.27
google-api-core 2.7.2
google-auth 1.34.0
google-auth-oauthlib 0.5.1
google-cloud-bigquery 2.34.3
google-cloud-bigquery-storage 2.13.1
google-cloud-core 2.3.0
google-crc32c 1.3.0
google-resumable-media 2.3.2
googleapis-common-protos 1.56.0
gower 0.0.5
grpcio 1.44.0
grpcio-status 1.44.0
h5py 3.6.0
hyperlink 21.0.0
idna 3.3
importlib-metadata 4.11.3
incremental 21.3.0
ipykernel 6.13.0
ipython 8.2.0
ipython-genutils 0.2.0
isort 5.10.1
jedi 0.18.1
Jinja2 3.1.1
joblib 1.1.0
json5 0.9.6
jsonschema 4.4.0
jupyter-client 7.3.0
jupyter-core 4.10.0
jupyter-lsp 1.5.1
jupyter-server 1.16.0
jupyter-server-mathjax 0.2.5
jupyterlab 3.3.4
jupyterlab-git 0.37.1
jupyterlab-lsp 3.10.1
jupyterlab-pygments 0.2.2
jupyterlab-server 2.13.0
Keras 2.4.3
kiwisolver 1.4.2
lazy-object-proxy 1.7.1
lxml 4.8.0
MarkupSafe 2.1.1
matplotlib 3.4.2
matplotlib-inline 0.1.3
mccabe 0.6.1
mistune 0.8.4
monotonic 1.6
murmurhash 1.0.7
mypy-extensions 0.4.3
nbclassic 0.3.7
nbclient 0.6.0
nbconvert 6.5.0
nbdime 3.1.1
nbformat 5.3.0
neotime 1.7.4
nest-asyncio 1.5.5
nltk 3.6.2
notebook 6.4.11
notebook-shim 0.1.0
numpy 1.21.1
oauthlib 3.2.0
openpyxl 3.0.9
packaging 21.3
pandas 1.3.1
pandas-gbq 0.15.0
pandocfilters 1.5.0
pansi 2020.7.3
parso 0.8.3
pathspec 0.9.0
pathy 0.6.1
patsy 0.5.2
pexpect 4.8.0
pickleshare 0.7.5
Pillow 9.1.0
pip 22.0.3
platformdirs 2.5.0
pluggy 1.0.0
preshed 3.0.6
prometheus-client 0.14.1
prompt-toolkit 3.0.29
proto-plus 1.20.3
protobuf 3.20.1
psutil 5.9.0
ptyprocess 0.7.0
pure-eval 0.2.2
py2neo 2021.1.5
pyarrow 7.0.0
pyasn1 0.4.8
pyasn1-modules 0.2.8
pycodestyle 2.8.0
pycparser 2.21
pydantic 1.8.2
pydata-google-auth 1.4.0
pydocstyle 6.1.1
pyflakes 2.4.0
Pygments 2.12.0
pylint 2.13.7
pyOpenSSL 22.0.0
pyparsing 3.0.8
pyrsistent 0.18.1
python-dateutil 2.8.2
python-lsp-jsonrpc 1.0.0
python-lsp-server 1.4.1
pytz 2022.1
PyYAML 6.0
pyzmq 22.3.0
queuelib 1.6.2
regex 2022.4.24
requests 2.26.0
requests-oauthlib 1.3.1
rope 1.0.0
rsa 4.8
scikit-learn 0.24.2
scipy 1.7.1
Scrapy 1.0.1
seaborn 0.11.1
Send2Trash 1.8.0
setuptools 60.5.0
six 1.16.0
smart-open 5.2.1
smmap 5.0.0
sniffio 1.2.0
snowballstemmer 2.2.0
soupsieve 2.3.2.post1
spacy 3.1.1
spacy-legacy 3.0.9
srsly 2.4.3
stack-data 0.2.0
statsmodels 0.12.2
terminado 0.13.3
thinc 8.0.15
threadpoolctl 3.1.0
tikzplotlib 0.9.15
tinycss2 1.1.1
toml 0.10.2
tomli 1.2.3
tornado 6.1
tqdm 4.62.0
traitlets 5.1.1
Twisted 22.4.0
typer 0.3.2
typing_extensions 4.1.1
ujson 5.2.0
urllib3 1.26.9
w3lib 1.22.0
wasabi 0.9.1
wcwidth 0.2.5
webencodings 0.5.1
websocket-client 1.3.2
wrapt 1.14.0
yapf 0.32.0
zipp 3.8.0
zope.interface 5.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions