-
Notifications
You must be signed in to change notification settings - Fork 97
Codeaction for exporting unused top-level bindings #711
Conversation
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.
Nice work, thanks a lot!
One question: I would have expected the code action to add the export at the end whereas your implementation adds it add the beginning. Was that an intentional choice or just because it was easier to implement?
I did that because it was easier to implement but now that I think about it, it would be just as easy to append it at the end (in the same line as the closing bracket). I'll update the PR. @cocreature I've updated it :) |
I just realized there is an edge case when appending to the export list - |
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.
Thank you!
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}" | ||
, "module A" | ||
, " (" | ||
, " foo) where" |
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 wonder how clever we should be in terms of inserting line breaks. At some point we venture into autoformatter territory which a code action is definitely not the right place for but maybe there is some middleground. E.g., insert a line break if the opening and closing parentheses are on different lines.
Let’s merge it like this but keep this in mind for a possible future extension.
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.
When writing codeactions, I prefer to offload as much work as possible to the formatter.
If we were to insert a line break, we would also have to get the indentation right.
* Add PatSynBind to GHC.Compat * Tests for "export unused top level binding" codeaction * Add "export unused top-level binding" codeaction * exportUnusedTests refactored * Fix export unused codeaction * NFC: remove unused import * hlint * add exports to the end of list instead * handle the case where last export end with comma
* Add PatSynBind to GHC.Compat * Tests for "export unused top level binding" codeaction * Add "export unused top-level binding" codeaction * exportUnusedTests refactored * Fix export unused codeaction * NFC: remove unused import * hlint * add exports to the end of list instead * handle the case where last export end with comma
* Add PatSynBind to GHC.Compat * Tests for "export unused top level binding" codeaction * Add "export unused top-level binding" codeaction * exportUnusedTests refactored * Fix export unused codeaction * NFC: remove unused import * hlint * add exports to the end of list instead * handle the case where last export end with comma
This codeaction lets you export unused top-level functions, data types, newtypes, type synonyms, type classes, type families and pattern synonyms.
Foo(..)
).This is done because it would require us to find the corresponding type in the export list.
Fixes haskell/haskell-language-server#157