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

Add references to pylsp client #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add references to pylsp client #46

wants to merge 1 commit into from

Conversation

kvptkr
Copy link

@kvptkr kvptkr commented Feb 29, 2024

@yeger00
Copy link
Owner

yeger00 commented Feb 29, 2024

Hi,
Thank you for your contribution.
As you can see we are in a transition to pydantic models, and these structs already exists there.
Please change the implementation to pydantic, you can see an example here: https://github.com/yeger00/pylspclient/pull/42/files
Also, please add a test.

Thanks,
Avi

@kvptkr
Copy link
Author

kvptkr commented Mar 1, 2024

Sounds good Avi! Before I make the change, is there a type pre-defined pydantic struct for context? If not, I'm happy to implement it myself, but is there a place from which you're getting the schema for all of these structs from?

@yeger00
Copy link
Owner

yeger00 commented Mar 2, 2024

The context is not implemented yet. It should be something like that (not tested):

from pydantic import BaseModel
from typing import Optional

class TextDocumentIdentifier(BaseModel):
    """
    Identifies a text document using its URI.
    """
    uri: str

class Position(BaseModel):
    """
    Represents a position in a text document.
    """
    line: int
    character: int

class TextDocumentPositionParams(BaseModel):
    """
    A base class including the text document identifier and a position within that document.
    """
    textDocument: TextDocumentIdentifier
    position: Position

class ReferenceContext(BaseModel):
    """
    Additional information about the context of a reference request.
    """
    includeDeclaration: bool  # Whether to include the declaration of the symbol being referenced

class ReferenceParams(TextDocumentPositionParams):
    """
    Parameters for a Reference Request in the Language Server Protocol.
    """
    context: ReferenceContext
    workDoneToken: Optional[str] = None  # Optional; used for progress reporting
    partialResultToken: Optional[str] = None  # Optional; used for partial results

# Example Usage
reference_params = ReferenceParams(
    textDocument=TextDocumentIdentifier(uri="file:///path/to/file.py"),
    position=Position(line=20, character=5),
    context=ReferenceContext(includeDeclaration=True)
)
print(reference_params)

It can be without the reference_params sruct and pass the params directly to the function.

@yeger00 yeger00 self-requested a review March 2, 2024 14:16
@yeger00
Copy link
Owner

yeger00 commented Mar 8, 2024

I added an example of more classes here: #47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants