Skip to content

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

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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