diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-06 10:56:27 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-06 10:56:27 +0300 |
| commit | 320de746f7a2985b60c8564a0e65bdf231e840b7 (patch) | |
| tree | e70bcf50813dba411afa2934e774383124bbc99e /internal/lsp/completion_provider_fallback_test.go | |
| parent | 06247527d5170f329b454b42f59a3e4434ab1f4b (diff) | |
use gofumpt
Diffstat (limited to 'internal/lsp/completion_provider_fallback_test.go')
| -rw-r--r-- | internal/lsp/completion_provider_fallback_test.go | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/internal/lsp/completion_provider_fallback_test.go b/internal/lsp/completion_provider_fallback_test.go index 04ca7a4..67dc78b 100644 --- a/internal/lsp/completion_provider_fallback_test.go +++ b/internal/lsp/completion_provider_fallback_test.go @@ -1,41 +1,50 @@ package lsp import ( - "context" - "encoding/json" - "io" - "testing" + "context" + "encoding/json" + "io" + "testing" - "codeberg.org/snonux/hexai/internal/llm" + "codeberg.org/snonux/hexai/internal/llm" ) // fakeCompleterErr implements both Client and CodeCompleter; CodeCompletion errors, // forcing tryProviderNativeCompletion to take the error path and fall back to chat. type fakeCompleterErr struct{} -func (fakeCompleterErr) Chat(context.Context, []llm.Message, ...llm.RequestOption) (string, error) { return "X", nil } -func (fakeCompleterErr) Name() string { return "prov" } + +func (fakeCompleterErr) Chat(context.Context, []llm.Message, ...llm.RequestOption) (string, error) { + return "X", nil +} +func (fakeCompleterErr) Name() string { return "prov" } func (fakeCompleterErr) DefaultModel() string { return "m" } -func (fakeCompleterErr) CodeCompletion(context.Context, string, string, int, string, float64) ([]string, error) { return nil, io.EOF } +func (fakeCompleterErr) CodeCompletion(context.Context, string, string, int, string, float64) ([]string, error) { + return nil, io.EOF +} func TestCompletion_FallbackOnProviderError(t *testing.T) { - s := newTestServer() - s.llmClient = fakeCompleterErr{} - // Provide simple document - uri := "file:///x.go" - s.setDocument(uri, "package p\nfunc f(){\nfmt.\n}\n") - // Position after 'fmt.' to satisfy prefix heuristics - p := CompletionParams{TextDocument: TextDocumentIdentifier{URI: uri}, Position: Position{Line:2, Character:4}} - // Build context for trigger character '.' - ctx := struct{ TriggerKind int `json:"triggerKind"`; TriggerCharacter string `json:"triggerCharacter"` }{TriggerKind: 2, TriggerCharacter: "."} - bctx, _ := json.Marshal(ctx) - p.Context = json.RawMessage(bctx) - - // Call handleCompletion and ensure it returns at least one item from chat fallback - var buf nopWriter - s.out = &buf - s.handleCompletion(Request{JSONRPC: "2.0", ID: json.RawMessage("6"), Method: "textDocument/completion", Params: mustJSON(p)}) - // No panic implies path executed; detailed decode not needed here + s := newTestServer() + s.llmClient = fakeCompleterErr{} + // Provide simple document + uri := "file:///x.go" + s.setDocument(uri, "package p\nfunc f(){\nfmt.\n}\n") + // Position after 'fmt.' to satisfy prefix heuristics + p := CompletionParams{TextDocument: TextDocumentIdentifier{URI: uri}, Position: Position{Line: 2, Character: 4}} + // Build context for trigger character '.' + ctx := struct { + TriggerKind int `json:"triggerKind"` + TriggerCharacter string `json:"triggerCharacter"` + }{TriggerKind: 2, TriggerCharacter: "."} + bctx, _ := json.Marshal(ctx) + p.Context = json.RawMessage(bctx) + + // Call handleCompletion and ensure it returns at least one item from chat fallback + var buf nopWriter + s.out = &buf + s.handleCompletion(Request{JSONRPC: "2.0", ID: json.RawMessage("6"), Method: "textDocument/completion", Params: mustJSON(p)}) + // No panic implies path executed; detailed decode not needed here } type nopWriter struct{} + func (nopWriter) Write(p []byte) (int, error) { return len(p), nil } |
