Skip to content

Add null to return types#2235

Open
MariaSolOs wants to merge 1 commit intomicrosoft:gh-pagesfrom
MariaSolOs:type-changes
Open

Add null to return types#2235
MariaSolOs wants to merge 1 commit intomicrosoft:gh-pagesfrom
MariaSolOs:type-changes

Conversation

@MariaSolOs
Copy link
Contributor

After microsoft/vscode-languageserver-node#1691 these methods are typed as potentially returning null. Updating the documentation to reflect this.

@mfussenegger
Copy link

This is a breaking change for clients. Is this really necessary?

@puremourning
Copy link

Hang on isn't this a breaking change?

@MariaSolOs
Copy link
Contributor Author

This is a breaking change for clients. Is this really necessary?

I'm just trying to update the documentation to reflect the current state of the protocol.

@jwortmann
Copy link

jwortmann commented Mar 2, 2026

I always thought that the documentation is the protocol.

In other words, the source of truth would be what is written on the website labeled as "Specification" under https://microsoft.github.io/language-server-protocol/specifications/specification-current, and not some implementation detail in a vscode-languageserver-node library.

That said, in the client implementation for Sublime Text we already have a workaround for exactly this use case (more precisely one part of the proposed changes), because apparently there is already a language server that violates the current specs for this return type.

Of course I don't know how other clients handle it, or whether they would crash if null is returned and they try to iterate the results directly.

@MariaSolOs
Copy link
Contributor Author

I always thought that the documentation is the protocol.

In other words, the source of truth would be what is written on the website labeled as "Specification" under https://microsoft.github.io/language-server-protocol/specifications/specification-current, and not some implementation detail in a vscode-languageserver-node library.

I 200% agree with you here. However from my contribution experience in this repository I know that changes will often be made first to the VS Code LSP implementation and then the metamodel will be generated there and ported to this repo (see how these generator scripts are defined there). I don't like this order of operations, but I want to make sure that when the metamodel is updated in the future the documentation reflects what the types do so that other editors can align.

@puremourning
Copy link

This is a breaking change for clients. Is this really necessary?

I'm just trying to update the documentation to reflect the current state of the protocol.

The documentation, is the protocol.

@MariaSolOs
Copy link
Contributor Author

This is a breaking change for clients. Is this really necessary?

I'm just trying to update the documentation to reflect the current state of the protocol.

The documentation, is the protocol.

Please read #2235 (comment). I'm on your side here.

@dbaeumer
Copy link
Member

dbaeumer commented Mar 3, 2026

The specification is the truth.

The reason why I actually would like to change the specification here is consistency. The fact that the two requests don't allow to return null seems to be an oversight. All other requests that return an [] of things do allow to return null.

So I somehow assume that most clients will handle null in these cases as well.

@puremourning
Copy link

puremourning commented Mar 3, 2026

I for one explicitly check the spec every time to see if a value can be null. Because that requires extra code vs say an empty list.

As it happens I don't think this particular item is supported by my client so it's not such a big deal for me, but in general it's true.

@mfussenegger
Copy link

mfussenegger commented Mar 3, 2026

So I somehow assume that most clients will handle null in these cases as well.

They don't.

I'd also think that if there is a someType[] | null the specification should clarify if there is a semantic difference between null and empty list. And if there isn't - just don't do the | null. Representing information with types that can represent more states than necessary isn't useful.

@dbaeumer
Copy link
Member

dbaeumer commented Mar 5, 2026

As said it is more about consistency. The protocol started to allow null in case of an empty array and I would prefer to keep it that way instead of saying it differs from case to case.

@MariaSolOs
Copy link
Contributor Author

As said it is more about consistency. The protocol started to allow null in case of an empty array and I would prefer to keep it that way instead of saying it differs from case to case.

Is this documented in the specification?

These types are defined using TypeScript syntax though, and in TypeScript an empty array is different from null. There's actually an inconsistency between the specification and the expected implementation.

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.

6 participants