diff options
Diffstat (limited to 'internal/lsp')
| -rw-r--r-- | internal/lsp/codeaction_custom_test.go | 18 | ||||
| -rw-r--r-- | internal/lsp/document_test.go | 45 | ||||
| -rw-r--r-- | internal/lsp/ignore_test.go | 12 | ||||
| -rw-r--r-- | internal/lsp/server_test.go | 4 | ||||
| -rw-r--r-- | internal/lsp/triggers_config_test.go | 4 |
5 files changed, 46 insertions, 37 deletions
diff --git a/internal/lsp/codeaction_custom_test.go b/internal/lsp/codeaction_custom_test.go index 36f99d4..d7fe283 100644 --- a/internal/lsp/codeaction_custom_test.go +++ b/internal/lsp/codeaction_custom_test.go @@ -30,13 +30,17 @@ func capResp(t *testing.T, buf *bytes.Buffer) Response { func TestHandleCodeAction_ListsCustomActions(t *testing.T) { var out bytes.Buffer cfg := appconfig.App{ - InlineOpen: ">!", - InlineClose: ">", - ChatSuffix: ">", - ChatPrefixes: []string{"?", "!", ":", ";"}, - CustomActions: []appconfig.CustomAction{ - {ID: "extract", Title: "Extract function", Scope: "selection", Kind: "refactor.extract", Instruction: "Extract into function"}, - {ID: "fix", Title: "Fix diagnostics", Scope: "diagnostics", Kind: "quickfix", User: "Fix:\n{{diagnostics}}\n\n{{selection}}"}, + CoreConfig: appconfig.CoreConfig{ + InlineOpen: ">!", + InlineClose: ">", + ChatSuffix: ">", + ChatPrefixes: []string{"?", "!", ":", ";"}, + }, + PromptConfig: appconfig.PromptConfig{ + CustomActions: []appconfig.CustomAction{ + {ID: "extract", Title: "Extract function", Scope: "selection", Kind: "refactor.extract", Instruction: "Extract into function"}, + {ID: "fix", Title: "Fix diagnostics", Scope: "diagnostics", Kind: "quickfix", User: "Fix:\n{{diagnostics}}\n\n{{selection}}"}, + }, }, } s := &Server{ diff --git a/internal/lsp/document_test.go b/internal/lsp/document_test.go index 3dc970d..c805d22 100644 --- a/internal/lsp/document_test.go +++ b/internal/lsp/document_test.go @@ -12,27 +12,30 @@ import ( func newTestServer() *Server { cfg := appconfig.App{ - InlineOpen: ">!", - InlineClose: ">", - ChatSuffix: ">", - ChatPrefixes: []string{"?", "!", ":", ";"}, - - PromptCompletionSystemParams: "You are a code completion engine for function signatures. Return only the parameter list contents (without parentheses), no braces, no prose. Prefer idiomatic names and types.", - PromptCompletionUserParams: "Cursor is inside the function parameter list. Suggest only the parameter list (no parentheses).\nFunction line: {{function}}\nCurrent line (cursor at {{char}}): {{current}}", - PromptCompletionSystemGeneral: "You are a terse code completion engine. Return only the code to insert, no surrounding prose or backticks. Only continue from the cursor; never repeat characters already present to the left of the cursor on the current line (e.g., if 'name :=' is already typed, only return the right-hand side expression).", - PromptCompletionUserGeneral: "Provide the next likely code to insert at the cursor.\nFile: {{file}}\nFunction/context: {{function}}\nAbove line: {{above}}\nCurrent line (cursor at character {{char}}): {{current}}\nBelow line: {{below}}\nOnly return the completion snippet.", - PromptCompletionSystemInline: "You are a precise code completion/refactoring engine. Output only the code to insert with no prose, no comments, and no backticks. Return raw code only.", - PromptCompletionExtraHeader: "Additional context:\n{{context}}", - PromptNativeCompletion: "// Path: {{path}}\n{{before}}", - PromptChatSystem: "You are a helpful coding assistant. Answer concisely and clearly.", - PromptCodeActionRewriteSystem: "You are a precise code refactoring engine. Rewrite the given code strictly according to the instruction. Return only the updated code with no prose or backticks. Preserve formatting where reasonable.", - PromptCodeActionDiagnosticsSystem: "You are a precise code fixer. Resolve the given diagnostics by editing only the selected code. Return only the corrected code with no prose or backticks. Keep behavior and style, and avoid unrelated changes.", - PromptCodeActionDocumentSystem: "You are a precise code documentation engine. Add idiomatic documentation comments to the given code. Preserve exact behavior and formatting as much as possible. Return only the updated code with comments, no prose or backticks.", - PromptCodeActionRewriteUser: "Instruction: {{instruction}}\n\nSelected code to transform:\n{{selection}}", - PromptCodeActionDiagnosticsUser: "Diagnostics to resolve (selection only):\n{{diagnostics}}\n\nSelected code:\n{{selection}}", - PromptCodeActionDocumentUser: "Add documentation comments to this code:\n{{selection}}", - PromptCodeActionGoTestSystem: "You are a precise Go unit test generator. Given a Go function, write one or more Test* functions using the testing package. Do NOT include package or imports, only the test function(s). Prefer table-driven tests. Keep it minimal and idiomatic.", - PromptCodeActionGoTestUser: "Function under test:\n{{function}}", + CoreConfig: appconfig.CoreConfig{ + InlineOpen: ">!", + InlineClose: ">", + ChatSuffix: ">", + ChatPrefixes: []string{"?", "!", ":", ";"}, + }, + PromptConfig: appconfig.PromptConfig{ + PromptCompletionSystemParams: "You are a code completion engine for function signatures. Return only the parameter list contents (without parentheses), no braces, no prose. Prefer idiomatic names and types.", + PromptCompletionUserParams: "Cursor is inside the function parameter list. Suggest only the parameter list (no parentheses).\nFunction line: {{function}}\nCurrent line (cursor at {{char}}): {{current}}", + PromptCompletionSystemGeneral: "You are a terse code completion engine. Return only the code to insert, no surrounding prose or backticks. Only continue from the cursor; never repeat characters already present to the left of the cursor on the current line (e.g., if 'name :=' is already typed, only return the right-hand side expression).", + PromptCompletionUserGeneral: "Provide the next likely code to insert at the cursor.\nFile: {{file}}\nFunction/context: {{function}}\nAbove line: {{above}}\nCurrent line (cursor at character {{char}}): {{current}}\nBelow line: {{below}}\nOnly return the completion snippet.", + PromptCompletionSystemInline: "You are a precise code completion/refactoring engine. Output only the code to insert with no prose, no comments, and no backticks. Return raw code only.", + PromptCompletionExtraHeader: "Additional context:\n{{context}}", + PromptNativeCompletion: "// Path: {{path}}\n{{before}}", + PromptChatSystem: "You are a helpful coding assistant. Answer concisely and clearly.", + PromptCodeActionRewriteSystem: "You are a precise code refactoring engine. Rewrite the given code strictly according to the instruction. Return only the updated code with no prose or backticks. Preserve formatting where reasonable.", + PromptCodeActionDiagnosticsSystem: "You are a precise code fixer. Resolve the given diagnostics by editing only the selected code. Return only the corrected code with no prose or backticks. Keep behavior and style, and avoid unrelated changes.", + PromptCodeActionDocumentSystem: "You are a precise code documentation engine. Add idiomatic documentation comments to the given code. Preserve exact behavior and formatting as much as possible. Return only the updated code with comments, no prose or backticks.", + PromptCodeActionRewriteUser: "Instruction: {{instruction}}\n\nSelected code to transform:\n{{selection}}", + PromptCodeActionDiagnosticsUser: "Diagnostics to resolve (selection only):\n{{diagnostics}}\n\nSelected code:\n{{selection}}", + PromptCodeActionDocumentUser: "Add documentation comments to this code:\n{{selection}}", + PromptCodeActionGoTestSystem: "You are a precise Go unit test generator. Given a Go function, write one or more Test* functions using the testing package. Do NOT include package or imports, only the test function(s). Prefer table-driven tests. Keep it minimal and idiomatic.", + PromptCodeActionGoTestUser: "Function under test:\n{{function}}", + }, } return &Server{ logger: log.New(io.Discard, "", 0), diff --git a/internal/lsp/ignore_test.go b/internal/lsp/ignore_test.go index 7df7428..d7b6776 100644 --- a/internal/lsp/ignore_test.go +++ b/internal/lsp/ignore_test.go @@ -15,11 +15,13 @@ import ( // from the given gitRoot and extra patterns. func newIgnoreTestServer(gitRoot string, useGI bool, extra []string, notifyIgnored *bool) *Server { cfg := appconfig.App{ - IgnoreLSPNotify: notifyIgnored, - InlineOpen: ">!", - InlineClose: ">", - ChatSuffix: ">", - ChatPrefixes: []string{"?", "!", ":", ";"}, + CoreConfig: appconfig.CoreConfig{ + InlineOpen: ">!", + InlineClose: ">", + ChatSuffix: ">", + ChatPrefixes: []string{"?", "!", ":", ";"}, + }, + FeatureConfig: appconfig.FeatureConfig{IgnoreLSPNotify: notifyIgnored}, } s := &Server{ logger: log.New(io.Discard, "", 0), diff --git a/internal/lsp/server_test.go b/internal/lsp/server_test.go index 836e43f..dc20eed 100644 --- a/internal/lsp/server_test.go +++ b/internal/lsp/server_test.go @@ -11,7 +11,7 @@ import ( func TestPromptSetUsesConfigStoreSnapshot(t *testing.T) { s := newTestServer() - initial := appconfig.App{MaxTokens: 77} + initial := appconfig.App{CoreConfig: appconfig.CoreConfig{MaxTokens: 77}} store := runtimeconfig.New(initial) s.configStore = store @@ -75,7 +75,7 @@ func (stubLLMClient) DefaultModel() string { return "stub-model" } func TestServerApplyOptions(t *testing.T) { s := newTestServer() client := stubLLMClient{} - cfg := appconfig.App{MaxTokens: 88} + cfg := appconfig.App{CoreConfig: appconfig.CoreConfig{MaxTokens: 88}} opts := ServerOptions{Config: &cfg, Client: client} s.ApplyOptions(opts) if s.currentLLMClient() != client { diff --git a/internal/lsp/triggers_config_test.go b/internal/lsp/triggers_config_test.go index 193e117..dbcefd0 100644 --- a/internal/lsp/triggers_config_test.go +++ b/internal/lsp/triggers_config_test.go @@ -30,7 +30,7 @@ func TestShouldSuppressForChatTriggerEOL_CustomConfig(t *testing.T) { func TestNewServer_AssignsTriggerGlobals_AndParsingUsesThem(t *testing.T) { var out bytes.Buffer - cfg := appconfig.App{InlineOpen: "<", InlineClose: ">", ChatSuffix: ")", ChatPrefixes: []string{":"}} + cfg := appconfig.App{CoreConfig: appconfig.CoreConfig{InlineOpen: "<", InlineClose: ">", ChatSuffix: ")", ChatPrefixes: []string{":"}}} s := NewServer(bytes.NewReader(nil), &out, log.New(io.Discard, "", 0), ServerOptions{Config: &cfg}) openStr, _, openChar, closeChar := s.inlineMarkers() if openChar != '<' || closeChar != '>' { @@ -68,7 +68,7 @@ func TestIsTriggerEvent_BareDoubleOpenBlocksEvenWithContextTriggerChar(t *testin func TestDetectAndHandleChat_CustomConfig_InsertsReply(t *testing.T) { var out bytes.Buffer - cfg := appconfig.App{ChatSuffix: "#", ChatPrefixes: []string{")"}} + cfg := appconfig.App{CoreConfig: appconfig.CoreConfig{ChatSuffix: "#", ChatPrefixes: []string{")"}}} s := NewServer(bytes.NewReader(nil), &out, log.New(io.Discard, "", 0), ServerOptions{Config: &cfg}) s.llmClient = fakeLLM{resp: "Hello\nmulti-line reply"} uri := "file:///chat2.go" |
