summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-04 08:57:04 +0300
committerPaul Buetow <paul@buetow.org>2025-09-04 08:57:04 +0300
commitba2e2a14edb310fc03b6a8e0e809af50474a4ecf (patch)
tree2d9f0ac36b7a323a7d97fa56e70a6e4261e6a336
parent9b5ce6a6ffc8d9ff10ae8d2c384efd91de8d2b76 (diff)
tests(lsp): add completion helper tests (trigger info, suppression, prefix heuristics)
-rw-r--r--internal/lsp/completion_helpers_more_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/lsp/completion_helpers_more_test.go b/internal/lsp/completion_helpers_more_test.go
new file mode 100644
index 0000000..02fe9f3
--- /dev/null
+++ b/internal/lsp/completion_helpers_more_test.go
@@ -0,0 +1,35 @@
+package lsp
+
+import (
+ "encoding/json"
+ "testing"
+)
+
+func TestExtractTriggerInfo_ParseManualInvoke(t *testing.T) {
+ // Compose a CompletionParams with a raw JSON context
+ ctx := struct{ TriggerKind int `json:"triggerKind"`; TriggerCharacter string `json:"triggerCharacter"` }{TriggerKind: 1, TriggerCharacter: "."}
+ raw, _ := json.Marshal(ctx)
+ p := CompletionParams{Context: json.RawMessage(raw)}
+ kind, ch := extractTriggerInfo(p)
+ if kind != 1 || ch != "." { t.Fatalf("unexpected trigger info: %d %q", kind, ch) }
+ if !parseManualInvoke(json.RawMessage(raw)) { t.Fatalf("expected manual invoke true") }
+}
+
+func TestShouldSuppressForChatTriggerEOL(t *testing.T) {
+ s := newTestServer()
+ p := CompletionParams{TextDocument: TextDocumentIdentifier{URI: "file:///x"}, Position: Position{Line:0, Character:10}}
+ line := "say hi;>"
+ if !s.shouldSuppressForChatTriggerEOL(line, p) { t.Fatalf("expected suppression when ;> at EOL") }
+ if s.shouldSuppressForChatTriggerEOL("plain>", p) { t.Fatalf("should not suppress for plain >") }
+}
+
+func TestPrefixHeuristicAllows(t *testing.T) {
+ s := newTestServer()
+ // inline prompt allows zero prefix
+ if !s.prefixHeuristicAllows(true, "", CompletionParams{Position: Position{Line:0, Character:0}}, false) { t.Fatalf("inline prompt should allow") }
+ // structural triggers like '.' allow without prefix
+ if !s.prefixHeuristicAllows(false, "fmt.", CompletionParams{Position: Position{Line:0, Character:4}}, false) { t.Fatalf("dot trigger should allow") }
+ // otherwise need at least minimal prefix (default min=1)
+ if s.prefixHeuristicAllows(false, " ", CompletionParams{Position: Position{Line:0, Character:0}}, false) { t.Fatalf("should not allow with no prefix") }
+}
+