diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-22 19:16:39 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-22 19:16:39 +0300 |
| commit | 90a9d57c05c033f19d0c233c8d0454708621d6b9 (patch) | |
| tree | 5b08f6e24ee4fc8d91a158b1bd713b03713a33f3 | |
| parent | 66cb694be4ada7d5249d5c5b6d0f33400691557d (diff) | |
lsp: always trigger completion on inline semicolon prompts (;text; or ';;...;'); relax prefix check accordingly; add tests
| -rw-r--r-- | internal/lsp/completion_prefix_strip_test.go | 11 | ||||
| -rw-r--r-- | internal/lsp/handlers.go | 18 |
2 files changed, 26 insertions, 3 deletions
diff --git a/internal/lsp/completion_prefix_strip_test.go b/internal/lsp/completion_prefix_strip_test.go index c8bd642..199838f 100644 --- a/internal/lsp/completion_prefix_strip_test.go +++ b/internal/lsp/completion_prefix_strip_test.go @@ -50,3 +50,14 @@ func TestTryLLMCompletion_ManualInvokeAfterWhitespace_Allows(t *testing.T) { if !ok { t.Fatalf("expected ok=true for manual invoke after whitespace") } if len(items) == 0 { t.Fatalf("expected at least one completion item") } } + +func TestTryLLMCompletion_InlineSemicolonPromptAlwaysTriggers(t *testing.T) { + s := &Server{ maxTokens: 32, triggerChars: []string{".", ":", "/", "_"}, compCache: make(map[string]string) } + s.llmClient = fakeLLM{resp: "replacement"} + line := "prefix ;do something; suffix" + // No trigger char immediately before cursor; place cursor at end + p := CompletionParams{ Position: Position{ Line: 0, Character: len(line) }, TextDocument: TextDocumentIdentifier{URI: "file://inline.go"} } + items, ok, busy := s.tryLLMCompletion(p, "", line, "", "", "", false, "") + if busy { t.Fatalf("unexpected busy=true") } + if !ok || len(items) == 0 { t.Fatalf("expected completion to trigger on inline ;text; prompt") } +} diff --git a/internal/lsp/handlers.go b/internal/lsp/handlers.go index 69ee7ab..9d58a44 100644 --- a/internal/lsp/handlers.go +++ b/internal/lsp/handlers.go @@ -706,8 +706,10 @@ func (s *Server) tryLLMCompletion(p CompletionParams, above, current, below, fun ctx, cancel := context.WithTimeout(context.Background(), 6*time.Second) defer cancel() - // Only invoke LLM when triggered by one of our trigger characters. - if !s.isTriggerEvent(p, current) { + // Inline prompt markers (strict ;text; or double-; patterns) explicitly allow triggering. + inlinePrompt := lineHasInlinePrompt(current) + // Only invoke LLM when triggered by our characters, manual invoke, or inline prompt markers. + if !inlinePrompt && !s.isTriggerEvent(p, current) { logging.Logf("lsp ", "%scompletion skip=no-trigger line=%d char=%d current=%q%s", logging.AnsiYellow, p.Position.Line, p.Position.Character, trimLen(current), logging.AnsiBase) return []CompletionItem{}, true, false } @@ -750,7 +752,7 @@ func (s *Server) tryLLMCompletion(p CompletionParams, above, current, below, fun if idx > len(current) { idx = len(current) } // Structural triggers allow no prefix allowNoPrefix := false - if manualInvoke { + if manualInvoke || inlinePrompt { allowNoPrefix = true } if idx > 0 { @@ -1184,6 +1186,16 @@ func isIdentChar(ch byte) bool { return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '_' } +// lineHasInlinePrompt returns true if the line contains an inline strict +// semicolon marker ;text; (no spaces at boundaries) or a double-semicolon +// pattern recognized by hasDoubleSemicolonTrigger. +func lineHasInlinePrompt(line string) bool { + if _, _, _, ok := findStrictSemicolonTag(line); ok { + return true + } + return hasDoubleSemicolonTrigger(line) +} + // stripDuplicateAssignmentPrefix removes a duplicated assignment prefix (e.g., // "name :=") from the beginning of the model suggestion when that same prefix // already appears immediately to the left of the cursor on the current line. |
