pappasam / jedi-language-server

A Python language server exclusively for Jedi. If Jedi supports it well, this language server should too.
MIT License
574 stars 44 forks source link

how to run jedi to find references using a lsp client? #277

Closed code2graph closed 8 months ago

code2graph commented 10 months ago

Can I run a lsp client to find references programatically?

I know jedi is a language server as theoreticallty I can connect to pylance and extract references from a function call is invoked.

For example for the following code:

import os
from getpass import getpass
from GPT4Readability.utils import *
import importlib.resources as pkg_resources  

def generate_readme(root_dir, output_name, model):
    """Generates a README.md file based on the python files in the provided directory

    Args:
        root_dir (str): The root directory of the python package to parse and generate a readme for
    """

    # prompt_folder_name = os.path.join(os.path.dirname(__file__), "prompts")
    # prompt_path = os.path.join(prompt_folder_name, "readme_prompt.txt")

    with pkg_resources.open_text('GPT4Readability.prompts','readme_prompt.txt') as f:         
        inb_msg = f.read()

    # with open(prompt_path) as f:
    #     lines = f.readlines()
    # inb_msg = "".join(lines)

    file_check_result = check_files_in_directory(root_dir)

Here I need to find out check_files_in_directory is defined in the GPT4Readability.utils.

I am stugglign to find this informaiton.

davidhalter commented 10 months ago

I know jedi is a language server

Jedi is not a language server. It is a Python API. Some projects like jedi-language-server build language servers on top of Jedi.


This is probably what you are looking for: https://jedi.readthedocs.io/en/latest/docs/api.html#jedi.Script.get_references