11local M = {}
22
3+ -- keep for debugging reasons
4+ M .get_editor_info = function ()
5+ local info = vim .empty_dict ()
6+ info .editorInfo = vim .empty_dict ()
7+ info .editorInfo .name = ' Neovim'
8+ info .editorInfo .version = ' 0.8.0-dev-809-g7dde6d4fd'
9+ info .editorPluginInfo = vim .empty_dict ()
10+ info .editorPluginInfo .name = ' copilot.vim'
11+ info .editorPluginInfo .version = ' 1.5.3'
12+ return info
13+ end
14+
15+ -- keep for debugging reasons
16+ local get_capabilities = function ()
17+ return {
18+ capabilities = {
19+ textDocumentSync = {
20+ change = 2 ,
21+ openClose = true
22+ },
23+ workspace = {
24+ workspaceFolders = {
25+ changeNotifications = true ,
26+ supported = true
27+ }
28+ }
29+ }
30+ }
31+ end
32+
333local format_pos = function ()
434 local pos = vim .api .nvim_win_get_cursor (0 )
535 return { character = pos [2 ], line = pos [1 ] - 1 }
@@ -17,16 +47,28 @@ M.get_copilot_client = function()
1747 end
1848end
1949
20- M .get_completion_params = function ()
50+ local normalize_ft = function (ft )
51+ local resolve_map = {
52+ text = " plaintext" ,
53+ javascriptreact = " javascript" ,
54+ jsx = " javascript" ,
55+ typescriptreact = " typescript" ,
56+ }
57+ if not ft or ft == ' ' then
58+ return ' plaintext'
59+ end
60+ return resolve_map [ft ] or ft
61+ end
62+
63+ M .get_completion_params = function (opts )
2164 local rel_path = get_relfile ()
2265 local uri = vim .uri_from_bufnr (0 )
2366 local params = {
24- options = vim .empty_dict (),
2567 doc = {
2668 source = table.concat (vim .api .nvim_buf_get_lines (0 , 0 , - 1 , false ), " \n " ),
2769 relativePath = rel_path ,
28- languageId = vim .bo . filetype ,
29- insertSpaces = true ,
70+ languageId = normalize_ft ( vim .api . nvim_buf_get_option ( 0 , ' filetype' )) ,
71+ insertSpaces = vim . o . expandtab ,
3072 tabsize = vim .bo .shiftwidth ,
3173 indentsize = vim .bo .shiftwidth ,
3274 position = format_pos (),
@@ -39,6 +81,8 @@ M.get_completion_params = function()
3981 uri = uri ,
4082 }
4183 }
84+ params .position = params .doc .position
85+ if opts then params .doc = vim .tbl_deep_extend (' keep' , params .doc , opts ) end
4286 return params
4387end
4488
0 commit comments