diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-17 00:06:00 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-17 00:06:00 +0300 |
| commit | dc383b4faef881f3bb22816f42c53a79236a4152 (patch) | |
| tree | 7c6a48487fc1d51fed72ea5d15618d133132cdaa /internal/lsp/context_test.go | |
| parent | 6a1d48036105e92193aef11a15a77a569eeb1562 (diff) | |
lsp/config: make completion trigger characters configurable
- Add trigger_characters to JSON config and ServerOptions
- Store on server and advertise in initialize
- Update README and example config
- Preserve previous defaults when unset
Diffstat (limited to 'internal/lsp/context_test.go')
| -rw-r--r-- | internal/lsp/context_test.go | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/internal/lsp/context_test.go b/internal/lsp/context_test.go index 32834b8..fe5d73b 100644 --- a/internal/lsp/context_test.go +++ b/internal/lsp/context_test.go @@ -1,69 +1,69 @@ package lsp import ( - "strconv" - "strings" - "testing" + "strconv" + "strings" + "testing" ) func TestWindowContext_Bounds(t *testing.T) { - s := newTestServer() - s.windowLines = 4 // half=2 - s.maxContextTokens = 9999 - lines := make([]string, 10) - for i := 0; i < 10; i++ { - lines[i] = "L" + strconv.Itoa(i) - } - text := strings.Join(lines, "\n") - uri := "file:///w.go" - s.setDocument(uri, text) - got := s.windowContext(uri, Position{Line: 5, Character: 0}) - // expect lines 3..7 inclusive - want := strings.Join(lines[3:8], "\n") - if got != want { - t.Fatalf("window context got %q want %q", got, want) - } + s := newTestServer() + s.windowLines = 4 // half=2 + s.maxContextTokens = 9999 + lines := make([]string, 10) + for i := 0; i < 10; i++ { + lines[i] = "L" + strconv.Itoa(i) + } + text := strings.Join(lines, "\n") + uri := "file:///w.go" + s.setDocument(uri, text) + got := s.windowContext(uri, Position{Line: 5, Character: 0}) + // expect lines 3..7 inclusive + want := strings.Join(lines[3:8], "\n") + if got != want { + t.Fatalf("window context got %q want %q", got, want) + } } func TestBuildAdditionalContext_Minimal(t *testing.T) { - s := newTestServer() - s.contextMode = "minimal" - if ctx, ok := s.buildAdditionalContext(false, "file:///x.go", Position{}); ok || ctx != "" { - t.Fatalf("expected no context in minimal mode; got ok=%v ctx=%q", ok, ctx) - } + s := newTestServer() + s.contextMode = "minimal" + if ctx, ok := s.buildAdditionalContext(false, "file:///x.go", Position{}); ok || ctx != "" { + t.Fatalf("expected no context in minimal mode; got ok=%v ctx=%q", ok, ctx) + } } func TestBuildAdditionalContext_FileOnNewFunc(t *testing.T) { - s := newTestServer() - s.contextMode = "file-on-new-func" - s.maxContextTokens = 9999 - uri := "file:///x.go" - body := "package x\n\nfunc a(){}\n" - s.setDocument(uri, body) - if ctx, ok := s.buildAdditionalContext(true, uri, Position{}); !ok || ctx == "" { - t.Fatalf("expected full context when new func; ok=%v ctx=%q", ok, ctx) - } - if ctx, ok := s.buildAdditionalContext(false, uri, Position{}); ok || ctx != "" { - t.Fatalf("expected no context when not new func; ok=%v ctx=%q", ok, ctx) - } + s := newTestServer() + s.contextMode = "file-on-new-func" + s.maxContextTokens = 9999 + uri := "file:///x.go" + body := "package x\n\nfunc a(){}\n" + s.setDocument(uri, body) + if ctx, ok := s.buildAdditionalContext(true, uri, Position{}); !ok || ctx == "" { + t.Fatalf("expected full context when new func; ok=%v ctx=%q", ok, ctx) + } + if ctx, ok := s.buildAdditionalContext(false, uri, Position{}); ok || ctx != "" { + t.Fatalf("expected no context when not new func; ok=%v ctx=%q", ok, ctx) + } } func TestBuildAdditionalContext_AlwaysFull(t *testing.T) { - s := newTestServer() - s.contextMode = "always-full" - s.maxContextTokens = 9999 - uri := "file:///x.go" - body := "line1\nline2\n" - s.setDocument(uri, body) - if ctx, ok := s.buildAdditionalContext(false, uri, Position{}); !ok || ctx == "" { - t.Fatalf("expected context in always-full; ok=%v ctx=%q", ok, ctx) - } + s := newTestServer() + s.contextMode = "always-full" + s.maxContextTokens = 9999 + uri := "file:///x.go" + body := "line1\nline2\n" + s.setDocument(uri, body) + if ctx, ok := s.buildAdditionalContext(false, uri, Position{}); !ok || ctx == "" { + t.Fatalf("expected context in always-full; ok=%v ctx=%q", ok, ctx) + } } func TestTruncateToApproxTokens(t *testing.T) { - text := strings.Repeat("abcd", 10) // 40 chars - got := truncateToApproxTokens(text, 5) // ~20 chars - if len(got) > 5*4 { - t.Fatalf("truncate exceeded budget: got len=%d budget=%d", len(got), 5*4) - } + text := strings.Repeat("abcd", 10) // 40 chars + got := truncateToApproxTokens(text, 5) // ~20 chars + if len(got) > 5*4 { + t.Fatalf("truncate exceeded budget: got len=%d budget=%d", len(got), 5*4) + } } |
