这是indexloc提供的服务,不要输入任何密码
Skip to content

Add remove_unused_binding assist #159

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

Closed
wants to merge 1 commit into from

Conversation

CPardi
Copy link
Contributor

@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.

@oxalica oxalica closed this in 58b7742 Jun 12, 2025
@oxalica
Copy link
Owner

oxalica commented Jun 12, 2025

Thanks! I manually merged it with some nit format change.

The trivia handling seems quite complex but the result change is quite good. Probably we need more convenient methods to handle it...

@CPardi
Copy link
Contributor Author

CPardi commented Jun 16, 2025

Great thank you for taking a look and merging.

The trivia handling seems quite complex but the result change is quite good. Probably we need more convenient methods to handle it...

The trivia collection code at lines 83-92 ended up the same as that in pack_binding.rs lines 87-96, so it would be nice to have somewhere the common code can be placed. I don't know where the most natural place this would be though.

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.

2 participants