(defun flymake-diagnostic-context-menu (menu click)
"Extend MENU with fix suggestions for diagnostic at CLICK."
- (when-let ((diag (mouse-posn-property (event-start click)
- 'flymake-diagnostic))
- (fix-fun (flymake--diag-fix-function diag))
- (fixes (funcall fix-fun (flymake--diag-data diag)))
+ (when-let ((diag (seq-find #'flymake--diag-fix-function
+ (flymake-diagnostics
+ (posn-point (event-start click)))))
+ (fixes (funcall (flymake--diag-fix-function diag)
+ (flymake--diag-data diag)))
(i 1))
(dolist (fix fixes)
(define-key menu (vector (intern (format "flymake-fix-%d" i)))
"Fix Flymake diagnostic at POS."
(interactive "d")
;; TODO - fix _all_ diagnostics at point.
- (if-let ((diag (car (flymake-diagnostics pos))))
- (if-let ((fix-fun (flymake--diag-fix-function diag))
- (fixes (funcall fix-fun (flymake--diag-data diag))))
+ (if-let ((diags (flymake-diagnostics pos)))
+ (if-let ((diag (seq-find #'flymake--diag-fix-function diags))
+ (fixes (funcall (flymake--diag-fix-function diag)
+ (flymake--diag-data diag))))
(refactor-apply-edits
(car (if (cdr fixes)
(alist-get
(defvar-local sh--shellcheck-process nil)
+(defun sh-shellcheck-fix (data)
+ "Format DATA, a cons cell (TITLE . FIX), as a Flymake fix suggestion."
+ `((,(car data)
+ ((,(current-buffer)
+ ,@(mapcar
+ (lambda (rep)
+ (let-alist rep
+ (without-restriction
+ (save-excursion
+ (goto-char (point-min))
+ (list (1- (+ (pos-bol .line) .column))
+ (1- (+ (pos-bol .endLine) .endColumn))
+ .replacement)))))
+ (alist-get 'replacements (cdr data))))))))
+
(defun sh-shellcheck-flymake (report-fn &rest _args)
"Flymake backend using the shellcheck program.
Takes a Flymake callback REPORT-FN as argument, as expected of a
("error" :error)
("warning" :warning)
(_ :note))
- (format "SC%s: %s" .code .message)))))
+ (format "SC%s: %s" .code .message)
+ (cons .message .fix) nil
+ (when (consp .fix) #'sh-shellcheck-fix)))))
(funcall report-fn))))
(kill-buffer (process-buffer proc)))))))
(unless dialect