Skip to content

Commit 1041a7b

Browse files
authored
Merge pull request #422 from zbirenbaum/various_cleanups
Various cleanups
2 parents 0d56d43 + 0da8869 commit 1041a7b

File tree

8 files changed

+31
-94
lines changed

8 files changed

+31
-94
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ As lua is far more efficient and makes things easier to integrate with modern pl
1111

1212
</details>
1313

14+
## Requirements
15+
16+
- Curl
17+
- NeoVim 0.10.0 or higher
18+
1419
## Install
1520

1621
Install the plugin with your preferred plugin manager.

lua/copilot/api.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local mod = {}
33

44
---@param callback? fun(err: any|nil, data: table, ctx: table): nil
55
---@return any|nil err
6-
---@return table data
6+
---@return any data
77
---@return table ctx
88
function mod.request(client, method, params, callback)
99
logger.trace("api request:", method, params)
@@ -139,14 +139,13 @@ function mod.get_completions_cycling(client, params, callback)
139139
return mod.request(client, "getCompletionsCycling", params, callback)
140140
end
141141

142-
---@alias copilot_get_panel_completions_data { solutionCountTarget: integer }
143142
---@alias copilot_panel_solution_data { panelId: string, completionText: string, displayText: string, range: { ['end']: { character: integer, line: integer }, start: { character: integer, line: integer } }, score: number, solutionId: string }
144143
---@alias copilot_panel_on_solution_handler fun(result: copilot_panel_solution_data): nil
145144
---@alias copilot_panel_solutions_done_data { panelId: string, status: 'OK'|'Error', message?: string }
146145
---@alias copilot_panel_on_solutions_done_handler fun(result: copilot_panel_solutions_done_data): nil
147146

148147
---@return any|nil err
149-
---@return copilot_get_panel_completions_data data
148+
---@return integer data
150149
---@return table ctx
151150
function mod.get_panel_completions(client, params, callback)
152151
return mod.request(client, "getPanelCompletions", params, callback)

lua/copilot/client.lua

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,6 @@ local function store_client_id(id)
4040
M.id = id
4141
end
4242

43-
local lsp_start = vim.lsp.start
44-
if not lsp_start then
45-
local function reuse_client(client, conf)
46-
return client.config.root_dir == conf.root_dir and client.name == conf.name
47-
end
48-
49-
-- shim for neovim < 0.8.2
50-
lsp_start = function(lsp_config)
51-
local bufnr = vim.api.nvim_get_current_buf()
52-
local client = M.get()
53-
if client and reuse_client(client, lsp_config) then
54-
vim.lsp.buf_attach_client(bufnr, client.id)
55-
return client.id
56-
end
57-
local client_id = vim.lsp.start_client(lsp_config) --[[@as number]]
58-
vim.lsp.buf_attach_client(bufnr, client_id)
59-
return client_id
60-
end
61-
end
62-
6343
function M.buf_is_attached(bufnr)
6444
return M.id and vim.lsp.buf_is_attached(bufnr or 0, M.id)
6545
end
@@ -92,7 +72,7 @@ function M.buf_attach(force)
9272
-- In case it has changed, we update it
9373
M.config.root_dir = config.get_root_dir()
9474

95-
local ok, client_id_or_err = pcall(lsp_start, M.config)
75+
local ok, client_id_or_err = pcall(vim.lsp.start, M.config)
9676
if not ok then
9777
logger.error(string.format("failed to start LSP client: %s", client_id_or_err))
9878
return
@@ -111,6 +91,7 @@ function M.buf_detach()
11191
end
11292
end
11393

94+
---@return nil|vim.lsp.Client
11495
function M.get()
11596
return vim.lsp.get_client_by_id(M.id)
11697
end
@@ -134,7 +115,7 @@ function M.use_client(callback)
134115
return
135116
end
136117

137-
local client_id, err = vim.lsp.start_client(M.config)
118+
local client_id, err = vim.lsp.start(M.config)
138119

139120
if not client_id then
140121
logger.error(string.format("error starting LSP client: %s", err))
@@ -434,7 +415,7 @@ function M.add_workspace_folder(folder_path)
434415

