Skip to content

Commit afcb9a0

Browse files
committed
Implement conditional returns
1 parent f16b84e commit afcb9a0

9 files changed

Lines changed: 1486 additions & 37 deletions

File tree

src/completion/resolver.rs

Lines changed: 350 additions & 23 deletions
Large diffs are not rendered by default.

src/completion/target.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ impl Backend {
130130
/// `paren_end` is the position one past the closing `)`.
131131
///
132132
/// Returns subjects such as:
133-
/// - `"app()"` for a standalone function call
133+
/// - `"app()"` for a standalone function call without arguments
134+
/// - `"app(A::class)"` for a function call with arguments (preserved)
134135
/// - `"$this->getService()"` for an instance method call
135136
/// - `"ClassName::make()"` for a static method call
136137
/// - `"ClassName"` for `new ClassName()` instantiation
@@ -140,6 +141,11 @@ impl Backend {
140141
return None;
141142
}
142143

144+
// Capture the argument text between the parentheses for later use
145+
// in conditional return-type resolution (e.g. `app(A::class)`).
146+
let args_text: String = chars[open + 1..paren_end - 1].iter().collect();
147+
let args_text = args_text.trim();
148+
143149
// Read the function / method name before `(`
144150
let mut i = open;
145151
while i > 0
@@ -187,8 +193,13 @@ impl Backend {
187193
}
188194
}
189195

190-
// Standalone function call: `app()`
191-
Some(format!("{}()", func_name))
196+
// Standalone function call: preserve arguments for conditional
197+
// return-type resolution (e.g. `app(A::class)` instead of `app()`).
198+
if args_text.is_empty() {
199+
Some(format!("{}()", func_name))
200+
} else {
201+
Some(format!("{}({})", func_name, args_text))
202+
}
192203
}
193204

194205
/// Raw helper: extract identifier/keyword before `::` without going

src/definition/resolve.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ impl Backend {
532532
/// `paren_end` is the position one past the closing `)`.
533533
///
534534
/// Returns subjects such as:
535-
/// - `"app()"` for a standalone function call
535+
/// - `"app()"` for a standalone function call without arguments
536+
/// - `"app(A::class)"` for a function call with arguments (preserved)
536537
/// - `"$this->getService()"` for an instance method call
537538
/// - `"ClassName::make()"` for a static method call
538539
/// - `"ClassName"` for `new ClassName()` instantiation
@@ -542,6 +543,11 @@ impl Backend {
542543
return None;
543544
}
544545

546+
// Capture the argument text between the parentheses for later use
547+
// in conditional return-type resolution (e.g. `app(A::class)`).
548+
let args_text: String = chars[open + 1..paren_end - 1].iter().collect();
549+
let args_text = args_text.trim();
550+
545551
// Read the function / method name before `(`
546552
let mut i = open;
547553
while i > 0
@@ -586,8 +592,13 @@ impl Backend {
586592
}
587593
}
588594

589-
// Standalone function call: `app()`
590-
Some(format!("{}()", func_name))
595+
// Standalone function call: preserve arguments for conditional
596+
// return-type resolution (e.g. `app(A::class)` instead of `app()`).
597+
if args_text.is_empty() {
598+
Some(format!("{}()", func_name))
599+
} else {
600+
Some(format!("{}({})", func_name, args_text))
601+
}
591602
}
592603

593604
/// Extract a `$variable` ending at position `end` (exclusive).

0 commit comments

Comments
 (0)