Skip to content

Commit e7e6cd1

Browse files
committed
fix: tests
1 parent 3b19675 commit e7e6cd1

8 files changed

+150
-19
lines changed

lua/copilot-lsp/nes/init.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ local nes_ns = vim.api.nvim_create_namespace("copilotlsp.nes")
88

99
---@param err lsp.ResponseError?
1010
---@param result copilotlsp.copilotInlineEditResponse
11-
local function handle_nes_response(err, result)
11+
---@param ctx lsp.HandlerContext
12+
local function handle_nes_response(err, result, ctx)
1213
if err then
1314
-- vim.notify(err.message)
1415
return
@@ -17,7 +18,7 @@ local function handle_nes_response(err, result)
1718
--- Convert to textEdit fields
1819
edit.newText = edit.text
1920
end
20-
nes_ui._display_next_suggestion(result.edits, nes_ns)
21+
nes_ui._display_next_suggestion(ctx.bufnr, nes_ns, result.edits)
2122
end
2223

2324
--- Requests the NextEditSuggestion from the current cursor position

lua/copilot-lsp/nes/ui.lua

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ function M.caculate_preview(bufnr, edit)
103103

104104
local is_same_line = start_line == end_line
105105
local is_deletion = text == ""
106+
local lines_edit = is_same_line or (start_char == 0 and end_char == 0)
106107
local is_insertion = is_same_line and start_char == end_char
107108

108109
if is_deletion and is_insertion then
109110
-- no-op
110111
return {}
111112
end
112113

