Repository: sublimelsp/LSP

Issue:
Unknown `CompletionItemKind`s are not handled properly
### Bug:
As it stands now, this LSP client specifies which `CompletionItemKind`s it supports in `TextDocumentClientCapabilities `. [According to the spec](https://microsoft.github.io/language-server-protocol/specification#initialize), if `InitializeParams.capabilities.textDocument.completion.completionItemKind.valueSet` is set, the client also guarantees that any value outside of `valueSet` will be handled gracefully and fall back to a default value:
```typescript
completionItemKind?: {
	/**
	 * The completion item kind values the client supports. When this
	 * property exists the client also guarantees that it will
	 * handle values outside its set gracefully and falls back
	 * to a default value when unknown.
	 *
	 * If this property is not present the client only supports
	 * the completion items kinds from `Text` to `Reference` as defined in
	 * the initial version of the protocol.
	 */
	valueSet?: CompletionItemKind[];
},
```
However, this is not the case here, the client emits an error instead of handling the unknown value:
```
Error handling server payload
Traceback (most recent call last):
  File "C:\Users\laure\AppData\Roaming\Sublime Text 3\Installed Packages\LSP.sublime-package\plugin/core/rpc.py", line 322, in receive_payload
    self.response_handler(payload)
  File "C:\Users\laure\AppData\Roaming\Sublime Text 3\Installed Packages\LSP.sublime-package\plugin/core/rpc.py", line 341, in response_handler
    self._response_handlers[handler_id](result)
  File "C:\Users\laure\AppData\Roaming\Sublime Text 3\Installed Packages\LSP.sublime-package\plugin/completion.py", line 261, in handle_response
    self.completions = list(self.format_completion(item) for item in items)
  File "C:\Users\laure\AppData\Roaming\Sublime Text 3\Installed Packages\LSP.sublime-package\plugin/completion.py", line 261, in <genexpr>
    self.completions = list(self.format_completion(item) for item in items)
  File "C:\Users\laure\AppData\Roaming\Sublime Text 3\Installed Packages\LSP.sublime-package\plugin/completion.py", line 237, in format_completion
    hint = completion_item_kind_names[kind]
KeyError: 19
```
This fallback behavior is also mandatory for `InitializeParams.capabilities.workspace.symbol.symbolKind.valueSet` and `InitializeParams.capabilities.textDocument.documentSymbol.symbolKind.valueSet`, although I haven't tested them in this client yet, so I don't know if they are affected as well.


Discussion:
@tomv564 once upon a time my python was strong.. I could have a look and see what I can do if you give me some hints what needs to be done? I'm eager to get it working with Ruby/Rails ;D

Resolving patch:
diff --git a/plugin/completion.py b/plugin/completion.py
--- a/plugin/completion.py
+++ b/plugin/completion.py
@@ -240,7 +240,7 @@ def format_completion(self, item: dict) -> 'Tuple[str, str]':
         elif settings.completion_hint_type == "kind":
             kind = item.get("kind")
             if kind:
-                hint = completion_item_kind_names[kind]
+                hint = completion_item_kind_names.get(kind)
         # label is an alternative for insertText if neither textEdit nor insertText is provided
         insert_text = self.text_edit_text(item) or item.get("insertText") or label
         if len(insert_text) > 0 and insert_text[0] == '$':  # sublime needs leading '$' escaped.
diff --git a/plugin/core/protocol.py b/plugin/core/protocol.py
--- a/plugin/core/protocol.py
+++ b/plugin/core/protocol.py
@@ -54,6 +54,13 @@ class CompletionItemKind(object):
     Color = 16
     File = 17
     Reference = 18
+    Folder = 19
+    EnumMember = 20
+    Constant = 21
+    Struct = 22
+    Event = 23
+    Operator = 24
+    TypeParameter = 25
 
 
 class DocumentHighlightKind(object):


Test patch: