summaryrefslogtreecommitdiff
path: root/internal/lsp/document_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-17 00:06:00 +0300
committerPaul Buetow <paul@buetow.org>2025-08-17 00:06:00 +0300
commitdc383b4faef881f3bb22816f42c53a79236a4152 (patch)
tree7c6a48487fc1d51fed72ea5d15618d133132cdaa /internal/lsp/document_test.go
parent6a1d48036105e92193aef11a15a77a569eeb1562 (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/document_test.go')
-rw-r--r--internal/lsp/document_test.go104
1 files changed, 52 insertions, 52 deletions
diff --git a/internal/lsp/document_test.go b/internal/lsp/document_test.go
index 8d81a99..e8fa6bb 100644
--- a/internal/lsp/document_test.go
+++ b/internal/lsp/document_test.go
@@ -1,76 +1,76 @@
package lsp
import (
- "io"
- "log"
- "strings"
- "testing"
+ "io"
+ "log"
+ "strings"
+ "testing"
)
func newTestServer() *Server {
- return &Server{
- logger: log.New(io.Discard, "", 0),
- docs: make(map[string]*document),
- }
+ return &Server{
+ logger: log.New(io.Discard, "", 0),
+ docs: make(map[string]*document),
+ }
}
func TestSplitLines(t *testing.T) {
- in := "a\r\nb\nc"
- got := splitLines(in)
- want := []string{"a", "b", "c"}
- if len(got) != len(want) {
- t.Fatalf("len mismatch: got %d want %d", len(got), len(want))
- }
- for i := range want {
- if got[i] != want[i] {
- t.Fatalf("line %d: got %q want %q", i, got[i], want[i])
- }
- }
+ in := "a\r\nb\nc"
+ got := splitLines(in)
+ want := []string{"a", "b", "c"}
+ if len(got) != len(want) {
+ t.Fatalf("len mismatch: got %d want %d", len(got), len(want))
+ }
+ for i := range want {
+ if got[i] != want[i] {
+ t.Fatalf("line %d: got %q want %q", i, got[i], want[i])
+ }
+ }
}
func TestLineContext(t *testing.T) {
- s := newTestServer()
- src := "package main\n\nfunc add(a, b int) int {\n\treturn a + b\n}\n"
- uri := "file:///test.go"
- s.setDocument(uri, src)
+ s := newTestServer()
+ src := "package main\n\nfunc add(a, b int) int {\n\treturn a + b\n}\n"
+ uri := "file:///test.go"
+ s.setDocument(uri, src)
- // Position on the return line (line 3, zero-based)
- above, current, below, funcCtx := s.lineContext(uri, Position{Line: 3, Character: 0})
+ // Position on the return line (line 3, zero-based)
+ above, current, below, funcCtx := s.lineContext(uri, Position{Line: 3, Character: 0})
- if want := "func add(a, b int) int {"; funcCtx != want {
- t.Fatalf("funcCtx got %q want %q", funcCtx, want)
- }
- if want := "func add(a, b int) int {"; above != want {
- t.Fatalf("above got %q want %q", above, want)
- }
- if want := "\treturn a + b"; current != want {
- t.Fatalf("current got %q want %q", current, want)
- }
- if want := "}"; below != want {
- t.Fatalf("below got %q want %q", below, want)
- }
+ if want := "func add(a, b int) int {"; funcCtx != want {
+ t.Fatalf("funcCtx got %q want %q", funcCtx, want)
+ }
+ if want := "func add(a, b int) int {"; above != want {
+ t.Fatalf("above got %q want %q", above, want)
+ }
+ if want := "\treturn a + b"; current != want {
+ t.Fatalf("current got %q want %q", current, want)
+ }
+ if want := "}"; below != want {
+ t.Fatalf("below got %q want %q", below, want)
+ }
}
func TestLineContext_EmptyDoc(t *testing.T) {
- s := newTestServer()
- a, c, b, f := s.lineContext("file:///missing.go", Position{Line: 0, Character: 0})
- if a != "" || b != "" || c != "" || f != "" {
- t.Fatalf("expected all empty for missing doc; got above=%q current=%q below=%q func=%q", a, c, b, f)
- }
+ s := newTestServer()
+ a, c, b, f := s.lineContext("file:///missing.go", Position{Line: 0, Character: 0})
+ if a != "" || b != "" || c != "" || f != "" {
+ t.Fatalf("expected all empty for missing doc; got above=%q current=%q below=%q func=%q", a, c, b, f)
+ }
}
func TestTrimLen(t *testing.T) {
- long := strings.Repeat("a", 205)
- got := trimLen(long)
- want := strings.Repeat("a", 200) + "…"
- if got != want {
- t.Fatalf("trimLen got %q want %q", got, want)
- }
+ long := strings.Repeat("a", 205)
+ got := trimLen(long)
+ want := strings.Repeat("a", 200) + "…"
+ if got != want {
+ t.Fatalf("trimLen got %q want %q", got, want)
+ }
}
func TestFirstLine(t *testing.T) {
- s := "first line\r\nsecond line"
- if got := firstLine(s); got != "first line" {
- t.Fatalf("firstLine got %q want %q", got, "first line")
- }
+ s := "first line\r\nsecond line"
+ if got := firstLine(s); got != "first line" {
+ t.Fatalf("firstLine got %q want %q", got, "first line")
+ }
}