LanguageServerProtocol icon indicating copy to clipboard operation
LanguageServerProtocol copied to clipboard

Is ValueSet decoding too strict?

Open jonsterling opened this issue 3 months ago • 2 comments

The Helix editor language client sends an empty dictionary {} for this params.capabilities.textDocument.completion.completionItemKind during initialisation, but the LanguageServerProtocol library expects this dictionary to have a valueSet field if it is sent at all.

This means that when the Helix language client attempts to initialise my server, it receives the following decoding error:

2025-09-20T21:13:26.786 helix_lsp::transport [ERROR] pterodactyl-lsp err <- "2025-09-20T21:13:26+0100 error org.jonmsterling.pterodactyl: [Pterodactyl] Received error: keyNotFound(CodingKeys(stringValue: \"valueSet\", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: \"params\", intValue: nil), CodingKeys(stringValue: \"capabilities\", intValue: nil), CodingKeys(stringValue: \"textDocument\", intValue: nil), CodingKeys(stringValue: \"completion\", intValue: nil), CodingKeys(stringValue: \"completionItemKind\", intValue: nil)], debugDescription: \"No value associated with key CodingKeys(stringValue: \\\"valueSet\\\", intValue: nil) (\\\"valueSet\\\").\", underlyingError: nil))\n"

Now, after having a look at the LSP specification for CompletionClientCapabilities, I think that it is intended that both

...completionItemKind = {}

and

...completionItemKind = { valueSet = ...}

are intended to be valid according to the specification. There are so many levels of optionality here. Perhaps the solution is to change the swift ValueSet struct to have an optional valueSet member.

What do you think? P.S. thanks for the great library! It is really speeding me up.

jonsterling avatar Sep 22 '25 10:09 jonsterling

I think we have enough evidence here to blame this package. This is potentially annoying, because I have encountered language servers that require you include a key with an explicit null. Kind of the hallmark of LSP - lots of subtle variations.

(also just a note: this is kind of coming in at a bad time for me. I won't have a lot of time to look at this for the next few weeks.)

mattmassicotte avatar Sep 23 '25 12:09 mattmassicotte

@mattmassicotte Thanks for having a look! Please don't worry about delays, I'm not blocked on this.

jonsterling avatar Sep 23 '25 12:09 jonsterling