Skip to content

Commit

Permalink
Remove redundant prefix from candidates.
Browse files Browse the repository at this point in the history
This is to fix the issue where if you complete 'java.uti' it will end up
inserting 'java.java.util'. This is because the completion prefix in
this example is 'uti', but the candidate returned by eclim will be the
full package name 'java.util'. Company will insert the completion from
the prefix, which leads to the incorrect behavior. This solves this
issue by looking before the prefix at what is already present in the
buffer, and removing and redundancy from candidates if present.
  • Loading branch information
bbelleville committed Jul 23, 2015
1 parent 4716244 commit b616f0d
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions company-emacs-eclim.el
Expand Up @@ -47,13 +47,40 @@
(remove-if (lambda (b) (find b '(company-nxml company-eclim)))
company-backends))))

(defun company-emacs-eclim--before-prefix-in-buffer (prefix)
"Search for the text before prefix that may be included as part of completions"
(ignore-errors
(save-excursion
(let ((end (progn
(backward-char (length prefix))
(point)))
(start (progn
(while (save-excursion
(backward-char)
(eq ?. (char-after)))
(backward-char)
(beginning-of-thing 'symbol))
(point))))
(buffer-substring-no-properties start end)))))

(defun company-emacs-eclim--candidates (prefix)
(mapcar
(lambda (str)
(if (string-match "(" str)
(propertize (substring str 0 (match-beginning 0)) 'eclim-meta str)
str))
(eclim--completion-candidates)))
(let ((before-prefix-in-buffer (company-emacs-eclim--before-prefix-in-buffer prefix)))
(cl-labels
((annotate (str)
(if (string-match "(" str)
(propertize
(substring str 0 (match-beginning 0)) 'eclim-meta str)
str))
(without-redundant-prefix (str)
(if (and before-prefix-in-buffer
(> (length before-prefix-in-buffer) 0)
(string-prefix-p before-prefix-in-buffer str))
(substring str (length before-prefix-in-buffer))
str)))
(mapcar
(lambda (candidate)
(annotate (without-redundant-prefix candidate)))
(eclim--completion-candidates)))))

(defun company-emacs-eclim--annotation (candidate)
(let ((str (get-text-property 0 'eclim-meta candidate)))
Expand Down

0 comments on commit b616f0d

Please sign in to comment.