-
Notifications
You must be signed in to change notification settings - Fork 64
Add interactive command for case splitting #112
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, you do rather rely on the regex here. I guess I don't have a better suggestion, then, since AFAICT there's no proper way to include some extra structured data in a I guess we could avoid the regex by just using the code action title as is, for something like:
but I guess that's a worse UX. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is too fragile, then we can remove it! Shame that the spec doesn't let us communicate more in the kind. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I just want to avoid the situation where someone changes the title, rightly reasoning that it's a user-facing string that can be changed freely, and then this function breaks. |
||
nil t)))))) | ||
|
||
;; --------------------------------------------------------------------- | ||
;; Starting the server and registration with lsp-mode | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a little fragile. I think the right way to do this is to use code action kinds: they're explicitly there to allow filtering by the client (i.e. us). We might need to teach the tactics plugin to add a kind, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can update the tactics plugin with kinds, good call!