-
Notifications
You must be signed in to change notification settings - Fork 194
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 _
to unused variable code action not working properly
#755
Comments
@lukaszsamson I looked into this, the code action cannot work as written; it uses the diagnostic start and end as the basis for the edit, and the diagnostic is just for pointing the user's attention to a specific line. The character can and is often 0. Furthermore, the action as written only accounts for the simplest variables of the form The current implementation is fatally flawed and cannot work, nor can it be made to work without a complete rewrite that actually looks at the syntax of the expression in question. I suggest removing the commits. |
Code actions was never high on my priority list so haven't tested this too much. I wouldn't immediately revert it as this was highly asked for. Can you take a look @lucacervello? To make this work more reliably we need to make the edits on AST. I will need to take a closer look on positions returned from elixir compiler. Some fixes may be neede upstream |
I would because it simply doesn't work in all but the simplest cases and breaks code. I've added a replacement code action that uses rewriting to handle the other cases here, you can see the different approach and the unit tests.
The compiler should only ever be a guide for where problems occur, Even if we had proper lines and columns, the approach above is still flawed and will remain flawed. Code modification cannot ever be text-based, there's just too much variability in elixir code. Personally, I don't think the compiler needs to change in this circumstance. |
It turns out I was working on the fix parallel to you. I've created a simple solution that you may consider (#778). It should work in most real-life cases and not break the code in the other ones. |
@lukaszsamson In my PR I pointed out that this code action wasn't working well, I didn't find a good solution to edit code in |
@lukaszsamson I believe that continuing down the current path will be a poor technical decision for the project in general, and represents a serious problem for any refactoring that I have already done actually landing in the project. I see the following technical problems with the current implementation of code actions:
In contrast, saying "all future code modification happens in the experimental server" means that
To sum up, what I'm asking is to remove code actions in their current form, to land the 3 PRs that have been sitting open for weeks (and don't affect the rest of the system) and direct people that would like to add functionality to I'd be curious to see what @sheldak thinks of the new approach too, he's been expending a lot of effort to write and test code actions. I'm always impressed when people jump through hoops to scratch an itch they have. |
@scohen You don't have to convince me that AST transformations are the right way to go. I simply wanted to see if the original author or some other contributor is willing to take up the mantle and implement it correctly. |
@lukaszsamson I think the long comment obscured the point i was trying to make, only part of which is that AST transforms are the way forward here. So let me clarify. I think that keeping string based modifications in the project at all is the mistake. Leaving them in will encourage more people to adopt that methodology, because people extend what's already there, as it's the path of least resistance. This will prevent the eventual AST based modifications from being tested or merged. You can see that we've had two additions to code actions since they were merged, and both follow the approach already taken. My take, and please correct me if I'm wrong, is that there's no way to implement this correctly using string-based source code modification in the current project without it being a massive performance problem. While @sheldak's bug fix indeed fixes some of the bugs present in the initial implementation, it doesn't account for multibyte characters on the line and will break in subtle ways if they're encountered. What I'm trying to prevent here is a pile-on of features that use dead-end techniques. |
@scohen I agree that working on AST should be the future of code actions. I created two PRs just before realizing there is all that work on refactoring code actions and rewriting strings in these particular cases seemed like a decent solution then. Maybe I will also add some background from me: I'm working in Qarma and we would like to have a few more code action features, so I'll be working part-time on elixir-ls for some time. Hopefully, we will be able to incorporate these features into the official project if @lukaszsamson finds them useful. I can surely work on top of @scohen's code actions framework. I just need to know where can I extend code actions safely (if anywhere). |
@sheldak I'm trying to do a couple of things here. The first is to outline a hopefully better approach to code modification. The second is to funnel some work to the experimental branches so more people try them out so we can improve the developer experience and get more eyes on the experimental server. Lastly, I'm trying to prevent work from happening on a technology that won't be used going forward. I think it's the last thing that I'm having a hard time getting across. I'm of the opinion that text-based code-modification is actively harmful to the project's long term health, and I think they should be removed from it right now. They represent an incorrect way to solve the problem, have serious bugs, and are causing real-world pain right now. I'm pretty surprised that they haven't been removed yet and a point-release added to address them. I'm pretty active on the elixir discord, and we have had pretty consistent complaints about elixir-ls since 0.12. I've been working with it and it burns me multiple times every day (And I have fixed code actions!). I don't like to be critical in public, but this is not a good developer experience. We need to address this now. |
Closing this as the broken implementation has been removed |
Environment
Current behavior
Where there is an unused in a function signature, and I try to apply the
Add '_' to unused variable
code action, the_
gets added in the wrong position depending on how the function is formatted.With oneliner function definitions, it adds the
_
to the function's name:With maps:
Apparently, it adds the
_
to the beginning of the line rather than to the beginning of the unused variable.Expected behavior
I should add the
_
to the beginning of the unused variable name.The text was updated successfully, but these errors were encountered: