Skip to content
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

Add remove_unused_binding assist #159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CPardi
Copy link

@CPardi CPardi commented Jan 8, 2025

Hi,

I've had a go at implementing an assist to remove bindings for the UnusedBinding liveness check described on #39. If you have time to take a look that would be great, thanks.

The changes include adding a remove_unused_binding function which does the following steps

  1. Retrieves the diagnostics at the cursor and if UnusedBinding is not present then return
  2. Assume the cursor is at a let binding and attempt to delete it
    • I started from the pack_bindings implementation and removed the inner bindings logic to get the TextRange to delete.
  3. If the previous fails, assume the cursor is at a pattern binding and attempt to delete it
    • the code checks to see if there is a comma after the pattern name
      • If so, then it is deleted along with the trivia after
      • If not, the preceding comma and trivia is deleted
  4. If both let and pattern binding cases fail then return without any edits. (I have assumed that there are only these two cases)

I have added some tests and updated the code_action.md document also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant