summaryrefslogtreecommitdiff
path: root/internal/lsp/helpers_inline_prompt_test.go
blob: 5dc698a8007813a1ab4030a0322ae5e986a12c20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package lsp

import (
	"encoding/json"
	"testing"
)

func TestLineHasInlinePrompt_BasicAndDoubleOpen(t *testing.T) {
	// Basic inline
	if !lineHasInlinePrompt("do >!task> now", ">!", '>', '>') {
		t.Fatalf("expected inline prompt detection for >!text>")
	}
	// Double-open variant should be recognized as inline prompt too
	if !lineHasInlinePrompt(">>!replace>", ">!", '>', '>') {
		t.Fatalf("expected inline prompt detection for >>!text>")
	}
}

func TestIsTriggerEvent_TriggerCharNotAllowed(t *testing.T) {
	s := newTestServer()
	cfg := s.cfg
	cfg.TriggerCharacters = []string{"."}
	s.cfg = cfg
	p := CompletionParams{Position: Position{Line: 0, Character: 3}}
	if s.isTriggerEvent(p, "ab:") { // ':' not in triggerChars
		t.Fatalf("expected false when TriggerCharacter not configured")
	}
}

func TestShouldSuppressForChatTriggerEOL_EmptySuffix_NoSuppression(t *testing.T) {
	s := newTestServer()
	cfg := s.cfg
	cfg.ChatSuffix = ""
	s.cfg = cfg
	p := CompletionParams{Position: Position{Line: 0, Character: 5}}
	if s.shouldSuppressForChatTriggerEOL("What?>", p) {
		t.Fatalf("expected no suppression when chat suffix is empty")
	}
}

func TestIsTriggerEvent_TriggerCharacterMissing_ReturnsFalse(t *testing.T) {
	s := newTestServer()
	// Context says TriggerCharacter, but none provided
	ctx := struct {
		TriggerKind int `json:"triggerKind"`
	}{TriggerKind: 2}
	raw, _ := json.Marshal(ctx)
	p := CompletionParams{Position: Position{Line: 0, Character: 1}, Context: json.RawMessage(raw)}
	if s.isTriggerEvent(p, "a") {
		t.Fatalf("expected false when TriggerCharacter kind with empty char")
	}
}

func TestIsTriggerEvent_TriggerForIncomplete_FallsBackToChar(t *testing.T) {
	s := newTestServer()
	cfg := s.cfg
	cfg.TriggerCharacters = []string{"."}
	s.cfg = cfg
	// TriggerKind=3 should consult fallback char check
	ctx := struct {
		TriggerKind int `json:"triggerKind"`
	}{TriggerKind: 3}
	raw, _ := json.Marshal(ctx)
	p := CompletionParams{Position: Position{Line: 0, Character: 2}, Context: json.RawMessage(raw)}
	if !s.isTriggerEvent(p, "x.") {
		t.Fatalf("expected true via fallback char for TriggerForIncomplete")
	}
}