Skip to content

Commit 5fbe531

Browse files
committed
js filetype normalization & update copilot version
1 parent 08230e4 commit 5fbe531

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed

copilot/dist/agent.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/copilot/client.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local M = { params = {} }
2+
local util = require("copilot.util")
23

34
local register_autocmd = function ()
45
vim.api.nvim_create_autocmd({ "BufEnter" }, {
@@ -20,11 +21,15 @@ end
2021

2122
M.merge_server_opts = function (params)
2223
return vim.tbl_deep_extend("force", {
23-
cmd = { "node", require("copilot.util").get_copilot_path(params.plugin_manager_path) },
24-
name = "copilot",
24+
cmd = {'node', require("copilot.util").get_copilot_path(params.plugin_manager_path)},
25+
cmd_cwd = vim.fn.expand('~'),
2526
root_dir = vim.loop.cwd(),
27+
name = "copilot",
2628
autostart = true,
27-
on_init = function(_, _)
29+
single_file_support = true,
30+
on_init = function(client, initialize_result)
31+
local notify = client.rpc.notify
32+
notify('setEditorInfo', util.get_editor_info())
2833
vim.schedule(M.buf_attach_copilot)
2934
vim.schedule(register_autocmd)
3035
end,

lua/copilot/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local M = { client_info = nil }
22
local client = require("copilot.client")
3-
43
local defaults = {
54
cmp = {
65
enabled = true,

lua/copilot/util.lua

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
local 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+
333
local 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
1848
end
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
4387
end
4488

0 commit comments

Comments
 (0)