python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.76k stars 186 forks source link

how to find references using a lsp client? #421

Closed code2graph closed 10 months ago

code2graph commented 10 months ago

how to code up a lsp client to find references programatically?

I know as python-lsp-server is a language server and theoreticallty I can connect to it 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 struggling to find this informaiton and any help is welcome.

ccordoba12 commented 10 months ago

Closing as a duplicate of #422.