113-
if is_same_line and is_deletion then
114-
-- inline deletion
114+
if is_deletion and lines_edit then
115115
return {
116116
deletion = {
117117
range = edit.range,
@@ -165,7 +165,7 @@ function M.caculate_preview(bufnr, edit)
165165
deletion = {
166166
range = {
167167
start = { line = start_line, character = 0 },
168-
["end"] = { line = end_line, character = #old_lines[num_old_lines] - 1 },
168+
["end"] = { line = end_line, character = #old_lines[num_old_lines] },
169169
},
170170
},
171171
lines_insertion = {
@@ -184,7 +184,7 @@ function M.display_inline_edit_preview(bufnr, ns_id, preview)
184184
vim.api.nvim_buf_set_extmark(bufnr, ns_id, range.start.line, range.start.character, {
185185
hl_group = "CopilotLspNesDelete",
186186
end_row = range["end"].line,
187-
end_col = range["end"].character + 1,
187+
end_col = range["end"].character,
188188
})
189189
end
190190

@@ -210,19 +210,16 @@ function M.display_inline_edit_preview(bufnr, ns_id, preview)
210210
end
211211

212212
---@private
213-
---@param edits copilotlsp.InlineEdit[]
213+
---@param bufnr integer
214214
---@param ns_id integer
215-
function M._display_next_suggestion(edits, ns_id)
215+
---@param edits copilotlsp.InlineEdit[]
216+
function M._display_next_suggestion(bufnr, ns_id, edits)
217+
M.clear_suggestion(bufnr, ns_id)
216218
if not edits or #edits == 0 then
217219
-- vim.notify("No suggestion available", vim.log.levels.INFO)
218220
return
219221
end
220222

221-
local bufnr = vim.uri_to_bufnr(edits[1].textDocument.uri)
222-
local state = vim.b[bufnr].nes_state
223-
if state then
224-
M.clear_suggestion(bufnr, ns_id)
225-
end
226223
local suggestion = edits[1]
227224

228225
local preview = M.caculate_preview(bufnr, suggestion)

tests/mock_lsp.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ local function getNesResponse(td)
7474
command = { title = "mock", command = "mock" },
7575
range = {
7676
start = { line = 4, character = 0 },
77-
["end"] = { line = 4, character = 30 },
77+
["end"] = { line = 4, character = 31 },
7878
},
7979
textDocument = td,
8080
text = [[ printf("Goodb, %s!\n", name);]],

tests/nes/test_ui_preview.lua

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ local cases = {
136136
deletion = {
137137
range = {
138138
["end"] = {
139-
character = 6,
139+
character = 7,
140140
line = 1,
141141
},
142142
start = {
@@ -171,7 +171,7 @@ local cases = {
171171
deletion = {
172172
range = {
173173
["end"] = {
174-
character = 6,
174+
character = 7,
175175
line = 1,
176176
},
177177
start = {
@@ -187,6 +187,37 @@ local cases = {
187187
},
188188
final = "123456\nXXXX\nhijklmn",
189189
},
190+
["delete lines"] = {
191+
content = "123456\nabcdefg\nhijklmn",
192+
edit = {
193+
range = {
194+
start = {
195+
line = 0,
196+
character = 0,
197+
},
198+
["end"] = {
199+
line = 2,
200+
character = 0,
201+
},
202+
},
203+
newText = "",
204+
},
205+
preview = {
206+
deletion = {
207+
range = {
208+
["end"] = {
209+
character = 0,
210+
line = 2,
211+
},
212+
start = {
213+
character = 0,
214+
line = 0,
215+
},
216+
},
217+
},
218+
},
219+
final = "hijklmn",
220+
},
190221
}
191222

192223
local function set_content(content)

tests/screenshots/tests-nes-test_nes.lua---nes---highlights-replacement-003

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
02|
44
03|int main(void) {
55
04| const char *name = "World";
6-
05| printf("Goodb, %s!\n", name);;
6+
05| printf("Goodb, %s!\n", name);
77
06| return 0;
88
07|}
99
08|~
@@ -29,7 +29,7 @@
2929
02|11111111111111111111111111111111111111111111111111111111111111111111111111111111
3030
03|33314444333333131111111111111111111111111111111111111111111111111111111111111111
3131
04|11555551333315444415122222223111111111111111111111111111111111111111111111111111
32-
05|11444444322222222222332314444333111111111111111111111111111111111111111111111111
32+
05|11444444322222222222332314444331111111111111111111111111111111111111111111111111
3333
06|11555555123111111111111111111111111111111111111111111111111111111111111111111111
3434
07|31111111111111111111111111111111111111111111111111111111111111111111111111111111
3535
08|66666666666666666666666666666666666666666666666666666666666666666666666666666666
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--|---------|---------|---------|---------|---------|---------|---------|---------|
2+
01|123456
3+
02|abcdefg
4+
03|hijklmn
5+
04|~
6+
05|~
7+
06|~
8+
07|~
9+
08|~
10+
09|~
11+
10|~
12+
11|~
13+
12|~
14+
13|~
15+
14|~
16+
15|~
17+
16|~
18+
17|~
19+
18|~
20+
19|~
21+
20|~
22+
21|~
23+
22|~
24+
23|[No Name] [+] 1,1 All
25+
24|
26+
27+
--|---------|---------|---------|---------|---------|---------|---------|---------|
28+
01|00000000000000000000000000000000000000000000000000000000000000000000000000000000
29+
02|00000000000000000000000000000000000000000000000000000000000000000000000000000000
30+
03|00000000000000000000000000000000000000000000000000000000000000000000000000000000
31+
04|11111111111111111111111111111111111111111111111111111111111111111111111111111111
32+
05|11111111111111111111111111111111111111111111111111111111111111111111111111111111
33+
06|11111111111111111111111111111111111111111111111111111111111111111111111111111111
34+
07|11111111111111111111111111111111111111111111111111111111111111111111111111111111
35+
08|11111111111111111111111111111111111111111111111111111111111111111111111111111111
36+
09|11111111111111111111111111111111111111111111111111111111111111111111111111111111
37+
10|11111111111111111111111111111111111111111111111111111111111111111111111111111111
38+
11|11111111111111111111111111111111111111111111111111111111111111111111111111111111
39+
12|11111111111111111111111111111111111111111111111111111111111111111111111111111111
40+
13|11111111111111111111111111111111111111111111111111111111111111111111111111111111
41+
14|11111111111111111111111111111111111111111111111111111111111111111111111111111111
42+
15|11111111111111111111111111111111111111111111111111111111111111111111111111111111
43+
16|11111111111111111111111111111111111111111111111111111111111111111111111111111111
44+
17|11111111111111111111111111111111111111111111111111111111111111111111111111111111
45+
18|11111111111111111111111111111111111111111111111111111111111111111111111111111111
46+
19|11111111111111111111111111111111111111111111111111111111111111111111111111111111
47+
20|11111111111111111111111111111111111111111111111111111111111111111111111111111111
48+
21|11111111111111111111111111111111111111111111111111111111111111111111111111111111
49+
22|11111111111111111111111111111111111111111111111111111111111111111111111111111111
50+
23|22222222222222222222222222222222222222222222222222222222222222222222222222222222
51+
24|00000000000000000000000000000000000000000000000000000000000000000000000000000000
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--|---------|---------|---------|---------|---------|---------|---------|---------|
2+
01|123456
3+
02|abcdefg
4+
03|hijklmn
5+
04|~
6+
05|~
7+
06|~
8+
07|~
9+
08|~
10+
09|~
11+
10|~
12+
11|~
13+
12|~
14+
13|~
15+
14|~
16+
15|~
17+
16|~
18+
17|~
19+
18|~
20+
19|~
21+
20|~
22+
21|~
23+
22|~
24+
23|[No Name] [+] 1,1 All
25+
24|
26+
27+
--|---------|---------|---------|---------|---------|---------|---------|---------|
28+
01|00000011111111111111111111111111111111111111111111111111111111111111111111111111
29+
02|00000001111111111111111111111111111111111111111111111111111111111111111111111111
30+
03|11111111111111111111111111111111111111111111111111111111111111111111111111111111
31+
04|22222222222222222222222222222222222222222222222222222222222222222222222222222222
32+
05|22222222222222222222222222222222222222222222222222222222222222222222222222222222
33+
06|22222222222222222222222222222222222222222222222222222222222222222222222222222222
34+
07|22222222222222222222222222222222222222222222222222222222222222222222222222222222
35+
08|22222222222222222222222222222222222222222222222222222222222222222222222222222222
36+
09|22222222222222222222222222222222222222222222222222222222222222222222222222222222
37+
10|22222222222222222222222222222222222222222222222222222222222222222222222222222222
38+
11|22222222222222222222222222222222222222222222222222222222222222222222222222222222
39+
12|22222222222222222222222222222222222222222222222222222222222222222222222222222222
40+
13|22222222222222222222222222222222222222222222222222222222222222222222222222222222
41+
14|22222222222222222222222222222222222222222222222222222222222222222222222222222222
42+
15|22222222222222222222222222222222222222222222222222222222222222222222222222222222
43+
16|22222222222222222222222222222222222222222222222222222222222222222222222222222222
44+
17|22222222222222222222222222222222222222222222222222222222222222222222222222222222
45+
18|22222222222222222222222222222222222222222222222222222222222222222222222222222222
46+
19|22222222222222222222222222222222222222222222222222222222222222222222222222222222
47+
20|22222222222222222222222222222222222222222222222222222222222222222222222222222222
48+
21|22222222222222222222222222222222222222222222222222222222222222222222222222222222
49+
22|22222222222222222222222222222222222222222222222222222222222222222222222222222222
50+
23|33333333333333333333333333333333333333333333333333333333333333333333333333333333
51+
24|11111111111111111111111111111111111111111111111111111111111111111111111111111111

tests/screenshots/tests-nes-test_ui_preview.lua---ui_preview---inline-deletion-002

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
--|---------|---------|---------|---------|---------|---------|---------|---------|
2828
01|00000000000000000000000000000000000000000000000000000000000000000000000000000000
29-
02|00111100000000000000000000000000000000000000000000000000000000000000000000000000
29+
02|00111000000000000000000000000000000000000000000000000000000000000000000000000000
3030
03|00000000000000000000000000000000000000000000000000000000000000000000000000000000
3131
04|22222222222222222222222222222222222222222222222222222222222222222222222222222222
3232
05|22222222222222222222222222222222222222222222222222222222222222222222222222222222

0 commit comments

Comments
 (0)