435416
local client = M.get()
436417
if client and client.initialized then
437-
client.notify("workspace/didChangeWorkspaceFolders", {
418+
api.notify(client, "workspace/didChangeWorkspaceFolders", {
438419
event = {
439420
added = { workspace_folder },
440421
removed = {},

lua/copilot/config.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ local default_config = {
4545
trace_lsp_progress = false,
4646
log_lsp_messages = false,
4747
},
48-
---@deprecated
49-
ft_disable = nil,
5048
---@type table<string, boolean>
5149
filetypes = {},
5250
---@type string|nil

lua/copilot/handlers.lua

Lines changed: 0 additions & 24 deletions
This file was deleted.

lua/copilot/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ local highlight = require("copilot.highlight")
44
local logger = require("copilot.logger")
55
local client = require("copilot.client")
66
local auth = require("copilot.auth")
7-
local lsp_binary = require("copilot.lsp_binary")
87

98
local create_cmds = function()
109
vim.api.nvim_create_user_command("CopilotDetach", function()

lua/copilot/panel.lua

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local marker_prefix = "[copilot] "
1212
local panel_uri_prefix = "copilot://"
1313

1414
local panel = {
15+
---@type vim.lsp.Client
1516
client = nil,
1617
setup_done = false,
1718

@@ -27,6 +28,7 @@ local panel = {
2728
filetype = nil,
2829

2930
state = {
31+
---@type integer|nil
3032
req_id = nil,
3133
line = nil,
3234
status = nil,
@@ -414,7 +416,7 @@ function panel:refresh()
414416
end
415417

416418
if self.state.req_id then
417-
self.client.cancel_request(self.state.req_id)
419+
self.client:cancel_request(self.state.req_id)
418420
self.state.req_id = nil
419421
end
420422

@@ -430,7 +432,6 @@ function panel:refresh()
430432
end
431433

432434
self.state.received_count = type(self.state.received_count) == "number" and self.state.received_count + 1 or 1
433-
434435
self:unlock():refresh_header():add_entry(result):lock()
435436
end,
436437
---@param result copilot_panel_solutions_done_data
@@ -466,31 +467,32 @@ function panel:refresh()
466467
if not auto_refreshing and self.state.was_insert then
467468
vim.cmd("stopinsert")
468469
else
470+
local utf16_index
469471
-- assume cursor at end of line
470-
local _, utf16_index = vim.str_utfindex(self.state.line)
472+
if vim.has("nvim-0.11") then
473+
utf16_index = vim.str_utfindex(self.state.line, "utf-16")
474+
else
475+
---@diagnostic disable-next-line: missing-parameter
476+
_, utf16_index = vim.str_utfindex(self.state.line)
477+
end
471478
params.doc.position.character = utf16_index
472479
params.position.character = params.doc.position.character
473480
end
474481

475482
-- on_solutions_done can be invoked before the api.get_panel_completions callback
476483
self.state.status = "loading"
477484

478-
local _, id = api.get_panel_completions(
479-
self.client,
480-
params,
481-
---@param result copilot_get_panel_completions_data
482-
function(err, result)
483-
if err then
484-
self.state.status = "error"
485-
self.state.error = err
486-
logger.error(self.state.error)
487-
return
488-
end
489-
490-
self.state.expected_count = result.solutionCountTarget
491-
panel:unlock():refresh_header():lock()
485+
local _, id = api.get_panel_completions(self.client, params, function(err, result)
486+
if err then
487+
self.state.status = "error"
488+
self.state.error = err
489+
logger.error(self.state.error)
490+
return
492491
end
493-
)
492+
493+
self.state.expected_count = result.solutionCountTarget
494+
panel:unlock():refresh_header():lock()
495+
end)
494496

495497
self.state.req_id = id
496498
end

lua/copilot/util.lua

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ function M.get_copilot_lua_version()
3737
return copilot_lua_version
3838
end
3939

40-
-- use `require("copilot.client").get()`
41-
---@deprecated
42-
M.get_copilot_client = function()
43-
return require("copilot.client").get()
44-
end
45-
4640
local internal_filetypes = {
4741
yaml = false,
4842
markdown = false,
@@ -106,12 +100,6 @@ function M.should_attach()
106100
return true
107101
end
108102

109-
-- use `require("copilot.client").buf_is_attached()`
110-
---@deprecated
111-
function M.is_attached()
112-
return require("copilot.client").buf_is_attached(0)
113-
end
114-
115103
local language_normalization_map = {
116104
bash = "shellscript",
117105
bst = "bibtex",
@@ -179,12 +167,6 @@ function M.get_doc_params(overrides)
179167
return params
180168
end
181169

182-
-- use `require("copilot.util").get_doc_params()`
183-
---@deprecated
184-
M.get_completion_params = function(opts)
185-
return M.get_doc_params(opts)
186-
end
187-
188170
---@return copilot_workspace_configurations
189171
function M.get_workspace_configurations()
190172
local conf = config.get() --[[@as copilot_config]]
@@ -227,11 +209,6 @@ M.get_plugin_path = function()
227209
end
228210
end
229211

230-
---@deprecated
231-
M.auth = function()
232-
require("copilot.auth").signin()
233-
end
234-
235212
---@param str string
236213
---@return integer
237214
function M.strutf16len(str)

0 commit comments

Comments
 (0)