Skip to content

Commit b755b53

Browse files
committed
Fix CI
1 parent 3688ea5 commit b755b53

18 files changed

Lines changed: 191 additions & 179 deletions

File tree

src/analyse.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,16 +1025,8 @@ const BAR_WIDTH: usize = 28;
10251025
/// Render a PHPStan-style progress bar string:
10261026
/// ` 120/883 [▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░] 13%`
10271027
fn progress_bar(done: usize, total: usize) -> String {
1028-
let pct = if total == 0 {
1029-
100
1030-
} else {
1031-
(done * 100) / total
1032-
};
1033-
let filled = if total == 0 {
1034-
BAR_WIDTH
1035-
} else {
1036-
(done * BAR_WIDTH) / total
1037-
};
1028+
let pct = (done * 100).checked_div(total).unwrap_or(100);
1029+
let filled = (done * BAR_WIDTH).checked_div(total).unwrap_or(BAR_WIDTH);
10381030
let empty = BAR_WIDTH - filled;
10391031

10401032
format!(

src/code_actions/extract_variable.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,24 @@ fn find_last_member_access(expr: &str) -> Option<String> {
392392
b')' => depth_paren -= 1,
393393
b'[' => depth_bracket += 1,
394394
b']' => depth_bracket -= 1,
395-
b'-' if depth_paren == 0 && depth_bracket == 0 => {
396-
if i + 1 < bytes.len() && bytes[i + 1] == b'>' {
397-
last_arrow_end = Some(i + 2);
398-
i += 2;
399-
continue;
400-
}
395+
b'-' if depth_paren == 0
396+
&& depth_bracket == 0
397+
&& i + 1 < bytes.len()
398+
&& bytes[i + 1] == b'>' =>
399+
{
400+
last_arrow_end = Some(i + 2);
401+
i += 2;
402+
continue;
401403
}
402-
b'?' if depth_paren == 0 && depth_bracket == 0 => {
403-
if i + 2 < bytes.len() && bytes[i + 1] == b'-' && bytes[i + 2] == b'>' {
404-
last_arrow_end = Some(i + 3);
405-
i += 3;
406-
continue;
407-
}
404+
b'?' if depth_paren == 0
405+
&& depth_bracket == 0
406+
&& i + 2 < bytes.len()
407+
&& bytes[i + 1] == b'-'
408+
&& bytes[i + 2] == b'>' =>
409+
{
410+
last_arrow_end = Some(i + 3);
411+
i += 3;
412+
continue;
408413
}
409414
_ => {}
410415
}
@@ -453,10 +458,12 @@ fn find_top_level_double_colon(expr: &str) -> Option<usize> {
453458
b')' => depth_paren -= 1,
454459
b'[' => depth_bracket += 1,
455460
b']' => depth_bracket -= 1,
456-
b':' if depth_paren == 0 && depth_bracket == 0 => {
457-
if i + 1 < bytes.len() && bytes[i + 1] == b':' {
458-
return Some(i);
459-
}
461+
b':' if depth_paren == 0
462+
&& depth_bracket == 0
463+
&& i + 1 < bytes.len()
464+
&& bytes[i + 1] == b':' =>
465+
{
466+
return Some(i);
460467
}
461468
_ => {}
462469
}

src/code_actions/phpstan/new_static.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -454,27 +454,27 @@ fn find_constructor(content: &str, class_kw_offset: usize) -> Option<Constructor
454454
return Some(build_constructor_info(content, construct_abs));
455455
}
456456
}
457-
b'/' if depth == 0 => {
457+
b'/' if depth == 0
458458
// Skip string literals and comments to avoid false matches.
459-
if i + 1 < body_bytes.len() {
460-
if body_bytes[i + 1] == b'/' {
461-
// Single-line comment: skip to end of line.
462-
while i < body_bytes.len() && body_bytes[i] != b'\n' {
463-
i += 1;
464-
}
465-
continue;
466-
} else if body_bytes[i + 1] == b'*' {
467-
// Multi-line comment: skip to `*/`.
468-
i += 2;
469-
while i + 1 < body_bytes.len() {
470-
if body_bytes[i] == b'*' && body_bytes[i + 1] == b'/' {
471-
i += 2;
472-
break;
473-
}
474-
i += 1;
459+
&& i + 1 < body_bytes.len() =>
460+
{
461+
if body_bytes[i + 1] == b'/' {
462+
// Single-line comment: skip to end of line.
463+
while i < body_bytes.len() && body_bytes[i] != b'\n' {
464+
i += 1;
465+
}
466+
continue;
467+
} else if body_bytes[i + 1] == b'*' {
468+
// Multi-line comment: skip to `*/`.
469+
i += 2;
470+
while i + 1 < body_bytes.len() {
471+
if body_bytes[i] == b'*' && body_bytes[i + 1] == b'/' {
472+
i += 2;
473+
break;
475474
}
476-
continue;
475+
i += 1;
477476
}
477+
continue;
478478
}
479479
}
480480
b'\'' | b'"' if depth == 0 => {

src/code_actions/promote_constructor_param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ mod tests {
473473
edits.push((offset, offset, default_text));
474474
}
475475
// Sort by start offset descending so applying them doesn't shift positions.
476-
edits.sort_by(|a, b| b.0.cmp(&a.0));
476+
edits.sort_by_key(|x| std::cmp::Reverse(x.0));
477477

478478
let mut result = php.to_string();
479479
for (start, end, text) in edits {

src/code_actions/remove_unused_import.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! published set so the squiggly lines disappear before the text edit
2020
//! is applied.
2121
22+
use std::cmp::Reverse;
2223
use std::collections::{HashMap, HashSet};
2324

2425
use tower_lsp::lsp_types::*;
@@ -152,7 +153,7 @@ impl Backend {
152153

153154
// Sort edits in reverse order so that byte offsets remain
154155
// valid as we apply deletions from bottom to top.
155-
edits.sort_by(|a, b| b.range.start.cmp(&a.range.start));
156+
edits.sort_by_key(|e| Reverse(e.range.start));
156157

157158
let mut changes = HashMap::new();
158159
changes.insert(doc_uri, edits);

src/code_actions/update_docblock.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,14 @@ fn find_standalone_function_by_docblock<'a>(
307307
) -> Option<FunctionWithDocblock> {
308308
for stmt in statements.iter() {
309309
match stmt {
310-
Statement::Function(func) => {
311-
if cursor_on_docblock(cursor, func, trivia, content) {
312-
return build_info_for_function_like(
313-
func.span().start.offset,
314-
&func.parameter_list,
315-
func.return_type_hint.as_ref(),
316-
trivia,
317-
content,
318-
);
319-
}
310+
Statement::Function(func) if cursor_on_docblock(cursor, func, trivia, content) => {
311+
return build_info_for_function_like(
312+
func.span().start.offset,
313+
&func.parameter_list,
314+
func.return_type_hint.as_ref(),
315+
trivia,
316+
content,
317+
);
320318
}
321319
Statement::Namespace(ns) => {
322320
for s in ns.statements().iter() {
@@ -1155,17 +1153,14 @@ fn find_param_insert_position(lines: &[DocLine]) -> usize {
11551153
DocLine::Text(_) | DocLine::Empty => {
11561154
last_text_or_empty = Some(i);
11571155
}
1158-
DocLine::Return(_) => {
1159-
if first_return_or_throws.is_none() {
1160-
first_return_or_throws = Some(i);
1161-
}
1156+
DocLine::Return(_) if first_return_or_throws.is_none() => {
1157+
first_return_or_throws = Some(i);
11621158
}
1163-
DocLine::OtherTag(text) => {
1159+
DocLine::OtherTag(text)
11641160
if (text.starts_with("@throws") || text.starts_with("@return"))
1165-
&& first_return_or_throws.is_none()
1166-
{
1167-
first_return_or_throws = Some(i);
1168-
}
1161+
&& first_return_or_throws.is_none() =>
1162+
{
1163+
first_return_or_throws = Some(i);
11691164
}
11701165
_ => {}
11711166
}
@@ -1202,10 +1197,8 @@ fn find_throws_insert_position(lines: &[DocLine]) -> usize {
12021197
DocLine::OtherTag(text) if text.starts_with("@throws") => {
12031198
last_throws = Some(i);
12041199
}
1205-
DocLine::Return(_) => {
1206-
if first_return.is_none() {
1207-
first_return = Some(i);
1208-
}
1200+
DocLine::Return(_) if first_return.is_none() => {
1201+
first_return = Some(i);
12091202
}
12101203
_ => {}
12111204
}

src/completion/context/namespace_completion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn infer_namespaces_from_path(
9494
}
9595

9696
// Sort by specificity descending (longest base_path first).
97-
results.sort_by(|a, b| b.specificity.cmp(&a.specificity));
97+
results.sort_by_key(|b| std::cmp::Reverse(b.specificity));
9898
results
9999
}
100100

src/completion/types/conditional.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ pub fn split_text_args(text: &str) -> Vec<&str> {
365365
continue;
366366
}
367367
match ch {
368-
'\\' => {
368+
'\\'
369369
// Only treat as escape if inside a quote
370-
if in_single_quote || in_double_quote {
371-
prev_was_backslash = true;
372-
}
370+
if in_single_quote || in_double_quote =>
371+
{
372+
prev_was_backslash = true;
373373
}
374374
'\'' if !in_double_quote => {
375375
in_single_quote = !in_single_quote;

src/completion/variable/completion.rs

Lines changed: 71 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -579,20 +579,25 @@ fn expr_contains_enclosing_closure<'b>(
579579
}
580580
// Also check the object/class expression for method calls.
581581
match call {
582-
Call::Method(mc) => {
583-
if expr_contains_enclosing_closure(content, mc.object, cursor_offset, vars) {
584-
return true;
585-
}
582+
Call::Method(mc)
583+
if expr_contains_enclosing_closure(content, mc.object, cursor_offset, vars) =>
584+
{
585+
return true;
586586
}
587-
Call::NullSafeMethod(nmc) => {
588-
if expr_contains_enclosing_closure(content, nmc.object, cursor_offset, vars) {
589-
return true;
590-
}
587+
Call::NullSafeMethod(nmc)
588+
if expr_contains_enclosing_closure(
589+
content,
590+
nmc.object,
591+
cursor_offset,
592+
vars,
593+
) =>
594+
{
595+
return true;
591596
}
592-
Call::StaticMethod(sc) => {
593-
if expr_contains_enclosing_closure(content, sc.class, cursor_offset, vars) {
594-
return true;
595-
}
597+
Call::StaticMethod(sc)
598+
if expr_contains_enclosing_closure(content, sc.class, cursor_offset, vars) =>
599+
{
600+
return true;
596601
}
597602
_ => {}
598603
}
@@ -605,20 +610,35 @@ fn expr_contains_enclosing_closure<'b>(
605610
Expression::Array(arr) => {
606611
for elem in arr.elements.iter() {
607612
match elem {
608-
ArrayElement::KeyValue(kv) => {
609-
if expr_contains_enclosing_closure(content, kv.value, cursor_offset, vars) {
610-
return true;
611-
}
613+
ArrayElement::KeyValue(kv)
614+
if expr_contains_enclosing_closure(
615+
content,
616+
kv.value,
617+
cursor_offset,
618+
vars,
619+
) =>
620+
{
621+
return true;
612622
}
613-
ArrayElement::Value(v) => {
614-
if expr_contains_enclosing_closure(content, v.value, cursor_offset, vars) {
615-
return true;
616-
}
623+
ArrayElement::Value(v)
624+
if expr_contains_enclosing_closure(
625+
content,
626+
v.value,
627+
cursor_offset,
628+
vars,
629+
) =>
630+
{
631+
return true;
617632
}
618-
ArrayElement::Variadic(v) => {
619-
if expr_contains_enclosing_closure(content, v.value, cursor_offset, vars) {
620-
return true;
621-
}
633+
ArrayElement::Variadic(v)
634+
if expr_contains_enclosing_closure(
635+
content,
636+
v.value,
637+
cursor_offset,
638+
vars,
639+
) =>
640+
{
641+
return true;
622642
}
623643
_ => {}
624644
}
@@ -628,20 +648,35 @@ fn expr_contains_enclosing_closure<'b>(
628648
Expression::LegacyArray(arr) => {
629649
for elem in arr.elements.iter() {
630650
match elem {
631-
ArrayElement::KeyValue(kv) => {
632-
if expr_contains_enclosing_closure(content, kv.value, cursor_offset, vars) {
633-
return true;
634-
}
651+
ArrayElement::KeyValue(kv)
652+
if expr_contains_enclosing_closure(
653+
content,
654+
kv.value,
655+
cursor_offset,
656+
vars,
657+
) =>
658+
{
659+
return true;
635660
}
636-
ArrayElement::Value(v) => {
637-
if expr_contains_enclosing_closure(content, v.value, cursor_offset, vars) {
638-
return true;
639-
}
661+
ArrayElement::Value(v)
662+
if expr_contains_enclosing_closure(
663+
content,
664+
v.value,
665+
cursor_offset,
666+
vars,
667+
) =>
668+
{
669+
return true;
640670
}
641-
ArrayElement::Variadic(v) => {
642-
if expr_contains_enclosing_closure(content, v.value, cursor_offset, vars) {
643-
return true;
644-
}
671+
ArrayElement::Variadic(v)
672+
if expr_contains_enclosing_closure(
673+
content,
674+
v.value,
675+
cursor_offset,
676+
vars,
677+
) =>
678+
{
679+
return true;
645680
}
646681
_ => {}
647682
}

src/composer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn extract_psr4_mappings_from_package(package: &ComposerPackage) -> Vec<Psr4
106106
}
107107

108108
// Sort by prefix length descending so longest-prefix-first matching works
109-
mappings.sort_by(|a, b| b.prefix.len().cmp(&a.prefix.len()));
109+
mappings.sort_by_key(|b| std::cmp::Reverse(b.prefix.len()));
110110

111111
mappings
112112
}

0 commit comments

Comments
 (0)