Skip to content

Commit

Permalink
tabnine-chat-prompt-alist to customize variable
Browse files Browse the repository at this point in the history
  • Loading branch information
shuxiao9058 committed Jul 22, 2023
1 parent 4b997d6 commit 374caa5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
28 changes: 21 additions & 7 deletions tabnine-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,33 @@ 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
;;

(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."
Expand Down Expand Up @@ -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)))
Expand Down
4 changes: 2 additions & 2 deletions tabnine-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit 374caa5

Please sign in to comment.