From 87076072cb63c560407b11e50b0293c5ac33307f Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Mon, 18 Mar 2024 02:08:22 +0200 Subject: [PATCH] Fold completion backends (and their features) into the core package * The CAPF backend gets feature parity (doc-buffer, location, kind icons). * The `company-robe` backend is moved into the main file. * The ac backend is deleted. Any existing users should try the `ac-capf` bridge. Resolves #62, resolves #71. --- README.md | 10 ++----- ac-robe.el | 44 ---------------------------- company-robe.el | 69 ------------------------------------------- robe.el | 78 ++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 79 insertions(+), 122 deletions(-) delete mode 100644 ac-robe.el delete mode 100644 company-robe.el diff --git a/README.md b/README.md index dd0de90..f90042a 100644 --- a/README.md +++ b/README.md @@ -94,19 +94,13 @@ Note that if your project is using `Bundler`, all dependencies have to be in the '(push 'company-robe company-backends)) ``` -### [auto-complete](https://github.com/auto-complete/auto-complete): - -```emacs -(add-hook 'robe-mode-hook 'ac-robe-setup) -``` +Built-in completion (triggered with C-M-i) is also supported, +no extra setup required. Both of the above work only when the connection to the Ruby subprocess has been established. To do that, either use one of the core Robe commands, or type M-x robe-start. -Built-in completion (triggered with C-M-i) is also supported, -no extra setup required. - ## Integration with rvm.el [rvm.el](https://github.com/senny/rvm.el) may not have activated the diff --git a/ac-robe.el b/ac-robe.el deleted file mode 100644 index 2659790..0000000 --- a/ac-robe.el +++ /dev/null @@ -1,44 +0,0 @@ -(eval-when-compile (require 'robe)) - -(defun ac-robe-doc (symbol) - "Return popup documentation for `auto-complete'." - (when robe-running - (let ((spec (car (robe-cached-specs symbol)))) - (when spec - (concat (robe-signature spec) - "\n\n" - (cdr (assoc 'docstring (robe-doc-for spec)))))))) - -;;;###autoload -(defun ac-robe-available () - "Return t if `robe-mode' completions are available, otherwise nil." - (and (boundp 'robe-mode) robe-mode)) - -(defun ac-robe-prefix () - (let ((bounds (robe-complete-bounds))) - (when (and bounds (robe-complete-symbol-p (car bounds))) - (car bounds)))) - -(defun ac-robe-candidates () - "Return completion candidates for `ac-prefix'." - (require 'robe) - (when (robe-running-p) - (let (robe-highlight-capf-candidates) - (robe-complete-thing ac-prefix)))) - -;;;###autoload -(defun ac-robe-setup () - (push 'ac-source-robe ac-sources)) - -(define-obsolete-function-alias 'robe-ac-setup 'ac-robe-setup "0.7.8") - -;;;###autoload -(defconst ac-source-robe - '((available . ac-robe-available) - (prefix . ac-robe-prefix) - (candidates . ac-robe-candidates) - (document . ac-robe-doc) - (symbol . "r")) - "`auto-complete' completion source for Ruby using `robe-mode'.") - -(provide 'ac-robe) diff --git a/company-robe.el b/company-robe.el deleted file mode 100644 index 0686162..0000000 --- a/company-robe.el +++ /dev/null @@ -1,69 +0,0 @@ -(eval-when-compile (require 'robe)) - -;;;###autoload -(defun company-robe (command &optional arg &rest ignore) - "A `company-mode' completion back-end for `robe-mode'." - (interactive (list 'interactive)) - (cl-case command - (interactive (company-begin-backend 'company-robe)) - (prefix (and (boundp 'robe-mode) - robe-mode (robe-running-p) - (company-robe--prefix))) - (candidates (robe-complete-thing arg)) - (duplicates t) - (meta (company-robe--meta arg)) - (location (let ((spec (company-robe--choose-spec arg))) - (cons (robe-spec-file spec) - (robe-spec-line spec)))) - (kind (company-robe--kind arg)) - (annotation (robe-complete-annotation arg)) - (doc-buffer (let ((spec (company-robe--choose-spec arg)) - (inhibit-redisplay t) - ;; XXX: Maybe revisit company-mode/company-mode#548. - (timer-list nil)) - (when spec - (save-window-excursion - (robe-show-doc spec) - (message nil) - (get-buffer "*robe-doc*"))))))) - -(defun company-robe--meta (completion) - (if-let ((type (get-text-property 0 'robe-type completion))) - (if-let ((vtype (get-text-property 0 'robe-variable-type completion))) - (format "%s => %s" type (propertize vtype 'face 'font-lock-type-face)) - type) - (let ((spec (car (robe-cached-specs completion)))) - (when spec (robe-signature spec))))) - -(defun company-robe--prefix () - (let ((bounds (robe-complete-bounds))) - (when (and bounds - (equal (point) (cdr bounds)) - (robe-complete-symbol-p (car bounds))) - (buffer-substring (car bounds) (cdr bounds))))) - -(defun company-robe--choose-spec (thing) - (let ((specs (robe-cached-specs thing))) - (when specs - (if (cdr specs) - (let ((alist (cl-loop for spec in specs - for module = (robe-spec-module spec) - when module - collect (cons module spec)))) - (cdr (assoc (robe-completing-read "Module: " alist nil t) alist))) - (car specs))))) - -(defun company-robe--kind (arg) - (let (case-fold-search) - (cond - ((string-match "\\(?:\\`\\|::\\)\\(?:[A-Z_0-9]*\\|\\([A-Z][A-Z_a-z0-9]*\\)\\)\\'" arg) - (if (match-beginning 1) - 'module - 'constant)) - ((string-match-p "\\`@" arg) - 'variable) - ((get-text-property 0 'robe-type arg) - 'value) - (t 'method)))) - -(provide 'company-robe) diff --git a/robe.el b/robe.el index 70b7017..c40ff02 100644 --- a/robe.el +++ b/robe.el @@ -949,7 +949,11 @@ Only works with Rails, see e.g. `rinari-console'." (when (robe-complete-symbol-p (car bounds)) (list (car bounds) (cdr bounds) fn :annotation-function #'robe-complete-annotation - :exit-function #'robe-complete-exit))))) + :exit-function #'robe-complete-exit + :company-doc-buffer #'robe-complete-doc-buffer + :company-location #'robe-complete-location + :company-dogsig #'robe-complete-docsig + :company-kind #'robe-complete-kind))))) (defvar robe-specs-cache nil) @@ -969,6 +973,54 @@ Only works with Rails, see e.g. `rinari-console'." (defun robe-complete-exit (&rest _) (setq robe-specs-cache nil)) +(defun robe-complete--choose-spec (thing) + (let ((specs (robe-cached-specs thing))) + (when specs + (if (cdr specs) + (let ((alist (cl-loop for spec in specs + for module = (robe-spec-module spec) + when module + collect (cons module spec)))) + (cdr (assoc (robe-completing-read "Module: " alist nil t) alist))) + (car specs))))) + +(defun robe-complete-doc-buffer (thing) + (let ((spec (robe-complete--choose-spec thing)) + (inhibit-redisplay t) + ;; XXX: Maybe revisit company-mode/company-mode#548. + (timer-list nil)) + (when spec + (save-window-excursion + (robe-show-doc spec) + (message nil) + (get-buffer "*robe-doc*"))))) + +(defun robe-complete-location (thing) + (let ((spec (robe-complete--choose-spec thing))) + (cons (robe-spec-file spec) + (robe-spec-line spec)))) + +(defun robe-complete-docsig (thing) + (if-let ((type (get-text-property 0 'robe-type thing))) + (if-let ((vtype (get-text-property 0 'robe-variable-type thing))) + (format "%s => %s" type (propertize vtype 'face 'font-lock-type-face)) + type) + (let ((spec (car (robe-cached-specs thing)))) + (when spec (robe-signature spec))))) + +(defun robe-complete-kind (thing) + (let (case-fold-search) + (cond + ((string-match "\\(?:\\`\\|::\\)\\(?:[A-Z_0-9]*\\|\\([A-Z][A-Z_a-z0-9]*\\)\\)\\'" thing) + (if (match-beginning 1) + 'module + 'constant)) + ((string-match-p "\\`@" thing) + 'variable) + ((get-text-property 0 'robe-type thing) + 'value) + (t 'method)))) + (defun robe-complete-thing (thing) (robe-start) (cond @@ -1268,6 +1320,30 @@ Only works with Rails, see e.g. `rinari-console'." 500 t) (match-string 1)))))) +;;;###autoload +(defun company-robe (command &optional arg &rest ignore) + "A `company-mode' completion back-end for `robe-mode'." + (interactive (list 'interactive)) + (cl-case command + (interactive (company-begin-backend 'company-robe)) + (prefix (and (boundp 'robe-mode) + robe-mode (robe-running-p) + (company-robe--prefix))) + (candidates (robe-complete-thing arg)) + (duplicates t) + (meta (robe-complete-docsig arg)) + (location (robe-complete-location arg)) + (kind (robe-complete-kind arg)) + (annotation (robe-complete-annotation arg)) + (doc-buffer (robe-complete-doc-buffer arg)))) + +(defun company-robe--prefix () + (let ((bounds (robe-complete-bounds))) + (when (and bounds + (equal (point) (cdr bounds)) + (robe-complete-symbol-p (car bounds))) + (buffer-substring (car bounds) (cdr bounds))))) + (defvar robe-mode-map (let ((map (make-sparse-keymap))) ;; FIXME: Add better Xref support.