Repository: spyder-ide/spyder

Issue:
No completions returned from Kite after unicode emoji
## Problem Description

```
json.loa # returns completions
send_message("user","😒")
json.loa # does not return completions
```

I suspect this is because Spyder does not correctly handle communicating about unicode with Kite.

Kite accepts a top-level `offset_encoding` parameter in the completions request JSON. This indicates whether the offset are counting utf-32 code units (4-byte sequences), utf-16 code units (2-byte sequences), or utf-8 code units (bytes). The default is utf-8.

It looks like this parameter is sent as `utf-32` for signature requests, but no other Kite requests.

### What is the expected output? What do you see instead?

Kite should return completions for both of the cases described above.


Discussion:
@metalogical, bugs reported by you or other guys from the Kite team are expected to be handled by the Kite team, right? 
In this case, feel free to assign to me. In general, I think it'll depend on the nature of the bug (but this should be easy for us to fix).

Resolving patch:
diff --git a/spyder/plugins/completion/kite/providers/document.py b/spyder/plugins/completion/kite/providers/document.py
--- a/spyder/plugins/completion/kite/providers/document.py
+++ b/spyder/plugins/completion/kite/providers/document.py
@@ -70,9 +70,11 @@ def document_did_open(self, params):
             'filename': osp.realpath(params['file']),
             'text': params['text'],
             'action': 'focus',
-            'selections': [
-                {'start': params['offset'], 'end': params['offset']}
-            ]
+            'selections': [{
+                'start': params['offset'],
+                'end': params['offset'],
+                'encoding': 'utf-16',
+            }],
         }
 
         with QMutexLocker(self.mutex):
@@ -87,9 +89,11 @@ def document_did_change(self, params):
             'filename': osp.realpath(params['file']),
             'text': params['text'],
             'action': 'edit',
-            'selections': [
-                {'start': params['offset'], 'end': params['offset']}
-            ]
+            'selections': [{
+                'start': params['offset'],
+                'end': params['offset'],
+                'encoding': 'utf-16',
+            }],
         }
         with QMutexLocker(self.mutex):
             self.opened_files[params['file']] = params['text']
@@ -106,7 +110,7 @@ def request_document_completions(self, params):
             'position': {
                 'begin': params['offset']
             },
-            'placeholders': []
+            'offset_encoding': 'utf-16',
         }
         return request
 
@@ -164,7 +168,8 @@ def request_hover(self, params):
         request = {
             'filename': path,
             'hash': md5,
-            'cursor_runes': params['offset']
+            'cursor_runes': params['offset'],
+            'offset_encoding': 'utf-16',
         }
         return None, request
 
@@ -191,7 +196,7 @@ def request_signature(self, request):
             'filename': request['file'],
             'text': text,
             'cursor_runes': request['offset'],
-            'offset_encoding': 'utf-32'
+            'offset_encoding': 'utf-16',
         }
         return response
 


Test patch: