-
-
Notifications
You must be signed in to change notification settings - Fork 779
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
"Import" code action sometimes fails and deletes a range of code #4092
Comments
Oh dear! Thank you for the report |
I'll look into this |
Ok digging into this a bit, this seems to be a bit of a wider issue than with this specific code action. I can't reproduce this very easily; sometimes I can get this to happen, sometimes it works as normal, and sometimes I get not code action at all. This seems to be a more general caching issue. Seemingly, errors in function signatures cause a bigger disruption in the LSP's ability to function more so than errors inside a function body. I would imagine this is due to some short-circuiting nature of the compiler when type-checking the top-level of a module. While trying to write a test to capture this behaviour, I noticed that this line was triggering an early return and not even checking for code actions, which is probably because the module did not compile properly. In a real project though, the compiler has some information on the module from when it was valid, causing it to suggest a code action which produces an invalid program after application. I'm not sure what we should do about this; we could try to make modules more fault tolerant and still compile them when function signatures have errors in them, or we could maybe somehow mark code actions as stale once there is an error and we can no longer provide useful actions (if LSP has an easy way to do that) |
@EthanOlpin do you have syntax errors in your code? Can you share your code that reproduces the issue please 🙏 |
I have encountered this issue in code that is free of syntax errors at the time of applying the action. I recognize this isn't ideal but I've found one set of steps that somewhat reliably produces the issue for me with a small amount of code. Still, timing/caching seems to be a factor here making this <100% reliable.
If I pay close attention during Step 5 I sometimes see that a code action is suggested while typing out the second method. You can see that in this recording of the full process: https://github.com/user-attachments/assets/1589f638-7eef-4781-be20-873c45d8fea1. Full code: import gleam/set
fn foo(s: set.Set(Int)) {
todo
}
// Applying "Import `gleam/dict`" deletes everything between `dict` and `todo`"
fn bar(d: dict.Dict(Int, Int)) {
todo
} |
Description
Occasionally an "Import" action is suggested for the type annotation on function arguments that, when applied, sometimes causes:
Reproduction Steps
I've experienced a bit of non-determinism with the issue that makes it difficult to give exact steps to reproduce. I am able to get the issue to occur somewhat frequently by repeatedly doing variations of the following:
Environment:
I am not sure where to look for logs that would be useful here, I only see
INFO compile=...
in theGleam Language Server
output in VSCode.Screenshots / Recording
Recording: https://github.com/user-attachments/assets/885af89e-9dd5-402f-830d-c399e51590ba
The text was updated successfully, but these errors were encountered: