|
4 | 4 |
|
5 | 5 | ;; Author: Huming Chen <chenhuming@gmail.com> |
6 | 6 | ;; URL: https://github.com/beacoder/gptel-cpp-complete |
7 | | -;; Version: 0.1.8 |
| 7 | +;; Version: 0.1.9 |
8 | 8 | ;; Created: 2025-12-26 |
9 | 9 | ;; Keywords: programming, convenience |
10 | 10 | ;; Package-Requires: ((emacs "30.1") (eglot "1.19") (gptel "0.9.8")) |
|
49 | 49 | ;; 0.1.6 Remove duplicated texts from completion |
50 | 50 | ;; 0.1.7 Retrieve completion-symbols and fix ag search issue |
51 | 51 | ;; 0.1.8 Show completion only when location didn't change |
| 52 | +;; 0.1.9 Add rg support |
52 | 53 |
|
53 | 54 | ;;; Code: |
54 | 55 |
|
|
84 | 85 | :type 'string |
85 | 86 | :group 'gptel-cpp-complete) |
86 | 87 |
|
| 88 | +(defcustom gptel-cpp-complete-rg-cmd "rg -t cpp -C 3 \"%s\" --no-heading --color never | head -n 30" |
| 89 | + "Rg command to search similar pattern." |
| 90 | + :type 'string |
| 91 | + :group 'gptel-cpp-complete) |
| 92 | + |
87 | 93 | ;; ------------------------------------------------------------ |
88 | 94 | ;; Helpers |
89 | 95 | ;; ------------------------------------------------------------ |
|
226 | 232 | (gptel-cpp-complete--safe-subseq (plist-get classified :vars) 0 1) |
227 | 233 | (gptel-cpp-complete--safe-subseq (plist-get classified :members) 0 1))) |
228 | 234 |
|
229 | | -(defun gptel-cpp-complete--ag-pattern-for-symbol (symbol) |
230 | | - "Format SYMBOL for searching with `ag'." |
| 235 | +(defun gptel-cpp-complete--grep-pattern-for-symbol (symbol) |
| 236 | + "Format SYMBOL for searching with `ag' or `rg'." |
231 | 237 | (let* ((name (plist-get symbol :label)) |
232 | 238 | (kind (plist-get symbol :kind))) |
233 | 239 | (cond |
|
243 | 249 | (t |
244 | 250 | (format "\\b%s\\b" name))))) |
245 | 251 |
|
246 | | -(defun gptel-cpp-complete--ag-search-pattern (pattern) |
247 | | - "Search PATTERN using `ag'." |
248 | | - (shell-command-to-string (format gptel-cpp-complete-ag-cmd pattern))) |
| 252 | +(defun gptel-cpp-complete--grep-search-pattern (pattern) |
| 253 | + "Search PATTERN using `ag' or `rg'." |
| 254 | + (let ((cmd (cond ((executable-find "rg") gptel-cpp-complete-rg-cmd) |
| 255 | + ((executable-find "ag") gptel-cpp-complete-ag-cmd) |
| 256 | + (t (error "Neither rg nor ag found"))))) |
| 257 | + (shell-command-to-string (format cmd pattern)))) |
249 | 258 |
|
250 | | -(defun gptel-cpp-complete--ag-similar-patterns (s-k) |
| 259 | +(defun gptel-cpp-complete--grep-similar-patterns (s-k) |
251 | 260 | "Search similar patterns based on S-K." |
252 | 261 | (let* ((symbols s-k) |
253 | 262 | (classified (gptel-cpp-complete--classify-symbols symbols)) |
254 | 263 | (targets (gptel-cpp-complete--select-search-symbols classified))) |
255 | 264 | (string-join |
256 | 265 | (cl-loop for sym in targets |
257 | | - for pat = (gptel-cpp-complete--ag-pattern-for-symbol sym) |
258 | | - collect (gptel-cpp-complete--ag-search-pattern pat)) |
| 266 | + for pat = (gptel-cpp-complete--grep-pattern-for-symbol sym) |
| 267 | + collect (gptel-cpp-complete--grep-search-pattern pat)) |
259 | 268 | "\n\n"))) |
260 | 269 |
|
261 | 270 | ;; ------------------------------------------------------------ |
@@ -400,7 +409,7 @@ Callees of this function: |
400 | 409 | (symbols+kind (or (gptel-cpp-complete--in-scope-symbols+kind) '())) |
401 | 410 | (symbols (or (delete-dups (mapcar #'car symbols+kind)) '())) |
402 | 411 | (s+k (or (mapcar #'cdr symbols+kind) '())) |
403 | | - (patterns (or (gptel-cpp-complete--ag-similar-patterns s+k) "None found")) |
| 412 | + (patterns (or (gptel-cpp-complete--grep-similar-patterns s+k) "None found")) |
404 | 413 | (calls (and gptel-cpp-complete-include-call-hierarchy |
405 | 414 | (gptel-cpp-complete--call-hierarchy-context))) |
406 | 415 | (incomming (or (car calls) "None found")) |
|
0 commit comments