summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/lsp/handlers.go')
-rw-r--r--internal/lsp/handlers.go34
1 files changed, 33 insertions, 1 deletions
diff --git a/internal/lsp/handlers.go b/internal/lsp/handlers.go
index d140ba1..cfd71ea 100644
--- a/internal/lsp/handlers.go
+++ b/internal/lsp/handlers.go
@@ -482,7 +482,17 @@ func (s *Server) tryLLMCompletion(p CompletionParams, above, current, below, fun
// Update response counters (received)
s.incRecvCounters(len(text))
s.logLLMStats()
- cleaned := stripCodeFences(strings.TrimSpace(text))
+ cleaned := stripCodeFences(strings.TrimSpace(text))
+ // For code completion responses, also strip inline single-backtick code spans
+ // when the model returns prose like: "Use `expr` here".
+ if cleaned != "" {
+ if strings.ContainsRune(cleaned, '`') {
+ inline := stripInlineCodeSpan(cleaned)
+ if strings.TrimSpace(inline) != "" {
+ cleaned = inline
+ }
+ }
+ }
if cleaned != "" {
cleaned = stripDuplicateAssignmentPrefix(current[:p.Position.Character], cleaned)
}
@@ -780,6 +790,28 @@ func stripCodeFences(s string) string {
return t
}
+// stripInlineCodeSpan returns only the contents of the first inline backtick
+// code span if present, e.g., "some text `x := y()` more" -> "x := y()".
+// If no matching pair of backticks exists, it returns the input unchanged.
+// This is intended for code completion responses where the model may wrap a
+// small snippet in single backticks among prose.
+func stripInlineCodeSpan(s string) string {
+ t := strings.TrimSpace(s)
+ if t == "" {
+ return t
+ }
+ i := strings.IndexByte(t, '`')
+ if i < 0 {
+ return t
+ }
+ jrel := strings.IndexByte(t[i+1:], '`')
+ if jrel < 0 {
+ return t
+ }
+ j := i + 1 + jrel
+ return t[i+1 : j]
+}
+
func labelForCompletion(cleaned, filter string) string {
label := trimLen(firstLine(cleaned))
if filter != "" && !strings.HasPrefix(strings.ToLower(label), strings.ToLower(filter)) {