-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheglot-uniteai.el
147 lines (121 loc) · 4.88 KB
/
eglot-uniteai.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;;; eglot-uniteai.el --- Eglot Clients for UniteAI -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Josh Freckleton
;; Copyright (C) 2023-2025 Shen, Jen-Chieh
;; Author: Josh Freckleton <[email protected]>
;; Shen, Jen-Chieh <[email protected]>
;; Maintainer: Shen, Jen-Chieh <[email protected]>
;; URL: https://github.com/emacs-openai/eglot-uniteai
;; Version: 0.1.0
;; Package-Requires: ((emacs "26.1"))
;; Keywords: convenience ai
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Eglot Clients for UniteAI.
;;
;;; Code:
(require 'eglot)
(defgroup eglot-uniteai nil
"Settings for the UniteAI Language Server."
:group 'eglot
:link '(url-link "https://github.com/emacs-openai/eglot-uniteai"))
(defcustom eglot-uniteai-active-modes
'( markdown-mode org-mode python-mode bibtex-mode clojure-mode coffee-mode
c-mode c++-mode csharp-mode css-mode diff-mode dockerfile-mode fsharp-mode
go-mode groovy-mode html-mode web-mode java-mode js-mode js2-mode json-mode
LaTeX-mode less-css-mode lua-mode makefile-mode objc-mode perl-mode
php-mode text-mode powershell-mode ess-mode ruby-mode rust-mode scss-mode
sass-mode sh-mode sql-mode swift-mode typescript-mode TeX-mode nxml-mode
yaml-mode sh-mode toml-mode)
"List of major mode that work with UniteAI."
:type 'list
:group 'lsp-uniteai)
(defcustom eglot-uniteai-connection-method 'stdio
"Method to connect to the UniteAI language server."
:type '(choice (const :tag "--stdio" stdio)
(const :tag "--tcp" tcp))
:group 'lsp-uniteai)
(defcustom eglot-uniteai-port 5033
"Port number to start the language server."
:type 'integer
:group 'lsp-uniteai)
;;
;; (@* "Client" )
;;
(defun eglot-uniteai--server-command ()
"Generate startup command for UniteAI language server."
(cl-case eglot-uniteai-connection-method
(`stdio (list 'eglot-uniteai-server "uniteai_lsp" "--stdio"))
(`tcp (list 'eglot-uniteai-server "uniteai_lsp" "--tcp" "--lsp_port" eglot-uniteai-port))))
(add-to-list 'eglot-server-programs
`(,eglot-uniteai-active-modes . ,(eglot-uniteai--server-command)))
;;
;; (@* "Util" )
;;
(defun eglot-uniteai--range ()
"Return the current region in LSP scope."
(unless (region-active-p)
(user-error "No region selected"))
(list :start (eglot--pos-to-lsp-position (region-beginning))
:end (eglot--pos-to-lsp-position (region-end))))
;;
;; (@* "Commands" )
;;
;; Global stopping
(defun eglot-uniteai-stop ()
"Stop the UniteAI."
(interactive)
(let* ((server (eglot--current-server-or-lose))
(doc (eglot--TextDocumentIdentifier)))
(eglot-execute-command server 'command.stop (vector doc))))
;; Example Counter
(defun eglot-uniteai-example-counter ()
"TODO: .."
(interactive)
(let* ((server (eglot--current-server-or-lose))
(doc (eglot--TextDocumentIdentifier))
(pos (eglot--pos-to-lsp-position (point))))
(eglot-execute-command server 'command.exampleCounter (vector doc pos))))
;; Local LLM
(defun eglot-uniteai-local-llm ()
"TODO: .."
(interactive)
(let ((server (eglot--current-server-or-lose))
(doc (eglot--TextDocumentIdentifier))
(range (eglot-uniteai--range)))
(eglot-execute-command server 'command.localLlmStream (vector doc range))))
;; Transcription
(defun eglot-uniteai-transcribe ()
"TODO: .."
(interactive)
(let* ((server (eglot--current-server-or-lose))
(doc (eglot--TextDocumentIdentifier))
(pos (eglot--pos-to-lsp-position (point))))
(eglot-execute-command server 'command.transcribe (vector doc pos))))
;; OpenAI
(defun eglot-uniteai-openai-gpt ()
"TODO: .."
(interactive)
(let ((server (eglot--current-server-or-lose))
(doc (eglot--TextDocumentIdentifier))
(range (eglot-uniteai--range)))
(eglot-execute-command server 'command.openaiAutocompleteStream (vector doc range "FROM_CONFIG_COMPLETION" "FROM_CONFIG"))))
(defun eglot-uniteai-openai-chatgpt ()
"TODO: .."
(interactive)
(let* ((server (eglot--current-server-or-lose))
(doc (eglot--TextDocumentIdentifier))
(range (eglot-uniteai--range)))
(eglot-execute-command server 'command.openaiAutocompleteStream (vector doc range "FROM_CONFIG_CHAT" "FROM_CONFIG"))))
(provide 'eglot-uniteai)
;;; eglot-uniteai.el ends here