why pslsp is not returning correct definition?

50 Views Asked by At

I am asking for a go to definition request to pylsp using websockets. However, correct deifinition is not returned.

Here is the definition_request:

definition_request = {
    "jsonrpc": "2.0",
    "id": 2,
    "method": "textDocument/definition",
    "params": {
        "textDocument": {
            "uri": "file://" + os.path.join(root_path, file_name)
        },
        "position": {
            "line": line,
            "character": character
        }
    }
}

For the following code, I want to get the defition for check_files_in_directory which is definied in the GPT4Readability.utils file. But somehow pylsp is not able to provide me with the correct definition location.

GPT4Readability/readme_gen.py file:

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)
....

I get the following response:

finish pylsp_definitions --> [[{'uri': 'file:///path/to/the/repo/GPT4Readability/GPT4Readability/readme_gen.py', 'range': {'start': {'line': 25, 'character': 4}, 'end': {'line': 25, 'character': 29}}}]]

Very strange as it thinks that check_files_in_directory is defined in the same GPT4Readability/readme_gen.py file. Why is that?

Am I missing something in this case?

0

There are 0 best solutions below