Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import qualified does not write temporarily to the buffer #167

Open
justinwoo opened this issue Jan 26, 2019 · 0 comments
Open

Import qualified does not write temporarily to the buffer #167

justinwoo opened this issue Jan 26, 2019 · 0 comments

Comments

@justinwoo
Copy link
Contributor

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.

psc-ide-emacs/psc-ide.el

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))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant