From add957285a5ed6bafbfe2ec5b88060fc01ed7082 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 18 Aug 2025 19:03:27 +0300 Subject: lsp: strip Markdown code fences from LLM outputs (completions and code actions) --- internal/lsp/handlers_helpers_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'internal/lsp/handlers_helpers_test.go') diff --git a/internal/lsp/handlers_helpers_test.go b/internal/lsp/handlers_helpers_test.go index 84dce77..f9ed18a 100644 --- a/internal/lsp/handlers_helpers_test.go +++ b/internal/lsp/handlers_helpers_test.go @@ -50,3 +50,22 @@ func TestPromptRemovalEditsForLine_WholeLine(t *testing.T) { } } +func TestStripCodeFences(t *testing.T) { + cases := []struct{ + name string + in string + want string + }{ + {"no fences", "package main\nfunc x(){}", "package main\nfunc x(){}"}, + {"triple backticks no lang", "```\nA\nB\n```", "A\nB"}, + {"triple backticks with lang", "```go\nfmt.Println(\"hi\")\n```", "fmt.Println(\"hi\")"}, + {"leading/trailing spaces", " \n```python\nprint('x')\n```\n ", "print('x')"}, + {"single line fenced", "```go\npackage main\n```", "package main"}, + } + for _, tc := range cases { + got := stripCodeFences(tc.in) + if got != tc.want { + t.Fatalf("%s: got %q want %q", tc.name, got, tc.want) + } + } +} -- cgit v1.2.3