coder / code-server

VS Code in the browser
https://coder.com
MIT License
67.59k stars 5.54k forks source link

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

Closed rohit901 closed 5 months ago

rohit901 commented 8 months ago

Is there an existing issue for this?

OS/Web Information

Steps to Reproduce

  1. Open settings.json, and add this line: "python.languageServer": "Jedi", [following #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?

Are you accessing code-server over a secure context?

Notes

No response

OceanTrader1 commented 8 months ago

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...
```bash #!/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 ```

https://github.com/coder/code-server/assets/69881238/85400cd4-d8a1-4b1f-b8aa-64d00f6b345c

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

rohit901 commented 8 months ago

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:

https://github.com/coder/code-server/assets/30185369/3bed60bb-6ed2-427d-8850-634ca386ae77

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",
}
OceanTrader1 commented 8 months ago

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

https://github.com/coder/code-server/assets/69881238/bab2a402-3f5e-4852-9350-655881c16d04

Python Environment Manager Extension...

```text 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 commented 8 months ago

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 :(

OceanTrader1 commented 8 months ago

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 commented 8 months ago

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 commented 5 months ago

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 commented 5 months ago

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

zengziru commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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