From f0530568e711ebf4c2b8a38fae3ec57ab5b3542d Mon Sep 17 00:00:00 2001 From: Reed Mullanix Date: Sat, 27 Feb 2021 13:56:27 -0800 Subject: [PATCH] Add interactive command for case splitting --- lsp-haskell.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lsp-haskell.el b/lsp-haskell.el index 97b43bf..bd4a67a 100644 --- a/lsp-haskell.el +++ b/lsp-haskell.el @@ -228,6 +228,25 @@ if projectile way fails" (user-error "Couldn't find cabal file, using: %s" dir) dir)))) + +;; --------------------------------------------------------------------- +;; Interactive commands + +(defun lsp-haskell-case-split () + "Case split on an identifier. +To use this, place make sure the point is over a type hole." + (interactive) + (let* ((case-split-regex "Case split on \\(.*\\)") + (actions (-filter (lambda (action) (s-matches-p case-split-regex (lsp:code-action-title action))) (lsp-code-actions-at-point)))) + (lsp-execute-code-action (cond ((seq-empty-p actions) (signal 'lsp-no-code-actions nil)) + ((and (eq (seq-length actions) 1) lsp-auto-execute-action) + (lsp-seq-first actions)) + (t (lsp--completing-read "Identifier: " + (seq-into actions 'list) + (lambda (action) + (cadr (s-match case-split-regex (lsp:code-action-title action)))) + nil t)))))) + ;; --------------------------------------------------------------------- ;; Starting the server and registration with lsp-mode