Crash On Unrecognized CompletionItemKind
- Dominant language
- Haskell
- Stars
- 423
- Forks
- 105
- PR merge metrics
- No merged PRs in 30d
Description
I am attempting to build a language client against haskell-language-server in Visual Studio 2019.
When I follow the [instructions](https://learn.microsoft.com/en-us/visualstudio/extensibility/adding-an-lsp-extension?view=vs-2019) for doing so however, haskell-language-server-wrapper fails with the following error
> 2022-09-24T11:34:34.192704Z | Info | Starting server
> 2022-09-24T11:34:34.193704Z | Error | Got error while decoding initialize:
> Error in $.params.capabilities.textDocument.completion.completionItemKind.valueSet[0]: CompletionItemKind
Upon further investigation, it seems the issue is that in the `CompletionItemKind` enumeration defined in `Microsoft.VisualStudio.LanguageServer.Protocol.dll`, the first element of this enumeration is `None`. Visual Studio attempts to pass all members of this enumeration as supported completion kinds to the language server. In the [A.FromJSON](https://github.com/haskell/lsp/blob/73df35690afbeca4666620a3350e7ff8b5104de2/lsp-types/src/Language/LSP/Types/Completion.hs#L73) declaration, `None` is not a valid identifier, resulting in `fail "CompletionItemKind"` being called, which I believe is what leads to the exception above.
According to the [LSP Specifiaction](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#enumerations):
> To support the evolution of enumerations the using side of an enumeration shouldn’t fail on an enumeration value it doesn’t know. It should simply ignore it as a value it can use and try to do its best to preserve the value on round trips. Lets look at the [CompletionItemKind](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemKind) enumeration as an example again: if in a future version of the specification an additional completion item kind with the value n gets added and announced by a client a (older) server not knowing about the value should not fail but simply ignore the value as a usable item kind.
There are actually 13 "additional" values in the `CompletionItemKind` enum of `Microsoft.VisualStudio.LanguageServer.Protocol.dll`, so I believe the key issue here is that haskell/lsp (and by extension haskell-language-server) do not correctly ignore unknown enumeration values as recommended by the LSP specification. This may potentially affect other LSP enumeration kinds implemented by this project as well
Attached is the log output of haskell-language-server-wrapper that generated this error
[log.log](https://github.com/haskell/lsp/files/9638603/log.log)
Contributor guide
Assessment
This issue has not been assessed yet.