From b5bed4ee62cd8249d3a133163a0d4cc752358a85 Mon Sep 17 00:00:00 2001 From: Aaron Ji Date: Sat, 22 Jul 2023 15:36:21 +0800 Subject: [PATCH] tabnine-chat-prompts-alist to customize variable --- tabnine-chat.el | 28 +++++++++++++++++++++------- tabnine-core.el | 4 ++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tabnine-chat.el b/tabnine-chat.el index 8cb8d04..d52cd2a 100644 --- a/tabnine-chat.el +++ b/tabnine-chat.el @@ -178,6 +178,26 @@ Default 1MB." :group 'tabnine :type 'float) +(defcustom tabnine-chat-prompt-alist '((explain-code . "Explain the selected code") + (generate-test-for-code . "Write tests for the selected code") + (document-code . "Add documentation for the selected code") + (fix-code . "Find errors in the selected code and fix them")) + "Alist of cons cells that map method to TabNine Chat prompt string. +Valid match type keys are: +- explain-code +- generate-test-for-code +- document-code +- fix-code + +The other element of each cons pair in this list is the prompt string to +use for TabNine Chat." + :type '(repeat (cons (choice :tag "Key" + (const explain-code) + (const generate-test-for-code) + (const document-code) + (const fix-code)) + (string :tag "Prompt String")))) + ;; ;; Variables ;; @@ -185,12 +205,6 @@ Default 1MB." (defvar tabnine-chat--conversation-id nil "The TabNine chat conversation id.") -(defvar tabnine-chat-prompts-alist - '((explain-code . "Explain the selected code") - (generate-test-for-code . "Write tests for the selected code") - (document-code ."Add documentation for the selected code") - (fix-code . "Find errors in the selected code and fix them")) - "A list of cons cells that map method to TabNine Chat prompt string.") (defun tabnine-chat--conversion-id() "Get conversion ID." @@ -403,7 +417,7 @@ the response is inserted into the current buffer after point." (save-excursion (goto-char (point-max)) (point-marker)))) - (prompt-by-method (and method (alist-get method tabnine-chat-prompts-alist))) + (prompt-by-method (and method (alist-get method tabnine-chat-prompt-alist))) (prompt (if prompt-by-method prompt-by-method (tabnine-chat--create-prompt response-pt))) diff --git a/tabnine-core.el b/tabnine-core.el index 5781ee3..ab29df9 100644 --- a/tabnine-core.el +++ b/tabnine-core.el @@ -1182,7 +1182,7 @@ command that triggered `post-command-hook'." (let ((completions (mapcar construct-candidate-fn results))) completions)) -(defun tabnine--get-candidates (response) +(defun tabnine--candidates (response) "Get candidates for RESPONSE." (when (tabnine--response-display-with-capf-p response) (let ((candidates (tabnine--construct-candidates @@ -1219,7 +1219,7 @@ command that triggered `post-command-hook'." (start (or (car bounds) pt)) (end (or (cdr bounds) pt)) (response tabnine--completion-cache-result) - (candidates (let* ((candidates (tabnine--get-candidates response))) + (candidates (let* ((candidates (tabnine--candidates response))) (when (tabnine--response-display-with-capf-p response) candidates))) (get-candidates (lambda () candidates)))