Closed jabbera closed 2 years ago
I have set up the .lsp_symlinks
to point to /home and /usr. The OS is debian-11.
Installing all as a private conda environment:
jupyterlab 3.1.9 and lsp from conda-forge
I can't access python modules located next to the notebook. "No jump targets found.", as described above.
I also fail to access python library modules, e.g. csv
.
Furthermore, the python library filename is changed from csv.py
to csv.py (external)
- which corrupts the conda based python installation. :scream:
Installing all as a venv using the system's python3.9:
The behaviour changes, when trying to reproduce the findings with a venv environment.
An editor window appears with the csv.py
and the jupyter-lab logs show
[W 2021-09-05 11:31:44.418 ServerApp] 403 GET /api/contents/.lsp_symlink/usr/lib/python3.9/csv.py/checkpoints?1630798304412 (::1) 2.10ms referer=http://localhost:8888/lab/tree/.lsp_symlink/usr/lib/python3.9/csv.py
[W 2021-09-05 11:31:44.464 ServerApp] 403 GET /api/contents/.lsp_symlink/usr/lib/python3.9/csv.py/checkpoints?1630798304450 (::1): Permission denied: .lsp_symlink/usr/lib/python3.9/.ipynb_checkpoints
[W 2021-09-05 11:31:44.465 ServerApp] Permission denied: .lsp_symlink/usr/lib/python3.9/.ipynb_checkpoints
[W 2021-09-05 11:31:44.466 ServerApp] 403 GET /api/contents/.lsp_symlink/usr/lib/python3.9/csv.py/checkpoints?1630798304450 (::1) 3.33ms referer=http://localhost:8888/lab/tree/.lsp_symlink/usr/lib/python3.9/csv.py
[W 2021-09-05 11:31:44.485 ServerApp] 403 PATCH /api/contents/.lsp_symlink/usr/lib/python3.9/csv.py?1630798304478 (::1): Permission denied: .lsp_symlink/usr/lib/python3.9/csv.py (external)
[W 2021-09-05 11:31:44.486 ServerApp] Permission denied: .lsp_symlink/usr/lib/python3.9/csv.py (external)
and so on...
No luck with the local modules.
Furthermore, the python library filename is changed from csv.py to csv.py (external) - which corrupts the conda based python installation. scream
Ouch, that's bad! Thank you for letting me know (this is due to a change of the behaviour in JupyterLab 3.1 I believe; previously changing tab title was just that, but now it apparently actually changes the file name on the disk :scream:
Please let me know whether you like to have a fully "engineered" example project for reproducing my finding. - Weather is too good at the moment, so I didn't prepare one upfront.
Btw, I really appreciate the jupyterlab-lsp extension.
@jabbera, @achimgaedke As for the original issue of code navigation when starting JupyterLab from a root directory (which I do not recommend, but I consider it a valid use case nonetheless):
The problem is that the language server does not know where is your project. This extension assumes that it is in the place where you started the JupyterLab, as it is typically started within the project directory. In that case you need to instruct the language server to scan additional paths. As I see that you have python-lsp-server
installed, I can recommend trying to set: pylsp.plugins.jedi.extra_paths
(see the https://github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md), by going to Settings
→ Advanced Settings Editor
→ Language Server
and pasting the following (after appropriate modifications) into the User Preferences
(right pane):
{
"language_servers": {
"pylsp": {
"serverSettings": {
"pylsp.plugins.jedi.extra_paths": ["/some/path"]
}
}
}
}
(do not forget to save). I am not sure how the path should look for you, I guess it will depend on the operating system you use.
I have just tested it on binder, and it works for sub-folders:
(before setting test
I was not able to jump to definition of x
, but after that I was able to do so).
@achimgaedke I see what is causing this issue (it is the same as https://github.com/jupyterlab/jupyterlab/issues/10856#issue-972712283), but your feedback led me to reevaluate the importance of it; I can only recommend not using .lsp_symlinks
with JupyterLab 3.1 for now, but I really hope we can fix it upstream soon.
And please let me know if it helped in your setup, as this one is a common question and a good candidate to be added to the documentation :)
Excellent, that solves the problem of accessing python code in a local notebook project.
It would be great to refer to the necessity of this configuration also in the https://github.com/krassowski/jupyterlab-lsp#jump-to-definition section.
I'm still a bit puzzled why I need to provide the path. Given that the language server has to consider the kernel's PYTHONPATH anyway, which contains the PWD of the python process (implying a notebook location if located on a file system). That bit of information would allow static analysis to predict what the importer would do. - Hmm maybe I need to read more about how and when the LSP process is started and investigates the execution environment.
just lost a couple hours to trying to understand what was happening.
here's a summary for anyone else coming across it:
jupyterlab in version 3.1 onwards introduced a change which breaks one of the underlying assumptions made by this extension: that the tab name will equal the file name.
in newer versions, a file is created which matches the tab name, which this package renames to hav (external)
as an annotation to communicate to the viewer that they are looking at code that is external to their project.
this breaks "jump to definition" because the file name expected on disk does not exist (it appears to be created). hover and other features like tab-completion still work fine.
i am also using jupyter/docker-stacks
based environments, so I spent a lot of time incorrectly presuming I was mis-symlinking. the script below shows the full install process that ended up working for me (root dir is /home/jovyan/
)
jump to definition is my # 1 use case for a language server and so my temporary solution was to use this installation script:
pip install 'jupyterlab~=3.0.0' && \
pip install jupyterlab-lsp==3.9.0 jupyter-lsp==1.4.1 && \
# pip install git+https://github.com/krassowski/python-language-server.git@main && \
pip install 'python-lsp-server[all]' && \
mkdir -p /home/jovyan/.lsp_symlink && \
cd /home/jovyan/.lsp_symlink && \
ln -s /home home && \
ln -s /opt opt
(the commented out line was me trying to rule out the python language server as the cause of the problem, I suppose either one can be used, and the pinned versions are also an artifact of trying to nail down the problem, should also be removable but I wanted to document a working example)
question: is it supposed to be ln -s /home home
or ln -s /home/jovyan home
? the instructions are not exactly clear but I presume the mappings should mirror the real paths.
UPDATE:
Hello! I think just removing the renaming of the tab would be a good idea, it would instantly fix the -currently present- bug and I don't think renaming the tab is essential... even if it is nice, no renaming is better than jumping not working :)
$ git diff fix_jumping origin/master
diff --git a/packages/code-jumpers/src/jumpers/jumper.ts b/packages/code-jumpers/src/jumpers/jumper.ts
index 4237c7d..714af70 100644
--- a/packages/code-jumpers/src/jumpers/jumper.ts
+++ b/packages/code-jumpers/src/jumpers/jumper.ts
@@ -91,7 +91,7 @@ export abstract class CodeJumper {
private protectFromAccidentalEditing(document_widget: IDocumentWidget) {
let editor_widget = document_widget as IDocumentWidget<FileEditor>;
- editor_widget.title.label = editor_widget.title.label + '';
+ editor_widget.title.label = editor_widget.title.label + ' (external)';
let editor = editor_widget.content.editor;
let disposable = editor.addKeydownHandler(
(editor: IEditor, event: KeyboardEvent) => {
I checked that this way it works.
Yes, that would be a good workaround for now. Though obviously changing the title label should not be bound to changing file name (as described in https://github.com/jupyterlab/jupyterlab/issues/10856).
@jepcor97 would you like to send a PR?
Yes, fine!
The fix from #712 was included in newly released v3.9.2. Many thank to @jepcor97 for the help with this one!
Description
I don't know when this started, but I can't get jump to definition working anymore. Whenever I use it I get: No Jump Targets Found
Reproduce
Expected behavior
It would jump to definition.
Context
It's not clear to me if it's the same issue as: https://github.com/krassowski/jupyterlab-lsp/issues/466
I do use / as my "root folder".
Required: installed server extensions
Required: installed lab extensions
Troubleshoot Output
Command Line Output
Browser Output (recommended for all interface issues)