-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from kevinkehl/unresolved-fix
Add handling for multiple unresolved imports
- Loading branch information
Showing
1 changed file
with
23 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
;; Author: Kevin Kehl <[email protected]> | ||
;; URL: http://github.com/Galooshi/emacs-import-js/ | ||
;; Package-Requires: ((grizzl "0.1.0") (emacs "24")) | ||
;; Version: 0.7.0 | ||
;; Version: 1.0.0 | ||
;; Keywords: javascript | ||
|
||
;; This file is not part of GNU Emacs. | ||
|
@@ -77,51 +77,51 @@ | |
(write-region file-content nil buffer-file-name)) | ||
(revert-buffer t t t)) | ||
|
||
(defun import-js-add (word file) | ||
(defun import-js-add (add-alist) | ||
"Resolves an import with multiple matches" | ||
(let ((json-data (json-encode-alist (list (cons word file))))) | ||
(let ((json-data (json-encode-alist add-alist))) | ||
(let ((import-data (json-read-from-string | ||
(import-js-send-input "add" json-data)))) | ||
(import-js-handle-imports import-data word)))) | ||
(import-js-handle-imports import-data)))) | ||
|
||
(defun import-js-handle-unresolved (unresolved word) | ||
(let ((paths (mapcar | ||
(lambda (car) | ||
(cdr (assoc 'importPath car))) | ||
(cdr (assoc-string word unresolved))))) | ||
(let ((file (minibuffer-with-setup-hook | ||
(lambda () (make-sparse-keymap)) | ||
(grizzl-completing-read (format "Unresolved import (%s)" word) | ||
(grizzl-make-index | ||
paths | ||
'files | ||
import-js-current-project-root | ||
nil))))) | ||
(import-js-add word file)))) | ||
|
||
(defun import-js-handle-imports (import-data word) | ||
(minibuffer-with-setup-hook | ||
(lambda () (make-sparse-keymap)) | ||
(grizzl-completing-read (format "Unresolved import (%s)" word) | ||
(grizzl-make-index | ||
paths | ||
'files | ||
import-js-current-project-root | ||
nil))))) | ||
|
||
(defun import-js-handle-imports (import-data) | ||
"Check to see if import is unresolved. If resolved, write file. Else, prompt the user to select" | ||
(let ((unresolved (cdr (assoc 'unresolvedImports import-data)))) | ||
(if unresolved | ||
(import-js-handle-unresolved unresolved word) | ||
(import-js-add (mapcar | ||
(lambda (word) | ||
(let ((key (car word))) | ||
(cons key (import-js-handle-unresolved unresolved key)))) | ||
unresolved)) | ||
(import-js-write-content import-data)))) | ||
|
||
;;;###autoload | ||
(defun import-js-import () | ||
(interactive) | ||
(save-some-buffers) | ||
(let ((word (import-js-word-at-point)) | ||
(import-data (json-read-from-string | ||
(import-js-send-input "word" (import-js-word-at-point))))) | ||
(import-js-handle-imports import-data word))) | ||
(import-js-handle-imports (json-read-from-string | ||
(import-js-send-input "word" (import-js-word-at-point))))) | ||
|
||
;;;###autoload | ||
(defun import-js-fix () | ||
(interactive) | ||
(save-some-buffers) | ||
(let ((import-data (json-read-from-string | ||
(import-js-send-input "fix")))) | ||
(import-js-write-content import-data))) | ||
(import-js-handle-imports (json-read-from-string | ||
(import-js-send-input "fix")))) | ||
|
||
;;;###autoload | ||
(defun import-js-goto () | ||
|