Skip to content

[Bug]: Ctrl+Click / Code Jump / Go To Definition Does Not Work Properly in Python/Jupyter Notebooks #6619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 of 6 tasks
rohit901 opened this issue Jan 4, 2024 · 12 comments
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer

Comments

@rohit901
Copy link

rohit901 commented Jan 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues

OS/Web Information

  • Web Browser: Chrome
  • Local OS: Mac
  • Remote OS: Linux
  • Remote Architecture: Ubuntu
  • code-server --version: 1.85.1
    0b84523
    x64

Steps to Reproduce

  1. Open settings.json, and add this line: "python.languageServer": "Jedi", [following [Bug]: Hover feature does not work in Jupyter notebooks #6323]
  2. Activate a specific conda environment and select it in the interpreter or select it in the jupyter notebook.
  3. import some libraries in test.py or test.ipynb, for example: [in activated or selected conda environment]
import torch
import numpy
import diffusers

Hover or Ctrl+Click on some libraries like torch and numpy above work, and they open the file located in /apps/local/anaconda2023/lib/python3.11/site-packages/<library>

However, Hover/Ctrl+Click on diffusers does not work. I believe this is because my conda environment is stored in this location, and diffusers is available here: /home/rohit.bharadwaj/.conda/envs/learn_diffusion/lib/python3.11/site-packages/diffusers

How can I ensure that Jedi gets the library files from correct location?
My conda environment is called learn_diffusion, and when I set the python interpreter in the GUI, the location for it is shown as ./conda/envs/learn_diffusion/bin/python
whereas location for base conda environment is: /apps/local/anaconda2023/bin/python, So JEDI seems to be using the base conda env location for code jump? How to change it?

Expected

Code Jump should work properly for all libraries in current conda environment and should route to proper location.

Actual

Hover/Ctrl+Click on diffusers does not work. I believe this is because my conda environment is stored in this location, and diffusers is available here: /home/rohit.bharadwaj/.conda/envs/learn_diffusion/lib/python3.11/site-packages/diffusers

Jedi server is looking for libraries in /apps/local/anaconda2023/lib/python3.11/site-packages/<library>

My conda environment is called learn_diffusion, and when I set the python interpreter in the GUI, the location for it is shown as ./conda/envs/learn_diffusion/bin/python
whereas location for base conda environment is: /apps/local/anaconda2023/bin/python, So JEDI seems to be using the base conda env location for code jump? How to change it?

Logs

No response

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

  • I tested this in native VS Code.
  • This does not happen in native VS Code.
  • I tested this in GitHub Codespaces.
  • This does not happen in GitHub Codespaces.

Are you accessing code-server over a secure context?

  • I am using a secure context.

Notes

No response

@rohit901 rohit901 added bug Something isn't working triage This issue needs to be triaged by a maintainer labels Jan 4, 2024
@skevetter
Copy link

skevetter commented Jan 4, 2024

I am using the same code-server configuration I used in #6323 and it appears to be working as expected by navigating to the correct package within the given conda environment. Confirm that you have selected the correct conda environment within the *.ipynb file. You may need to refresh the page once or twice to load the correct settings.

Setup temporary environment...
#!/bin/bash

TEST_DIR="$HOME/Documents/github/test"

conda create -n tmp -c conda-forge python=3.10 numpy diffusers -y

if [ ! -d "$TEST_DIR" ]; then
    mkdir -p "$TEST_DIR"
fi

if [ ! -f "$TEST_DIR/test.ipynb" ]; then
    touch "$TEST_DIR/test.ipynb"
fi
conda-jedi-lsp.mov

By default, Jedi should be able to work with conda environments. https://jedi.readthedocs.io/en/latest/docs/api.html

@rohit901
Copy link
Author

rohit901 commented Jan 4, 2024

Thanks a lot for your reply @OceanTrader1.
Its strange that its not working for me, is it because I'm not running in HTTPS?

I have a university machine allocated to me through SLURM system and I don't have sudo access to it and hence I'm limited in terms of software packages that I can install or settings I can actually change.

To be specific, I installed code-server by this command:
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method standalone
Then in my allocated remote machine through SLURM system, I run this to start the server:
.local/bin/code-server --bind-addr 0.0.0.0:10000
after running the server this is the output:

.local/bin/code-server --bind-addr 0.0.0.0:10000
[2024-01-04T16:41:31.950Z] info  code-server 4.20.0 d0215eca8804d0be5d3551c39404e336032c3141
[2024-01-04T16:41:31.950Z] info  Using user-data-dir /home/rohit.bharadwaj/.local/share/code-server
[2024-01-04T16:41:31.959Z] info  Using config file /home/rohit.bharadwaj/.config/code-server/config.yaml
[2024-01-04T16:41:31.959Z] info  HTTP server listening on http://0.0.0.0:10000/
[2024-01-04T16:41:31.959Z] info    - Authentication is enabled
[2024-01-04T16:41:31.959Z] info      - Using password from /home/rohit.bharadwaj/.config/code-server/config.yaml
[2024-01-04T16:41:31.959Z] info    - Not serving HTTPS
[2024-01-04T16:41:31.959Z] info  Session server listening on /home/rohit.bharadwaj/.local/share/code-server/code-server-ipc.sock
[20:41:34]

I then just copy the ip of the remote machine and visit the URL <ip>:10000/ on my local machine to access code server.

Im sure I have selected the correct conda environment and I had refreshed multiple times and had also restarted the server many times but still same error, please refer below video:

code_jump_not_working.mov

These are the extension versions I'm using:
Python

Name: Python
Id: ms-python.python
Description: IntelliSense (Pylance), Linting, Debugging (multi-threaded, remote), code formatting, refactoring, unit tests, and more.
Version: 2023.20.0
Publisher: ms-python
VS Marketplace Link: https://open-vsx.org/vscode/item?itemName=ms-python.python

Jupyter

Name: Jupyter
Id: ms-toolsai.jupyter
Description: Jupyter notebook support, interactive programming and computing that supports Intellisense, debugging and more.
Version: 2023.9.100
Publisher: ms-toolsai
VS Marketplace Link: https://open-vsx.org/vscode/item?itemName=ms-toolsai.jupyter

code-server:

code-server: v4.20.0
Code: 1.85.1
Commit: 0b84523121d6302fbe30eda7899ec3b81810748e
Date: 2023-12-18T20:21:20.879Z
Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Also my settings.json:

{
    "editor.fontSize": 16,
    "debug.console.fontSize": 15,
    "terminal.integrated.fontSize": 16,
    "markdown.preview.fontSize": 17,
    "notebook.output.fontSize": 17,
    "workbench.colorTheme": "Default Dark Modern",
    // Overrides colors
    "workbench.colorCustomizations": {
        "[Community Material Theme VARIANT]": {
            "sideBar.background": "#ff0000",
        }
    },

    // Overrides editor syntax colors and font style
    "editor.tokenColorCustomizations": {
        "[Community Material Theme VARIANT]": {
            "comments": "#229977"
        }
    },
    "editor.tokenColorCustomizations": {
        "[Community Material Theme VARIANT]": {
            "textMateRules": [
                {
                    "scope": [
                        "punctuation.definition.comment",
                        "comment.block",
                        "comment.line",
                        "comment.block.documentation"
                    ],
                    "settings": {
                        "foreground": "#FF0000"
                    }
                }
            ]
        },
    },
    // Controls the font family.
    "editor.fontFamily": "Operator Mono",
    // Controls the line height. Use 0 to compute the lineHeight from the fontSize.
    "editor.lineHeight": 24,
    // Enables font ligatures
    "editor.fontLigatures": true,
    // Controls if file decorations should use badges.
    "explorer.decorations.badges": false,
    "workbench.iconTheme": "material-icon-theme",
    "files.autoSave": "off",
    "github.copilot.enable": {
        "*": true,
        "plaintext": true,
        "markdown": false,
        "scminput": false,
        "python": true
    },
    "python.languageServer": "Jedi",
    "remote.autoForwardPortsSource": "hybrid",
}

@skevetter
Copy link

skevetter commented Jan 4, 2024

is it because I'm not running in HTTPS?

Yes. It is an HTTP/S issue. I am not able to open *.ipynb files at all on HTTP (blank screen area where file contents should be).

For *.py files, I am having success setting the workspace environment to the conda environment using the Python Environment Manager extension

jedi-over-http.mov
Python Environment Manager Extension...

Name: Python Environment Manager
Id: donjayamanne.python-environment-manager
Description: View and manage Python environments & packages.
Version: 1.2.4
Publisher: donjayamanne
VS Marketplace Link: https://open-vsx.org/vscode/item?itemName=donjayamanne.python-environment-manager

@rohit901
Copy link
Author

rohit901 commented Jan 4, 2024

Yes. It is an HTTP/S issue. I am not able to open *.ipynb files at all on HTTP (blank screen area where file contents should be).

Regarding not being able to open *.ipynb files, I use this hack which works if you use Google Chrome.

  1. Go to this link on chrome: chrome://flags/#unsafely-treat-insecure-origin-as-secure
  2. Enable the option Insecure origins treated as secure in that page, and in the input text box there, type this:
    http://<ip_of_the_machine>:10000
  3. Click outside the box, and it should ask you to reload chrome for changes to take effect.
  4. Now you can open *.ipynb files in HTTP.

Since with this change we are able to open ipynb files in HTTP, this should not be the reason that Jedi LSP is not working correctly right?

Btw I checked out python environment manager extension and it still didn't seem to work :(

@skevetter
Copy link

skevetter commented Jan 4, 2024

This is a non-answer but since the focus is towards Jupyter notebooks, Jupyter Lab might be a potential alternative that supports user installs, language servers, and runs over HTTP (and early AI code completion in the works).

@rohit901
Copy link
Author

rohit901 commented Jan 4, 2024

This is a non-answer but since the focus is towards Jupyter notebooks, Jupyter Lab might be a potential alternative that supports user installs and runs over HTTP.

Thanks for sharing. I did explore jupyter lab earlier too, but it does not suit me well because I would like to use VS Code while working on my projects so I can make use of all the extensions available in VS Code which also includes Github Copilot that I often use a lot to help me with my projects and easily get the boilerplate code done.

Thus, this project (code-server) seems to be the only useful way for me to use VS Code in my remote systems which are allocated to me through SLURM system [I can not use remote SSH feature of my local VS Code to access this SLURM based machines]

@lizheray
Copy link

The following trick method works for me:

  1. Click "File -> New File..." at the top left corner menu bar
  2. Choose "Jupyter Notebook" to create a new blank jupyter notebook file

Then go back to your python file, the code jump works well! Amazing!

@code-asher
Copy link
Member

code-asher commented Apr 9, 2024

Closing since it looks like there is nothing to fix in code-server? Let me know if I got it wrong.

@code-asher code-asher closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
@zengziru
Copy link

I have the same question, and I found when I use the method above like:
Click "File -> New File..." at the top left corner menu bar
Choose "Jupyter Notebook" to create a new blank jupyter notebook file
I found the new file will be save to /opt/conda/lib....., but not the current workspace folder like:/workspace/my_user/project....
It seems like the code-server is in the system conda environment but not in the current python interpreter.
How should we solve it?

@zengziru
Copy link

This is a non-answer but since the focus is towards Jupyter notebooks, Jupyter Lab might be a potential alternative that supports user installs and runs over HTTP.

Thanks for sharing. I did explore jupyter lab earlier too, but it does not suit me well because I would like to use VS Code while working on my projects so I can make use of all the extensions available in VS Code which also includes Github Copilot that I often use a lot to help me with my projects and easily get the boilerplate code done.

Thus, this project (code-server) seems to be the only useful way for me to use VS Code in my remote systems which are allocated to me through SLURM system [I can not use remote SSH feature of my local VS Code to access this SLURM based machines]

I found the solution!!! You can download the Pyright in vscode extensions market, it is the open source version for pylance。 Then you can see when you debug it can go to the right definition!

@rohit901
Copy link
Author

Thanks for sharing, @zengziru. I'm sure it will be helpful for others who happen to come across this same issue/thread.

@benoit-cty
Copy link

Hello, for thoose coming here from a search engine, I solve my Ctrl+click problem by updating Code Server.

Have a look to the output where a message tell me the version was outdated:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer
Projects
None yet
Development

No branches or pull requests

6 participants