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
132 lines (115 loc) · 2.81 KB
/
Copy pathchild_helper.lua
File metadata and controls
132 lines (115 loc) · 2.81 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
local env = require("tests.env")
local M = {}
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
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
function child.run_pre_case()
child.reset_config()
child.restart({ "-u", "tests/scripts/minimal_init.lua" })
if env.COPILOT_TOKEN and env.COPILOT_TOKEN ~= "" then
child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
end
child.setup_and_wait_for_debugger()
child.lua("M = require('copilot')")
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
script = string.format(
[[%s%s = {
%s
},
]],
script,
k,
v
)
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(30000, copilot_is_initialized, 10)
]])
end
function child.wait_for_suggestion()
child.lua([[
vim.wait(30000, function()
return M.suggested
end, 10)
]])
end
function child.wait_for_panel_suggestion()
child.lua([[
local function suggestion_is_visible()
lines = vim.api.nvim_buf_get_lines(2, 4, 5, false)
return lines[1] and lines[1] ~= ""
end
vim.wait(30000, function()
return suggestion_is_visible()
end, 50)
]])
end
return child
end
return M