-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
Add import will write to a temporary file and do replacements on the buffer, but add import qualified will write to the whole file and require reverting the buffer.
Lines 533 to 569 in 230101a
| (defun psc-ide-add-import-impl (identifier &optional filters) | |
| "Invoke the addImport command for IDENTIFIER with the given FILTERS." | |
| (let* ((tmp-file (make-temp-file "psc-ide-add-import")) | |
| (result (progn | |
| (write-region (point-min) (point-max) tmp-file) | |
| (psc-ide-unwrap-result | |
| (psc-ide-send-sync (psc-ide-command-add-import identifier filters tmp-file tmp-file)))))) | |
| (if (not (stringp result)) | |
| (let ((selection | |
| (completing-read "Which Module to import from: " | |
| (-map (lambda (x) | |
| (cdr (assoc 'module x))) result)))) | |
| (psc-ide-add-import-impl identifier (vector (psc-ide-filter-modules (vector selection))))) | |
| (progn (message "Added import for %s" identifier) | |
| (save-restriction | |
| (widen) | |
| ;; command successful, insert file with replacement to preserve | |
| ;; markers. | |
| (insert-file-contents tmp-file nil nil nil t)))) | |
| (delete-file tmp-file))) | |
| (defun psc-ide-add-import-qualified-impl (identifier qualifier) | |
| "Add a qualified import for the given IDENTIFIER and QUALIFIER." | |
| (let* ((completions | |
| (psc-ide-unwrap-result | |
| (psc-ide-send-sync | |
| (psc-ide-command-show-type (vector) identifier)))) | |
| (module | |
| (pcase (length completions) | |
| (`0 (error "Couldn't find a module for %s" identifier)) | |
| (`1 (cdr (assoc 'module (aref completions 0)))) | |
| (_ (completing-read "Which Module: " | |
| (seq-map (lambda (x) (let-alist x .module)) completions)))))) | |
| (unless (string= (psc-ide-qualifier-for-module module) qualifier) | |
| (save-buffer) | |
| (psc-ide-send-sync (psc-ide-command-add-qualified-import module qualifier)) | |
| (revert-buffer nil t)))) |
Metadata
Metadata
Assignees
Labels
No labels