|
1 | 1 | local M = {} |
2 | 2 |
|
3 | 3 | local format_pos = function() |
4 | | - local pos = vim.api.nvim_win_get_cursor(0) |
5 | | - return { character = pos[2], line = pos[1]-1 } |
| 4 | + local pos = vim.api.nvim_win_get_cursor(0) |
| 5 | + return { character = pos[2], line = pos[1] - 1 } |
6 | 6 | end |
7 | 7 |
|
8 | 8 | local get_relfile = function() |
9 | | - local file,_= string.gsub(vim.api.nvim_buf_get_name(0), vim.loop.cwd() .. "/", '') |
10 | | - return file |
| 9 | + local file, _ = string.gsub(vim.api.nvim_buf_get_name(0), vim.loop.cwd() .. "/", "") |
| 10 | + return file |
11 | 11 | end |
12 | 12 |
|
13 | 13 | M.get_completion_params = function() |
14 | | - local params = { |
15 | | - options = vim.empty_dict(), |
16 | | - doc = { |
17 | | - relativePath = get_relfile(), |
18 | | - source = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), '\n'), |
19 | | - languageId = vim.bo.filetype, |
20 | | - insertSpaces = true, |
21 | | - tabsize = vim.bo.shiftwidth, |
22 | | - indentsize = vim.bo.shiftwidth, |
23 | | - position = format_pos(), |
24 | | - path = vim.api.nvim_buf_get_name(0), |
25 | | - }, |
26 | | - } |
27 | | - return params |
| 14 | + local params = { |
| 15 | + options = vim.empty_dict(), |
| 16 | + doc = { |
| 17 | + relativePath = get_relfile(), |
| 18 | + source = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), "\n"), |
| 19 | + languageId = vim.bo.filetype, |
| 20 | + insertSpaces = true, |
| 21 | + tabsize = vim.bo.shiftwidth, |
| 22 | + indentsize = vim.bo.shiftwidth, |
| 23 | + position = format_pos(), |
| 24 | + path = vim.api.nvim_buf_get_name(0), |
| 25 | + }, |
| 26 | + } |
| 27 | + return params |
28 | 28 | end |
29 | 29 |
|
30 | 30 | M.get_copilot_path = function(plugin_path) |
31 | | - for _, loc in ipairs{"/opt", "/start", ""} do |
32 | | - local copilot_path = plugin_path .. loc .. "/copilot.lua/copilot/index.js" |
33 | | - if vim.fn.filereadable(copilot_path) ~= 0 then |
34 | | - return copilot_path |
35 | | - end |
36 | | - end |
| 31 | + for _, loc in ipairs({ "/opt", "/start", "" }) do |
| 32 | + local copilot_path = plugin_path .. loc .. "/copilot.lua/copilot/index.js" |
| 33 | + if vim.fn.filereadable(copilot_path) ~= 0 then |
| 34 | + return copilot_path |
| 35 | + end |
| 36 | + end |
37 | 37 | end |
38 | 38 |
|
39 | | -local function completion_handler (_, result, _, _) |
40 | | - print(vim.inspect(result)) |
| 39 | +local function completion_handler(_, result, _, _) |
| 40 | + print(vim.inspect(result)) |
41 | 41 | end |
42 | 42 |
|
43 | | -M.register_completion_handler = function (handler) |
44 | | - if handler then completion_handler = handler end |
| 43 | +M.register_completion_handler = function(handler) |
| 44 | + if handler then |
| 45 | + completion_handler = handler |
| 46 | + end |
45 | 47 | end |
46 | 48 |
|
47 | 49 | M.send_completion_request = function() |
48 | | - local params = M.get_completion_params() |
49 | | - vim.lsp.buf_request(0, 'getCompletions', params, completion_handler) |
| 50 | + local params = M.get_completion_params() |
| 51 | + vim.lsp.buf_request(0, "getCompletions", params, completion_handler) |
50 | 52 | end |
51 | 53 |
|
52 | 54 | M.create_request_autocmd = function(group) |
53 | | - vim.api.nvim_create_autocmd(group, {callback = M.send_completion_request}) |
| 55 | + vim.api.nvim_create_autocmd(group, { callback = M.send_completion_request }) |
54 | 56 | end |
55 | 57 |
|
56 | 58 | return M |
0 commit comments