forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchild_helper.lua
More file actions
171 lines (150 loc) · 3.72 KB
/
Copy pathchild_helper.lua
File metadata and controls
171 lines (150 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
local M = {
mock_lsp_server = false,
}
if not _G.attach_debugger then
_G.attach_debugger = false
end
---@param test_name string
function M.new_child_neovim(test_name)
---@class MiniTest.child
---@field [any] any don't bother type checking this one
local child = MiniTest.new_child_neovim()
local logfile = string.format("./tests/logs/%s.log", test_name)
child.config = nil
if vim.fn.filereadable(logfile) == 1 then
vim.fn.delete(logfile)
end
function child.reset_config()
child.config = {
panel = "",
suggestion = [[
suggestion_notification = function(virt_text, _)
if (#virt_text > 0) and (#virt_text[1] > 0) then
M.suggested = true
end
end,
]],
logger = string.format(
[[
file_log_level = vim.log.levels.TRACE,
file = "%s",
]],
logfile
),
server = "",
root_dir = "",
should_attach = "",
filetypes = [[
["*"] = true,
]],
auth_provider_url = "",
workspace_folders = "",
server_opts_overrides = "",
copilot_model = "",
copilot_node_command = "",
}
end
function child.setup_and_wait_for_debugger()
if not _G.attach_debugger then
return
end
child.lua([[
require("osv").launch({ port = 8086, blocking = true })
]])
end
---@param mock_lsp_server? boolean
function child.run_pre_case(mock_lsp_server)
M.mock_lsp_server = mock_lsp_server or true
child.reset_config()
child.restart({ "-u", "tests/scripts/minimal_init.lua" })
if M.mock_lsp_server then
child.lua('package.loaded["copilot.lsp"] = require("tests.stubs.lsp_init")')
end
child.setup_and_wait_for_debugger()
child.lua("M = require('copilot')")
end
function child.reset_suggested()
child.lua("M.suggested = false")
end
function child.configure_copilot()
local script = ""
for k, v in pairs(child.config) do
if v ~= "" and v ~= nil then
if type(v) == "string" then
if v:sub(1, 8) == "function" then
script = string.format(
[[%s
%s = %s,]],
script,
k,
v
)
else
script = string.format(
[[%s
%s = { %s },]],
script,
k,
v
)
end
end
end
end
script = string.format(
[[
M.suggested = false
M.setup({ %s })
]],
script
)
child.lua(script)
child.lua([[
local copilot_is_initialized = function()
local client = require("copilot.client")
return client.initialized
end
vim.wait(5000, copilot_is_initialized, 10)
]])
end
function child.wait_for_suggestion()
if M.mock_lsp_server then
child.lua([[
vim.wait(500, function()
return M.suggested
end, 10)
]])
else
child.lua([[
vim.wait(5000, function()
return M.suggested
end, 10)
]])
end
end
function child.wait_for_panel_suggestion()
if M.mock_lsp_server then
child.lua([[
local function suggestion_is_visible()
lines = vim.api.nvim_buf_get_lines(2, 4, 5, false)
return lines[1] and (lines[1] == "789" or lines[1] == "789\r")
end
vim.wait(500, function()
return suggestion_is_visible()
end, 50)
]])
else
child.lua([[
local function suggestion_is_visible()
lines = vim.api.nvim_buf_get_lines(2, 4, 5, false)
return lines[1] and (lines[1] == "789" or lines[1] == "789\r")
end
vim.wait(10000, function()
return suggestion_is_visible()
end, 50)
]])
end
end
return child
end
return M