@@ -40,6 +40,14 @@ describe("Tool: get_diagnostics", function()
40
40
end
41
41
return - 1 -- File not open
42
42
end )
43
+ _G .vim .uri_to_fname = spy .new (function (uri )
44
+ -- Realistic mock that matches vim.uri_to_fname behavior
45
+ if uri :sub (1 , 7 ) == " file://" then
46
+ return uri :sub (8 )
47
+ end
48
+ -- Real vim.uri_to_fname throws an error for URIs without proper scheme
49
+ error (" URI must contain a scheme: " .. uri )
50
+ end )
43
51
end )
44
52
45
53
after_each (function ()
@@ -49,6 +57,7 @@ describe("Tool: get_diagnostics", function()
49
57
_G .vim .api .nvim_buf_get_name = nil
50
58
_G .vim .json .encode = nil
51
59
_G .vim .fn .bufnr = nil
60
+ _G .vim .uri_to_fname = nil
52
61
-- Note: We don't nullify _G.vim.lsp or _G.vim.diagnostic entirely
53
62
-- as they are checked for existence.
54
63
end )
@@ -175,7 +184,8 @@ describe("Tool: get_diagnostics", function()
175
184
expect (success ).to_be_true ()
176
185
expect (# result .content ).to_be (1 )
177
186
178
- -- Should have called vim.diagnostic.get with specific buffer
187
+ -- Should have used vim.uri_to_fname to convert URI to file path
188
+ assert .spy (_G .vim .uri_to_fname ).was_called_with (" file:///test/file.lua" )
179
189
assert .spy (_G .vim .diagnostic .get ).was_called_with (1 )
180
190
assert .spy (_G .vim .fn .bufnr ).was_called_with (" /test/file.lua" )
181
191
end )
@@ -192,27 +202,9 @@ describe("Tool: get_diagnostics", function()
192
202
expect (err .message ).to_be (" File not open in buffer" )
193
203
assert_contains (err .data , " File must be open in Neovim to retrieve diagnostics: /unknown/file.lua" )
194
204
195
- -- Should have checked for buffer but not called vim.diagnostic.get
205
+ -- Should have used vim.uri_to_fname and checked for buffer but not called vim.diagnostic.get
206
+ assert .spy (_G .vim .uri_to_fname ).was_called_with (" file:///unknown/file.lua" )
196
207
assert .spy (_G .vim .fn .bufnr ).was_called_with (" /unknown/file.lua" )
197
208
assert .spy (_G .vim .diagnostic .get ).was_not_called ()
198
209
end )
199
-
200
- it (" should handle URI without file:// prefix" , function ()
201
- _G .vim .fn .bufnr = spy .new (function (filepath )
202
- if filepath == " /test/file.lua" then
203
- return 1
204
- end
205
- return - 1
206
- end )
207
- _G .vim .diagnostic .get = spy .new (function ()
208
- return {}
209
- end )
210
-
211
- local success , result = pcall (get_diagnostics_handler , { uri = " /test/file.lua" })
212
- expect (success ).to_be_true ()
213
-
214
- -- Should have used the path directly
215
- assert .spy (_G .vim .fn .bufnr ).was_called_with (" /test/file.lua" )
216
- assert .spy (_G .vim .diagnostic .get ).was_called_with (1 )
217
- end )
218
210
end )
0 commit comments