Skip to content

Import qualified does not write temporarily to the buffer #167

@justinwoo

Description

@justinwoo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions