| 1 |
This test exercises the "go_file_diagnostics" MCP tool. |
| 2 |
|
| 3 |
Some diagnostics from the "printf" analyzer carry fixes, and those fixes have edits. |
| 4 |
(Not all fixes have edits; some analyzers rely on gopls to compute them lazily.) |
| 5 |
|
| 6 |
The printf analyzer only reports a fix in files using >= go1.24. |
| 7 |
|
| 8 |
-- flags -- |
| 9 |
-mcp |
| 10 |
-min_go_command=go1.24 |
| 11 |
|
| 12 |
-- settings.json -- |
| 13 |
{ |
| 14 |
"mcpTools": { |
| 15 |
"go_file_diagnostics": true |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
-- go.mod -- |
| 20 |
module example.com |
| 21 |
go 1.24 |
| 22 |
|
| 23 |
-- a/main.go -- |
| 24 |
package main |
| 25 |
|
| 26 |
func foo() {} //@loc(foo, "foo") |
| 27 |
|
| 28 |
//@mcptool("go_file_diagnostics", `{"file":"$WORKDIR/a/main.go"}`, output=unused) |
| 29 |
//@diag(foo, re"unused") |
| 30 |
-- @unused -- |
| 31 |
2:5-2:8: [Information] function "foo" is unused |
| 32 |
Fix: |
| 33 |
--- $WORKDIR/a/main.go |
| 34 |
+++ $WORKDIR/a/main.go |
| 35 |
@@ -1,6 +1,6 @@ |
| 36 |
package main |
| 37 |
|
| 38 |
-func foo() {} //@loc(foo, "foo") |
| 39 |
+ |
| 40 |
|
| 41 |
//@mcptool("go_file_diagnostics", `{"file":"$WORKDIR/a/main.go"}`, output=unused) |
| 42 |
//@diag(foo, re"unused") |
| 43 |
|
| 44 |
|
| 45 |
-- b/main.go -- |
| 46 |
package main |
| 47 |
|
| 48 |
import "fmt" |
| 49 |
|
| 50 |
// (diagnostic with fix) |
| 51 |
var ( |
| 52 |
msg string |
| 53 |
_ = fmt.Sprintf(msg) //@ diag("msg", re"non-constant format string") |
| 54 |
) |
| 55 |
|
| 56 |
// (diagnostic without fix) |
| 57 |
var _ = fmt.Sprintf("%d", "hello") //@ diag("%d", re"%d .* wrong type string") |
| 58 |
|
| 59 |
//@ mcptool("go_file_diagnostics", `{"file":"$WORKDIR/b/main.go"}`, output=diagnosePrintf) |
| 60 |
|
| 61 |
-- @diagnosePrintf -- |
| 62 |
7:17-7:20: [Warning] non-constant format string in call to fmt.Sprintf |
| 63 |
Fix: |
| 64 |
--- $WORKDIR/b/main.go |
| 65 |
+++ $WORKDIR/b/main.go |
| 66 |
@@ -5,7 +5,7 @@ |
| 67 |
// (diagnostic with fix) |
| 68 |
var ( |
| 69 |
msg string |
| 70 |
- _ = fmt.Sprintf(msg) //@ diag("msg", re"non-constant format string") |
| 71 |
+ _ = fmt.Sprintf("%s", msg) //@ diag("msg", re"non-constant format string") |
| 72 |
) |
| 73 |
|
| 74 |
// (diagnostic without fix) |
| 75 |
|
| 76 |
|
| 77 |
11:21-11:23: [Warning] fmt.Sprintf format %d has arg "hello" of wrong type string |