fix(emacs/lean-company): import auto complete bug

fix #189
This commit is contained in:
Soonho Kong 2014-09-14 22:58:49 -07:00
parent d424cdd336
commit 81ecbb4c94
3 changed files with 49 additions and 41 deletions

View file

@ -34,22 +34,18 @@
file-name)) file-name))
(t file-name))) (t file-name)))
(defun company-lean--import-candidates-main (&optional root-dir) (defun company-lean--import-candidates-main (root-dir)
(interactive) (when root-dir
(unless root-dir (let* ((lean-files (f-files root-dir
(setq root-dir (lambda (file) (equal (f-ext file) "lean"))
(f--traverse-upwards (f-exists? (f-expand ".project" it)) t))
(f-dirname (buffer-file-name))))) ;; Relative to project root-dir
(let* ((lean-files (f-files root-dir (lean-files-r (--map (f-relative it root-dir) lean-files))
(lambda (file) (equal (f-ext file) "lean")) (candidates
t)) (--map (s-replace-all `((,(f-path-separator) . "."))
;; Relative to project root-dir (company-lean--import-remove-lean it))
(lean-files-r (--map (f-relative it root-dir) lean-files)) lean-files-r)))
(candidates (--zip-with (propertize it 'file-name other) candidates lean-files))))
(--map (s-replace-all `((,(f-path-separator) . "."))
(company-lean--import-remove-lean it))
lean-files-r)))
(--zip-with (propertize it 'file-name other) candidates lean-files)))
(defun company-lean--import-prefix () (defun company-lean--import-prefix ()
"FINDG is triggered when it looks at '_'" "FINDG is triggered when it looks at '_'"
@ -63,6 +59,8 @@
(defun company-lean--import-candidates (prefix) (defun company-lean--import-candidates (prefix)
(let* ((cur-dir (f-dirname (buffer-file-name))) (let* ((cur-dir (f-dirname (buffer-file-name)))
(parent-dir (f-parent cur-dir)) (parent-dir (f-parent cur-dir))
(project-dir (f--traverse-upwards (f-exists? (f-expand ".project" it))
(f-dirname (buffer-file-name))))
(candidates (candidates
(cond (cond
;; prefix = ".." ;; prefix = ".."
@ -73,7 +71,10 @@
((s-starts-with? "." prefix) ((s-starts-with? "." prefix)
(--map (concat "." it) (--map (concat "." it)
(company-lean--import-candidates-main cur-dir))) (company-lean--import-candidates-main cur-dir)))
(t (company-lean--import-candidates-main))))) ;; normal prefix
(t (-flatten
(-map 'company-lean--import-candidates-main
(lean-path-list)))))))
(--filter (s-starts-with? prefix it) candidates))) (--filter (s-starts-with? prefix it) candidates)))
(defun company-lean--import-location (arg) (defun company-lean--import-location (arg)

View file

@ -5,41 +5,24 @@
;; ;;
(require 'dash) (require 'dash)
(require 'f)
(require 'lean-util)
(defun lean-tags-table-list () (defun lean-tags-table-list ()
(let* ((lean-path-env-list (-filter 'f-exists?
(parse-colon-path (getenv "LEAN_PATH"))) (--map (f-join it "TAGS") (lean-path-list))))
(lean--path-list
(parse-colon-path
(ignore-errors
(car (process-lines (lean-get-executable lean-executable-name)
"--path")))))
(lean-path-list
(-uniq (append lean-path-env-list lean--path-list)))
(tags-file-list
(-non-nil
(--map (let ((tags-file (concat (file-name-as-directory it)
"TAGS")))
(if (file-exists-p tags-file)
tags-file
nil))
lean-path-list))))
tags-file-list))
(defun lean-generate-tags () (defun lean-generate-tags ()
"Run linja TAGS and let emacs use the generated TAGS file." "Run linja TAGS and let emacs use the generated TAGS file."
(interactive) (interactive)
(let ((ltags-file-name (lean-get-executable "linja")) (let ((ltags-file-name (lean-get-executable "linja")))
tags-file)
(message "Generating TAGS...") (message "Generating TAGS...")
(apply 'call-process (apply 'call-process
(append `(,ltags-file-name nil "*lean-tags*" nil) (append `(,ltags-file-name nil "*lean-tags*" nil)
lean-flycheck-checker-options lean-flycheck-checker-options
'("TAGS"))) '("TAGS")))
(message "TAGS generated.") (message "TAGS generated.")
(setq tags-table-list (lean-tags-table-list)) (setq tags-table-list (lean-tags-table-list))))
(setq tags-file (lean-find-file-upward "TAGS"))
(when tags-file
(add-to-list 'tags-table-list tags-file))))
(defmacro lean-tags-make-advice-to-call-ltags (f) (defmacro lean-tags-make-advice-to-call-ltags (f)
(let* ((f-name (symbol-name f)) (let* ((f-name (symbol-name f))

View file

@ -5,6 +5,10 @@
;; ;;
(require 'cl-lib) (require 'cl-lib)
(require 'f)
(require 's)
(require 'dash)
(require 'dash-functional)
(defun lean-concat-paths (&rest seq) (defun lean-concat-paths (&rest seq)
"Concatenate paths" "Concatenate paths"
@ -43,4 +47,24 @@
(let ((lean-bin-dir-name "bin")) (let ((lean-bin-dir-name "bin"))
(lean-concat-paths (lean-get-rootdir) lean-bin-dir-name exe-name))) (lean-concat-paths (lean-get-rootdir) lean-bin-dir-name exe-name)))
(defun lean-path-list ()
(interactive)
(let* ((lean-path-env-list
(parse-colon-path (getenv "LEAN_PATH")))
(lean--path-list
(parse-colon-path
(ignore-errors
(car (process-lines (lean-get-executable lean-executable-name)
"--path")))))
(project-dir (f--traverse-upwards (f-exists? (f-expand ".project" it))
(f-dirname (buffer-file-name))))
(path-list (append lean-path-env-list lean--path-list)))
(when project-dir
(setq path-list
(--map-when (f-relative? it)
(f-canonical (f-join project-dir it))
path-list)))
(-uniq (-map (-compose 'f-slash 'f-canonical)
path-list))))
(provide 'lean-util) (provide 'lean-util)