-
-
Notifications
You must be signed in to change notification settings - Fork 299
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
autofix removes extra line sometimes on pointless discard #2076
Comments
This doesn't seem to reproduce with vscode or with adding this test to test "remove discard with trailing text" {
try testAutofix(
\\fn debug(comptime fmt: []const u8, args: anytype) void {
\\ _ = args; // autofix
\\ _ = fmt; // autofix
\\ @import("std").debug.print(fmt ++ "\n", args);
\\}
\\
,
\\fn debug(comptime fmt: []const u8, args: anytype) void {
\\ @import("std").debug.print(fmt ++ "\n", args);
\\}
\\
);
} That makes me think this might be a sublime text bug. |
I can confirm that this is a bug with Sublime Text LSP. We start with the following source file: const std = @import("std");
fn debug(comptime fmt: []const u8, args: anytype) void {
_ = args; // autofix
_ = fmt; // autofix
std.debug.print(fmt ++ "\n", args);
} Sublime Text applies the first code action: {
"range": {
"start": {
"line": 2,
"character": 56
},
"end": {
"line": 3,
"character": 24
}
},
"newText": ""
} This result in the following file: const std = @import("std");
fn debug(comptime fmt: []const u8, args: anytype) void {
_ = fmt; // autofix
std.debug.print(fmt ++ "\n", args);
} It then applies the second code action:
Note that the "character" value of "start" is being "clamped" to the end of line. This result in the corrupted source file: const std = @import("std");
fn debug(comptime fmt: []const u8, args: anytype) void {
_ = fmt; // autofix ++ "\n", args);
} Sublime Text LSP needs to apply the code actions simultaniously. This behaviour can be easily noticed when using Removing |
Thanks for the detailed feedback 👍. I think I you're saying that fixing the first code action results in a second one with invalid ranges? I can also see the actions getting undone individually w/ ctrl+z. I think you're right. I haven't noticed this issue until i pulled and rebuilt yesterday. |
Yes. the code actions are meant to be applied to the "initial" document. Applying one of them modifies the document and invalidates the other code action's "range". |
And thanks for the sublime lsp link 🙏. I just noticed that its a specific issue. |
Closing since this appears to be a sublime lsp bug. |
Zig Version
0.14.0-dev.2126+e27b4647d
ZLS Version
0.14.0-dev.190+2451194
Client / Code Editor / Extensions
sublime text stable build 4180
Steps to Reproduce and Observed Behavior
here is the sequence of actions
ok - save file becomes
ok - uncomment
oops - save becomes
here the final line has been removed incorrectly. the removed length seems to be equal to the length of the last line
~/.config/zls.json
i notice that adding a newline after the last autofixed line produces a good result
save
Expected Behavior
the pointless discards should be remove and result in
Relevant log output
No response
The text was updated successfully, but these errors were encountered: