-
-
Notifications
You must be signed in to change notification settings - Fork 58
feat(code-action): add remove unused formal parameter quickfix #778
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: main
Are you sure you want to change the base?
Conversation
- Implement code action to remove unused lambda formals - Handle comma placement for first, middle, and last formals - Add tests for basic, first, middle, default, and ellipsis cases - Update build to include RemoveUnusedFormal sources
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.
|
@inclyc That said, I agree that attaching the fix directly to the diagnostic in VariableLookup.cpp would be the more natural fit for this case, since the Formals context is already available at diagnostic emission time — unlike AddToFormals, which needs ParentMap to find the enclosing lambda. What would you prefer?
|
|
I believe this PR (#778) should be refactored to be primarily based on diagnostic information in The reasons are: (1) The existing structure based on fix-it hints is very prevalent and common in (2) On the other hand, if a formal parameter is unused, automatically removing it feels natural and provides a unique solution. In contrast, "AddToFormals" appears to be "one of several possible solutions," which makes it more suitable to be implemented as a separate Code Action. Furthermore, considering "technical perfectionism," open-source communities generally don't share the same sense of "urgency" found in commercial software. If you're willing, I would also prefer to maintain a more robust project rather than leaving this as technical debt indefinitely. Implementing this specific task within Code Actions feels somewhat "awkward" and counter-intuitive. この PR (#778) は 理由は以下の通りです: (1) (2) 一方で、形式引数が**未使用(unused)**である場合、それを自動的に削除することは自然であり、かつ解決策も一意です。それに対して "AddToFormals" は「複数の解決策のうちの一つ」という側面が強いため、個別の Code Action として記述する方が適しています。 また、「技術的なこだわり(技術潔癖)」という面から見ても、オープンソースコミュニティは通常、商用ソフトウェアのような「急ぎの対応」を追求する場ではないと考えています。もし許されるのであれば、これを技術負債として放置するのではなく、より堅牢なプロジェクトとして維持していきたいです。この機能を Code Actions の中で実装し続けるのは、どこか「不自然(拧巴)」で無理があると感じています。 |
|
@inclyc |
Summary
Add code action to remove unused formal parameters from lambda expressions.
Example Transformation:
{x, y}: x{x}: x{x, y, z}: x + z{x, z}: x + z{x ? 1, y}: y{y}: y{x, y, ...}: y{y, ...}: yChanges
nixd/lib/Controller/CodeActions/RemoveUnusedFormal.hnixd/lib/Controller/CodeActions/RemoveUnusedFormal.cppnixd/lib/Controller/CodeAction.cppnixd/lib/meson.buildBehavior
Action offered when:
DK_UnusedDefLambdaNoArg_FormalorDK_UnusedDefLambdaWithArg_FormalexistsAction NOT offered when:
...)Handles comma placement:
{x, y}:→ removexand next formal's leading comma{x, y}:→ removey(comma is part of its range)Test Plan
basic.md: Remove last formalfirst-formal.md: Remove first formal (special comma handling)middle-formal.md: Remove middle formalwith-default.md: Remove formal with default valuewith-ellipsis.md: Remove formal when ellipsis presentall-used-negative.md: Negative - all formals used (no action offered)Related