Skip to content

Commit

Permalink
Fix auto-import
Browse files Browse the repository at this point in the history
  • Loading branch information
mopemope committed Feb 13, 2017
1 parent 5b0dd95 commit 52db9d5
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions meghanada.el
Original file line number Diff line number Diff line change
Expand Up @@ -537,19 +537,29 @@ function."
(goto-char (point-min))
(re-search-forward (concat "^import\\s-+" imp "\\s-*;") nil t))))

(defun meghanada--add-import-callback (out)
"TODO: FIX DOC OUT."
(let* ((result (read out))
(severity (car result)))
(pcase severity
(`success
(let ((fqcn (car (cdr result))))
(unless (or (string-prefix-p "java.lang." fqcn) (meghanada--import-exists-p fqcn))
(let ((imp (meghanada--import-name fqcn))
(start t))
(save-excursion
(meghanada--goto-imports-start)
(while (and start (re-search-forward "^import .+;" nil t))
(forward-line)
(setq start (/= (point-at-bol) (point-at-eol))))
(insert (format "import %s;\n" imp))))))))))

(defun meghanada--add-import (imp)
"TODO: FIX DOC IMP ."
(unless (or (string-prefix-p "java.lang." imp) (meghanada--import-exists-p imp))
(let ((imp (meghanada--import-name imp))
(start t))
(save-excursion
(meghanada--goto-imports-start)
(while (and start
(re-search-forward "^import .+;" nil t))
(forward-line)
(setq start (/= (point-at-bol) (point-at-eol))))
(insert (format "import %s;\n" imp)))
(meghanada-add-import-async imp #'identity))))
(let ((imp (meghanada--import-name imp)))
(meghanada-add-import-async imp #'meghanada--add-import-callback))))


(defun meghanada-optimize-import--callback (out)
"TODO: FIX DOC OUT ."
Expand Down

0 comments on commit 52db9d5

Please sign in to comment.