Skip to content

Commit

Permalink
Fold completion backends (and their features) into the core package
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dgutov committed Mar 18, 2024
1 parent 1c46065 commit 8707607
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 122 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kbd>C-M-i</kbd>) 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 <kbd>M-x robe-start</kbd>.

Built-in completion (triggered with <kbd>C-M-i</kbd>) is also supported,
no extra setup required.

## Integration with rvm.el

[rvm.el](https://github.com/senny/rvm.el) may not have activated the
Expand Down
44 changes: 0 additions & 44 deletions ac-robe.el

This file was deleted.

69 changes: 0 additions & 69 deletions company-robe.el

This file was deleted.

78 changes: 77 additions & 1 deletion robe.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8707607

Please sign in to comment.