autofix now handles comments in the event of a newline w/ comments (#1236)
* autofix now handles comments in the event of a newline w/ comments * oob check * continue statements so we don't waste time checking things we know * added a skip for if the characters are a comment * convert to switch for readability
This commit is contained in:
parent
c28a59ccf3
commit
83c9a7b493
@ -183,9 +183,23 @@ fn handleUnusedCapture(
|
||||
// look for next non-whitespace after last '|'. if its a '{' we can insert discards.
|
||||
// this means bare loop/switch captures (w/out curlies) aren't supported.
|
||||
var block_start = capture_loc.end + 1;
|
||||
while (block_start < builder.handle.text.len and
|
||||
std.ascii.isWhitespace(builder.handle.text[block_start])) : (block_start += 1)
|
||||
{}
|
||||
var is_comment = false;
|
||||
while (block_start < builder.handle.text.len) : (block_start += 1)
|
||||
{
|
||||
switch (builder.handle.text[block_start]) {
|
||||
'/' => if (block_start + 1 < builder.handle.text.len and builder.handle.text[block_start + 1] == '/') {
|
||||
is_comment = true;
|
||||
// we already know the next character is a `/` so lets skip that iteration
|
||||
block_start += 1;
|
||||
},
|
||||
// if we go to a new line, drop the is_comment boolean
|
||||
'\n' => if (is_comment) {
|
||||
is_comment = false;
|
||||
},
|
||||
//If the character is not a whitespace, and we're not in a comment then break out of the loop
|
||||
else => |c| if(!std.ascii.isWhitespace(c) and !is_comment) break,
|
||||
}
|
||||
}
|
||||
if (builder.handle.text[block_start] != '{') {
|
||||
return;
|
||||
}
|
||||
|
@ -81,6 +81,25 @@ test "code actions - discard captures" {
|
||||
);
|
||||
}
|
||||
|
||||
test "code actions - discard capture with comment" {
|
||||
try testAutofix(
|
||||
\\test {
|
||||
\\ if (1 == 1) |a|
|
||||
\\ //a
|
||||
\\ {}
|
||||
\\}
|
||||
,
|
||||
\\test {
|
||||
\\ if (1 == 1) |a|
|
||||
\\ //a
|
||||
\\ {
|
||||
\\ _ = a;
|
||||
\\ }
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "code actions - remove pointless discard" {
|
||||
try testAutofix(
|
||||
\\fn foo(a: u32) u32 {
|
||||
|
Loading…
Reference in New Issue
Block a user