]> rtime.felk.cvut.cz Git - sojka/company-mode.git/commitdiff
company-eclim: Show overloads, insert call templates
authorDmitry Gutov <dgutov@yandex.ru>
Thu, 21 Mar 2013 21:09:58 +0000 (01:09 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Thu, 21 Mar 2013 21:09:58 +0000 (01:09 +0400)
NEWS.md
company-eclim.el

diff --git a/NEWS.md b/NEWS.md
index 0be44ad7e4536d1a5460e81e3bbb7e7128532b94..57019cdcb57b8141e34f6a1afd76cbb30199ad94 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
 
 ## Next
 
+* `company-eclim` shows method overloads and inserts call templates with placeholders.
 * `company-clang` ObjC arguments template insertion now requires explicit user action.
 * `company-clang-objc-templatify` does not insert spaces after colons anymore.
 * `company-clang` is now only initialized in supported buffers.
index e5bce3b4dcc3bd57dc146b0cf75d373c84350da1..1637f3cab37859e1ade9ca5bad259153d6b620f2 100644 (file)
@@ -116,25 +116,38 @@ eclim can only complete correctly when the buffer has been saved."
                                    "-p" (company-eclim--project-name)
                                    "-f" project-file))
     (setq company-eclim--doc
-          (cdr (assoc 'completions
-                      (company-eclim--call-process
-                       "java_complete" "-p" (company-eclim--project-name)
-                       "-f" project-file
-                       "-o" (number-to-string (1- (point)))
-                       "-e" "utf-8"
-                       "-l" "standard")))))
+          (make-hash-table :test 'equal))
+    (dolist (item (cdr (assoc 'completions
+                              (company-eclim--call-process
+                               "java_complete" "-p" (company-eclim--project-name)
+                               "-f" project-file
+                               "-o" (number-to-string (1- (point)))
+                               "-e" "utf-8"
+                               "-l" "standard"))))
+      (let* ((meta (cdr (assoc 'info item)))
+             (completion meta))
+        (when (string-match " [:-]" completion)
+          (setq completion (substring completion 0 (match-beginning 0))))
+        (puthash completion meta company-eclim--doc))))
   (let ((completion-ignore-case nil))
-    ;; TODO: Handle overloaded methods somehow. Show one candidate per overload?
-    ;; That would look nice, but kinda useless: a bunch of candidates for the
-    ;; same completion. Maybe do expansion like `company-clang-objc-templatify'.
-    (all-completions prefix (mapcar (lambda (item) (cdr (assoc 'completion item)))
-                                    company-eclim--doc))))
+    (all-completions prefix company-eclim--doc)))
 
 (defun company-eclim--meta (candidate)
-  (cdr (assoc 'info (find-if
-                     (lambda (item) (equal (cdr (assoc 'completion item))
-                                      arg))
-                     company-eclim--doc))))
+  (gethash candidate company-eclim--doc))
+
+(defun company-eclim--templatify (call)
+  (let* ((end (point))
+         (beg (- (point) (length call)))
+         (templ (company-template-declare-template beg end)))
+    (save-excursion
+      (goto-char beg)
+      (while (re-search-forward "\\([(,] ?\\)\\(?:[^ ]+ \\)\\([^ ,)]*\\)" end t)
+        (let ((name (match-string 2)))
+          (replace-match "\\1" t)
+          (decf end (- (length (match-string 0))
+                       (length (match-string 1))))
+          (company-template-add-field templ (point) (format "<%s>" name)))))
+    (company-template-move-to-first templ)))
 
 (defun company-eclim (command &optional arg &rest ignored)
   "A `company-mode' completion back-end for eclim.
@@ -153,9 +166,10 @@ Completions only work correctly when the buffer has been saved.
                  (or (company-grab-symbol) 'stop)))
     (candidates (company-eclim--candidates arg))
     (meta (company-eclim--meta arg))
-    (duplicates t)
     ;; because "" doesn't return everything
-    (no-cache (equal arg ""))))
+    (no-cache (equal arg ""))
+    (post-completion (when (string-match "([^)]" arg)
+                       (company-eclim--templatify arg)))))
 
 (provide 'company-eclim)
 ;;; company-eclim.el ends here