Skip to content

Commit 56842aa

Browse files
committed
fix(getDiagnostics): remove Neovim context from description
1 parent 548fd1a commit 56842aa

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lua/claudecode/tools/get_diagnostics.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
--- Tool implementation for getting diagnostics.
22

3+
-- NOTE: Its important we don't tip off Claude that we're dealing with Neovim LSP diagnostics because it may adjust
4+
-- line and col numbers by 1 on its own (since it knows nvim LSP diagnostics are 0-indexed). By calling these
5+
-- "editor diagnostics" and converting to 1-indexed ourselves we (hopefully) avoid incorrect line and column numbers
6+
-- in Claude's responses.
37
local schema = {
4-
description = "Get Neovim LSP diagnostics (errors, warnings) from open buffers",
8+
description = "Get language diagnostics (errors, warnings) from the editor",
59
inputSchema = {
610
type = "object",
711
properties = {
@@ -28,7 +32,7 @@ local function handler(params)
2832
error({
2933
code = -32000,
3034
message = "Feature unavailable",
31-
data = "LSP or vim.diagnostic.get not available in this Neovim version/configuration.",
35+
data = "Diagnostics not available in this editor version/configuration.",
3236
})
3337
end
3438

@@ -55,8 +59,8 @@ local function handler(params)
5559
logger.debug("File buffer must be open to get diagnostics: " .. filepath)
5660
error({
5761
code = -32001,
58-
message = "File not open in buffer",
59-
data = "File must be open in Neovim to retrieve diagnostics: " .. filepath,
62+
message = "File not open",
63+
data = "File must be open to retrieve diagnostics: " .. filepath,
6064
})
6165
else
6266
-- Get diagnostics for the specific buffer

tests/unit/tools/get_diagnostics_spec.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe("Tool: get_diagnostics", function()
7373

7474
it("should return formatted diagnostics if available", function()
7575
local mock_diagnostics = {
76-
{ bufnr = 1, lnum = 10, col = 5, severity = 1, message = "Error message 1", source = "linter1" },
76+
{ bufnr = 1, lnum = 10, col = 5, severity = 1, message = "Error message 1", source = "linter1" },
7777
{ bufnr = 2, lnum = 20, col = 15, severity = 2, message = "Warning message 2", source = "linter2" },
7878
}
7979
_G.vim.diagnostic.get = spy.new(function()
@@ -95,7 +95,7 @@ describe("Tool: get_diagnostics", function()
9595
-- Check the first diagnostic was encoded with 1-indexed values
9696
local first_call_args = _G.vim.json.encode.calls[1].vals[1]
9797
expect(first_call_args.filePath).to_be("/path/to/file_for_buf_1.lua")
98-
expect(first_call_args.line).to_be(11) -- 10 + 1 for 1-indexing
98+
expect(first_call_args.line).to_be(11) -- 10 + 1 for 1-indexing
9999
expect(first_call_args.character).to_be(6) -- 5 + 1 for 1-indexing
100100
expect(first_call_args.severity).to_be(1)
101101
expect(first_call_args.message).to_be("Error message 1")
@@ -107,7 +107,7 @@ describe("Tool: get_diagnostics", function()
107107

108108
it("should filter out diagnostics with no file path", function()
109109
local mock_diagnostics = {
110-
{ bufnr = 1, lnum = 10, col = 5, severity = 1, message = "Error message 1", source = "linter1" },
110+
{ bufnr = 1, lnum = 10, col = 5, severity = 1, message = "Error message 1", source = "linter1" },
111111
{ bufnr = 99, lnum = 20, col = 15, severity = 2, message = "Warning message 2", source = "linter2" }, -- This one will have no path
112112
}
113113
_G.vim.diagnostic.get = spy.new(function()
@@ -140,7 +140,7 @@ describe("Tool: get_diagnostics", function()
140140
expect(err).to_be_table()
141141
expect(err.code).to_be(-32000)
142142
assert_contains(err.message, "Feature unavailable")
143-
assert_contains(err.data, "LSP or vim.diagnostic.get not available")
143+
assert_contains(err.data, "Diagnostics not available in this editor version/configuration.")
144144
end)
145145

146146
it("should error if vim.diagnostic is not available", function()
@@ -199,8 +199,8 @@ describe("Tool: get_diagnostics", function()
199199
expect(success).to_be_false()
200200
expect(err).to_be_table()
201201
expect(err.code).to_be(-32001)
202-
expect(err.message).to_be("File not open in buffer")
203-
assert_contains(err.data, "File must be open in Neovim to retrieve diagnostics: /unknown/file.lua")
202+
expect(err.message).to_be("File not open")
203+
assert_contains(err.data, "File must be open to retrieve diagnostics: /unknown/file.lua")
204204

205205
-- Should have used vim.uri_to_fname and checked for buffer but not called vim.diagnostic.get
206206
assert.spy(_G.vim.uri_to_fname).was_called_with("file:///unknown/file.lua")

0 commit comments

Comments
 (0)