Conversation
| """The declaration of a symbol representation as one or many {@link Location locations}.""" | ||
|
|
||
| DeclarationLink = 'LocationLink' | ||
| DeclarationLink: TypeAlias = 'LocationLink' |
There was a problem hiding this comment.
TypeAlias was needed for ambiguous cases like this one where this is otherwise treated as a variable assignment.
|
There is an experiment branch in here where I experimented with generating requests. Here is an example of how it can be used: Note when doing this I did conclude that I do not need to generate notifications, although it is possible. |
|
Yeah, but it's a different use case really. As I've said in my comment, this is not to be used by our send_request/send_notification functionality. |
Something like this could get introduced separately but I'm affraid that while it would add some automation and type safety, we would then potentially have to create wrappers for some of those because we might call some from different places and it sometimes takes quite a bit of code to prepare the |
| messageDirection: MessageDirection | ||
| method: str | ||
| params: NotRequired[EveryType | list[EveryType]] | ||
| params: NotRequired[EveryType] |
There was a problem hiding this comment.
the previous type did match the JSON schema - so the previous type was more correct.
lsp-python-types/lsprotocol/lsp.schema.json
Line 385 in a020fc5
"Notification": {
...
"params": {
"anyOf": [
{
"$ref": "#/definitions/Type"
},
{
"items": {
"$ref": "#/definitions/Type"
},
"type": "array"
}
],
"description": "The parameter type(s) if any."
},
There was a problem hiding this comment.
In your example params is not a list. It's still an object.
The original type is not correct and also triggers a type error when passed to format_type.
There was a problem hiding this comment.
-
we have a JSON schema lsprotocol/lsp.schema.json
-
that JSON schema describes the data shape in lsprotocol/lsp.json
-
The JSON schema for the Notification
paramskey, describe the type as:
"params": {
"anyOf": [
{
"$ref": "#/definitions/Type"
},
{
"items": {
"$ref": "#/definitions/Type"
},
"type": "array"
}
],
To translated that to python params: Type | list[Type]
and it was marked as not required, as it was not listed as required in the JSON schema -
lsp-python-types/lsprotocol/lsp.schema.json
Line 431 in a020fc5
param: NotRequired[Type | list[Type]]
-
The lsp_schema.py offers python types that are a 1:1 match to the lsprotocol/lsp.schema.json - if the python type doesn't align with the JSON schema that is a bug
-
That was the reason why params was typed as
params: NotRequired[EveryType | list[EveryType]]
There was a problem hiding this comment.
In your example params is not a list. It's still an object.
Can you explain more -> "It's still an object." my eyes don't see an object :)
my eyes see params, as params: Type | list[Type] (or more precisely params: NotRequired[EveryType | list[EveryType]] if I take into account that params is not required)
The original type is not correct and also triggers a type error when passed to format_type.
Can you provide an example (screenshot)? I can take a look. (I could not see anything wrong)
There was a problem hiding this comment.
You are right. I will look into the type error it causes and address it differently.
There was a problem hiding this comment.
Actually I think the json schema is "wrong".
Text specification states that Request params are:
params?: array | objectso it kinda makes sense what JSON schema came up with:
"params": {
"anyOf": [
{
"$ref": "#/definitions/Type"
},
{
"items": {
"$ref": "#/definitions/Type"
},
"type": "array"
}
],
"description": "The parameter type(s) if any."
},but really what is:
{
"items": {
"$ref": "#/definitions/Type"
},
"type": "array"
}if not just the #/definitions/Type itself which already includes the #/definitions/ArrayType type:
"ArrayType": {
"additionalProperties": false,
"description": "Represents an array type (e.g. `TextDocument[]`).",
"properties": {
"element": {
"$ref": "#/definitions/Type"
},
"kind": {
"const": "array",
"type": "string"
}
},
"required": [
"kind",
"element"
],
"type": "object"
},There was a problem hiding this comment.
And note that none of the params or result in https://github.com/sublimelsp/lsp-python-types/blob/main/lsprotocol/lsp.json have params: [...]. It would have to be that to match list[EveryType].
There was a problem hiding this comment.
I could change it back to the original type, allow that type in format_type and then not handle that case since it's clearly not meant as a actual case with the schema file. But that would be just a different workaround with more code.
| messageDirection: MessageDirection | ||
| method: str | ||
| params: NotRequired[EveryType | list[EveryType]] | ||
| params: NotRequired[EveryType] |
There was a problem hiding this comment.
the previous type was more correct
lsp-python-types/lsprotocol/lsp.schema.json
Lines 550 to 561 in a020fc5
"Request": {
"params": {
"anyOf": [
{
"$ref": "#/definitions/Type"
},
{
"items": {
"$ref": "#/definitions/Type"
},
"type": "array"
}
],
"description": "The parameter type(s) if any."
},
I would suggest reverting this.
predragnikolic
left a comment
There was a problem hiding this comment.
I find this change ok. I misunderstood the use-case at first.
There is only one suggestion to revert the type change.
I've figured out a nice way to make code like https://github.com/sublimelsp/LSP-basedpyright/blob/941722d6b075997beca3b183d4b6ef078c3d2784/plugin/client.py#L104-L127 nice and type safe without casts.
We will just pass a
ServerResponseparameter and type checker will automatically infer type ofresultafterif method == 'foo/bar'.I don't see a way we could use those extra types for our Request/Response/Notification classes but it will at least allow making
LspPlugin.on_server_response_async,LspPlugin.on_pre_send_request_asyncandLspPlugin.on_pre_send_notification_asyncnice and type safe for the new plugin API.@predragnikolic @jwortmann