From f14eb9199f4e1aee49594e590c08996244bb77b3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 28 Sep 2025 21:56:32 +0300 Subject: Add slash toggle for completions --- internal/lsp/completion_toggle_test.go | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 internal/lsp/completion_toggle_test.go (limited to 'internal/lsp/completion_toggle_test.go') diff --git a/internal/lsp/completion_toggle_test.go b/internal/lsp/completion_toggle_test.go new file mode 100644 index 0000000..57ee1fd --- /dev/null +++ b/internal/lsp/completion_toggle_test.go @@ -0,0 +1,46 @@ +package lsp + +import ( + "bytes" + "encoding/json" + "strings" + "testing" +) + +func TestHandleCompletionRespectsDisableCommand(t *testing.T) { + s := newTestServer() + var buf bytes.Buffer + s.out = &buf + + // Disable completions and trigger handler + s.setCompletionsDisabled(true) + + params := CompletionParams{TextDocument: TextDocumentIdentifier{URI: "file:///test.go"}, Position: Position{Line: 0, Character: 0}} + req := Request{JSONRPC: "2.0", ID: json.RawMessage("1"), Method: "textDocument/completion", Params: mustJSON(params)} + + s.handleCompletion(req) + + payload := buf.String() + parts := strings.SplitN(payload, "\r\n\r\n", 2) + if len(parts) != 2 { + t.Fatalf("unexpected response framing: %q", payload) + } + var resp Response + if err := json.Unmarshal([]byte(parts[1]), &resp); err != nil { + t.Fatalf("unmarshal response: %v", err) + } + resultMap, ok := resp.Result.(map[string]any) + if !ok { + t.Fatalf("expected map result, got %T", resp.Result) + } + switch v := resultMap["items"].(type) { + case []any: + if len(v) != 0 { + t.Fatalf("expected no completion items when disabled, got %d", len(v)) + } + case nil: + // ok: encoder emitted null for slice + default: + t.Fatalf("expected items slice or null, got %T", v) + } +} -- cgit v1.2.3