Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Discard unused variable code action#4967

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
clr-cera wants to merge10 commits intogleam-lang:main
base:main
Choose a base branch
Loading
fromclr-cera:discard_unused_variable

Conversation

@clr-cera
Copy link

This PR creates the code action to discarding an unused variable.

References Issue#4950

As suggested the code action is currently set as preferred.

@clr-cera
Copy link
Author

Hi, I am having two problems with this pr!

First, is the code action always applied after formatting? When the variable is assigned through a pattern, the code action must also remove the ' as ' before the variable name, and I haven't figured out how to find this span.

Also, the tests for the code action are failing, although they produce the right result, how can I fix that?

Accepted the snapshots, and the LabelShorthand edit now adds a ' ' tocomply with formatting
@GearsDatapacks
Copy link
Member

GearsDatapacks commentedSep 12, 2025
edited
Loading

  1. No, the user isn't guaranteed to have formatted their code before running a code action. What we usually do when a certain new piece of location information is required is to add it to the AST. However in this case, I should think it would be possible to remove the code from the end of the inner pattern to the end of theas pattern, both of which you should already have the locations for.
  2. That's because we use snapshot testing! The way it works is that first you run the tests to generate the output, then you manually review it to determine whether it is correct or not (usecargo insta review). After that, the correct value is stored and the test will only fail if it differs from the accepted snapshot. Seedocs/compiler/README.md for more information
clr-cera reacted with heart emoji

@clr-cera
Copy link
Author

  1. No, the user isn't guaranteed to have formatted their code before running a code action. What we usually do when a certain new piece of location information is required is to add it to the AST. However in this case, I should think it would be possible to remove the code from the end of the inner pattern to the end of theas pattern, both of which you should already have the locations for.

    1. That's because we use snapshot testing! The way it works is that first you run the tests to generate the output, then you manually review it to determine whether it is correct or not (usecargo insta review). After that, the correct value is stored and the test will only fail if it differs from the accepted snapshot. Seedocs/compiler/README.md for more information

Thank you! Now I understood the snapshot testing, and wow, it works so well!
I will try to find the locations in the AST

@clr-cera
Copy link
Author

clr-cera commentedSep 12, 2025
edited
Loading

I couldn't find the assign pattern related to the unused variable warning, I tried to visit all assign patterns locations and check if the variable location start is inside, but this returned no patterns, and I did not think of any other way.

Is there a way to, given a location, find the location of a string before it?

I will try to fix it later, thanks for helping!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@clr-cera@GearsDatapacks

[8]ページ先頭

©2009-2025 Movatter.jp