Skip to content
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

Some Python LSP methods do not search the user's namespace #5739

Closed
vinaychuri opened this issue Dec 14, 2024 · 3 comments
Closed

Some Python LSP methods do not search the user's namespace #5739

vinaychuri opened this issue Dec 14, 2024 · 3 comments
Assignees
Labels
area: kernels Issues related to Jupyter kernels and LSP servers bug Something isn't working lang: python support

Comments

@vinaychuri
Copy link

vinaychuri commented Dec 14, 2024

System details:

Mac ,Venture, 13.7.2

Positron and OS details:

Positron Version: 2025.01.0 (Universal) build 39
Code - OSS Version: 1.93.0
Commit: c7ef34f
Date: 2024-12-09T02:49:50.608Z (5 days ago)
Electron: 30.4.0
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Darwin x64 22.6.0

Interpreter details:

Python 3.12.8 (Venv: python_env)

Describe the issue:

Context help especially for local function is partially missing in Jupyter notebooks

Steps to reproduce the issue:

Create a .py file with following code

import pandas as pd

def abc(x=1):
    """ 
    TESTING
    """
    print(x)

abc()
  1. As you type "c" in "abc" , the function help tip is displayed
  2. As you type the "(" , the function help tip is displayed
  3. As you hover over the "abc()" , the function help tip is displayed

If the same is done in ".ipynb" file, only the #1 help is displayed, #2,#3 are not

Expected or desired behavior:

All 3 help tip methods should be displayed in ".ipynb" file as well

https://github.com/user-attachments/assets/4012ecf1-bf2a-4c7e-9ca5-efafedba1aca
https://github.com/user-attachments/assets/fab31d13-fb51-42a6-9dd2-712c2c3b86f2

@nstrayer nstrayer added the area: notebooks Issues related to Notebooks category. label Dec 16, 2024
@nstrayer nstrayer assigned nstrayer and unassigned nstrayer Dec 16, 2024
@nstrayer
Copy link
Contributor

Can confirm this behavior. Probably related to #4263.

@juliasilge juliasilge added bug Something isn't working support labels Dec 16, 2024
@seeM seeM added this to the 2025.02.0 Pre-Release milestone Dec 17, 2024
@seeM
Copy link
Contributor

seeM commented Jan 10, 2025

Thank you for the helpful writeup!

This affects the console too. It seems to only work correctly in scripts.

The problem is that we use jedi-language-server's hover and signature_help functions for textDocument/hover and textDocument/signatureHelp here: https://github.com/posit-dev/positron/blob/44ed531e074d4b0b0886d370c5f879e0a61e68f4/extensions/positron-python/python_files/positron/positron_ipykernel/positron_jedilsp.py.

They use jedi.Script instead of jedi.Interpreter. The latter also searches the user's namespace.

There are other functions that use Script too, so maybe we could patch jedi_utils.script to always return an Interpreter?

@seeM seeM changed the title Local function help tips are partially missing in Jupyter notebooks Some Python LSP methods do not search the user's namespace Jan 10, 2025
@seeM seeM added lang: python area: kernels Issues related to Jupyter kernels and LSP servers and removed area: notebooks Issues related to Notebooks category. labels Jan 10, 2025
@seeM seeM self-assigned this Jan 16, 2025
seeM added a commit that referenced this issue Jan 31, 2025
…upyter notebooks e.g. hover and signature help (#6140)

The main goal of this PR is to address #5739. Along the way, I decided
to refactor how we customize Jedi. I've moved away from subclassing to
just patching things. Since Jedi wasn't really designed to be customized
at this level, patching lets us copy/paste _a lot_ less of their code,
which I think is more robust moving forward, and it's more succinct.
Since we're patching a _vendored_ version of Jedi, we also don't run the
risk of messing with a user's own independent usage of Jedi.

I also added a bunch of tests for different LSP features. I think it's
worth having those since we might still want to run a variation of them
even if we eventually move away from Jedi.

### Release Notes

#### New Features

- N/A

#### Bug Fixes

- Fix some language server features not working in the console and in
Jupyter notebooks e.g. hover and signature help (#5739). This also fixes
language server features for custom Pandas DataFrame accessors (#5077).

### QA Notes

The linked issues have great repros. They should work in both notebooks
and the console when you define an object in one execution, then trigger
the LSP in another.
@midleman
Copy link
Contributor

Verified Fixed

Positron Version(s) : 2025.03.0 (Universal) build 4
OS Version(s) : MacOS

Test scenario(s)

Confirmed that hover and signature help displayed in all scenarios:

  • .py file
  • .ipynb file
  • console

Link(s) to TestRail test cases run or created:

n/a

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: kernels Issues related to Jupyter kernels and LSP servers bug Something isn't working lang: python support
Projects
None yet
Development

No branches or pull requests

5 participants