Now I can see the issue. Looking at child_containing_offset:
match expression {
Expression::Function { body, .. } | Expression::Lambda { body, .. } => c(body),
...
}
When traversing a Function expression, it only looks in the body, not in the params! So when find_expression_at is called with the binding's span (which is at the parameter location), it can't find the parameter expression because the traversal only goes into the function body.
This means find_expression_at(&file.items, binding.span.byte_offset) returns None when the binding is a function parameter, because the traversal never visits the parameters.
So in resolve_variable_type:
let expression = find_expression_at(&file.items, binding.span.byte_offset)?;
This returns None for function parameters! The ? propagates the None, so resolve_variable_type returns None, and no completions are returned.
Wait, but actually let me check - offset_in_span is called first in find_in_expression:
fn find_in_expression(expression: &Expression, offset: u32) -> Option<&Expression> {
if !offset_in_span(offset, &expression.get_span()) {
return None;
}
...
}
The function's span includes the entire function (from fn to }). So the parameter IS within the function's span. Then it enters the loop and looks for children. But child_containing_offset only checks the body:
Expression::Function { body, .. } | Expression::Lambda { body, .. } => c(body),
So it only checks if the offset is in the body. Since the parameter is NOT in the body (it's in the parameter list), c(body) returns None, and the function returns the Function expression itself.
So actually, find_expression_at DOES return the Expression::Function when the offset is at the parameter. The issue is that in resolve_variable_type, the match arm for Function does work:
Expression::Function { params, .. } | Expression::Lambda { params, .. } => {
let param = params.iter().find(|p| match &p.pattern {
syntax::ast::Pattern::Identifier { identifier, .. } => identifier == var_name,
syntax::ast::Pattern::AsBinding { name, .. } => name == var_name,
_ => false,
})?;
Some(¶m.ty)
}
This should find the parameter and return its type. So the issue might be elsewhere...
Wait, but the issue is that detect_dot_context is being called first. Let me trace through what happens:
detect_dot_context(file, offset, &snapshot) is called
- It tries to find a
DotAccess at offset - 1 (the position of the dot)
- Since the source is
ex.\n, the dot is at some position
find_expression_at at the dot position - does this return a DotAccess or just an Identifier?
If the parser doesn't create a DotAccess for ex. (empty member), then find_expression_at at the dot position would return the Identifier expression for ex (since the dot is within the span of ex).
Actually wait, the span of an Identifier expression would just be the identifier itself (ex), not including the dot. So the dot position would NOT be within the span of the Identifier ex.
Hmm, so find_expression_at at the dot position might return the Block or the Function, because those spans include the dot.
Let me think again. The source is:
fn example_call(ex: Example) -> string {
ex.
}
The parser might parse ex. as just ex (an Identifier) and leave the dot as a syntax error. Or it might parse ex. as a DotAccess with an empty member.
Actually, looking at the issue description more carefully - it says "LSP isn't providing completions for interfaces". So the completions feature isn't working at all for interfaces. This suggests that the issue is in how interface methods are discovered, not in how the type is resolved.
Let me think about this differently. For structs with impl blocks:
- The struct type is registered
- Methods are registered as
{module}.{struct_name}.{method_name} with DefinitionBody::Value
is_instance_method checks if the first param type matches the type_id
For interfaces:
- The interface type is registered
- Methods are registered as
{module}.{interface_name}.{method_name} with DefinitionBody::Value
is_instance_method checks if the first param type matches the type_id
Both should work the same way. So why doesn't it work for interfaces?
The key difference might be in how is_instance_method checks the first parameter. For interface methods, the first parameter is self, and its type should be the interface type. But maybe the type isn't matching?
Let me check what type interface method parameters have. Looking at the interface registration code in methods.rs:
let method_qualified_name = format!("{}.{}.{}", module_id, interface_name, method_name);
module.definitions.insert(
method_qualified_name.into(),
Definition {
visibility: visibility.clone(),
ty: method_ty, // <-- This is the method type
...
body: DefinitionBody::Value { ... },
},
);
The method_ty is the type of the method. For an interface method like fn example(self, name: string) -> string, this would be a function type with self as the first parameter.
But wait - what's the actual type of self in the method_ty? Is it the qualified interface type or just a parameter type?
Let me check how interface methods are type-checked...
Actually, I think I found a potential issue. Let me look at the interface method registration more carefully:
let (method_name, method_ty, go_hints, allowed_lints) = ...
The method_ty is built from extract_function_signature and potentially modified. Let me see how the self parameter type is set for interface methods.
Actually, I think the issue might be simpler. Let me check if maybe detect_dot_context is failing because when ex. is parsed, it's not recognized as a DotAccess.
Let me look at what happens step by step in the completion handler:
detect_dot_context(file, offset, &snapshot) - tries to find DotAccess at offset-1
- If that fails (returns None), falls through to:
get_module_prefix(&file.source, offset as usize) - extracts "ex"
- Checks if "ex" is a module/import alias - it's not
resolve_variable_type("ex", file, offset, &snapshot, false) - tries to find the type of "ex"
Now in resolve_variable_type:
- Find binding named "ex" in
snapshot.facts().bindings
- Find expression at binding's span
- Extract type from expression
The question is: is there a binding for the function parameter "ex"? And if so, what's its span?
I think the issue might be that function parameter bindings have a span that's outside the function body. When find_expression_at is called with that span, it might return None because the traversal doesn't go into parameters.
Wait, I already checked this. find_in_expression checks if the offset is within the expression's span first:
if !offset_in_span(offset, &expression.get_span()) {
return None;
}
The Function expression's span includes the entire function, including parameters. So the offset IS within the function's span. Then it enters the loop:
loop {
match child_containing_offset(current, offset) {
Some(child) => current = child,
None => return Some(current),
}
}
child_containing_offset for Function only checks the body:
Expression::Function { body, .. } | Expression::Lambda { body, .. } => c(body),
If the offset is NOT in the body (it's in the parameter list), c(body) returns None. So child_containing_offset returns None, and the loop returns the Function expression itself.
So find_expression_at returns the Function expression when the offset is at the parameter! And then in resolve_variable_type, the match arm:
Expression::Function { params, .. } => {
let param = params.iter().find(|p| ...)?;
Some(¶m.ty)
}
This should find the parameter and return its type!
So resolve_variable_type should work for function parameters. Unless the type of the parameter isn't properly resolved...
OK let me think about what might actually be different. Let me look at the is_instance_method function again:
fn is_instance_method(ty: &syntax::types::Type, type_id: &str) -> bool {
let func_ty = match ty {
syntax::types::Type::Forall { body, .. } => body,
other => other,
};
match func_ty {
syntax::types::Type::Function { params, .. } if !params.is_empty() => {
type_name(¶ms[0]).is_some_and(|name| name == type_id)
}
_ => false,
}
}
This checks if the first parameter's type name equals the type_id. For interface methods, the first parameter is self with the interface type.
But what if the interface method type doesn't have self as the first parameter? What if interface methods are stored differently?
Let me check the interface method registration code again...
In register_interface:
let method_sig = function.to_function_signature();
let mut fn_ty = self.extract_function_signature(&*store, &method_sig, span);
...
let is_instance_method = method_sig.params.first().is_some_and(|p| {
matches!(p.pattern, Pattern::Identifier { ref identifier, .. } if identifier == "self")
});
let has_unannotated_self = method_sig
.params
.first()
.is_some_and(|p| p.annotation.is_none());
if is_instance_method && has_unannotated_self {
fn_ty = fn_ty.with_replaced_first_param(&interface_ty);
}
So if the interface method has self as the first parameter with no annotation, fn_ty has its first parameter replaced with interface_ty.
And interface_ty is:
let interface_ty = store
.get_type(&qualified_name)
.expect("interface type scheme must exist")
.clone();
So the first parameter of interface methods should have the qualified interface type!
And then:
let method_defs: Vec<_> = methods.into_iter().map(|(method_sig, method_ty)| {
...
(method_sig.name.clone(), method_ty.clone(), ...)
}).collect();
for (method_name, method_ty, ...) in method_defs {
let method_qualified_name = format!("{}.{}.{}", module_id, interface_name, method_name);
module.definitions.insert(method_qualified_name.into(), Definition {
ty: method_ty,
...
});
}
So interface methods are registered with the correct type that has self as the interface type.
So why doesn't is_instance_method match?
Wait, let me check: what is interface_ty? It's obtained from store.get_type(&qualified_name). This might be a Type::Scheme or similar, not a Type::Nominal. Let me check what get_type returns...
Actually, looking more carefully at the code:
let interface_ty = store
.get_type(&qualified_name)
.expect("interface type scheme must exist")
.clone();
And:
if is_instance_method && has_unannotated_self {
fn_ty = fn_ty.with_replaced_first_param(&interface_ty);
}
So interface_ty is substituted as the type of self. Then later:
let method_ty = ... // some transformation of fn_ty
Wait, let me look at what happens to the method type between being extracted and being stored:
let mut fn_ty = self.extract_function_signature(&*store, &method_sig, span);
...
if is_instance_method && has_unannotated_self {
fn_ty = fn_ty.with_replaced_first_param(&interface_ty);
}
...
let method_ty = ... // need to check this
Actually, I need to see the full context. Let me look at the full register_interface function.
Actually, let me try a different approach. Instead of tracing through all the code, let me add a test that works (struct method) and compare with the interface test to understand the difference.
But wait - I can't modify tests. Let me just look at what's happening by examining the test output more carefully.
The test says: "should include 'example' method from interface, got: []"
So no completions at all. This means either:
detect_dot_context returns None AND resolve_variable_type returns None
detect_dot_context returns Some(DotContext::Instance(wrong_type_id)) AND get_instance_completions returns empty
Let me check if maybe the issue is that the type of ex isn't a Nominal type. If the semantic analyzer doesn't resolve the interface type annotation, the parameter's type might be something like Type::Error or unresolved.
Actually wait, I just realized something. The test uses a simple source file without a project structure. It's in "standalone mode". In standalone mode, type resolution might work differently.
Let me check if the interface type is properly resolved in standalone mode...
Hmm, actually let me try a different test. Let me modify my test to use a let binding instead of a function parameter:
Wait, I can't modify tests. Let me just analyze the code and figure out the fix.
Actually, let me re-read the completion handler more carefully. When detect_dot_context returns None, it falls through to:
if let Some(prefix) = get_module_prefix(&file.source, offset as usize) {
if prefix == "self" {
// Handle self in impl blocks
} else {
// Check for type-level completions (module.Type)
for module in [file.module_id.as_str(), "prelude"] {
let qualified = format!("{module}.{prefix}");
if let Some(definition) = snapshot.definitions().get(qualified.as_str())
&& definition.is_type_definition()
{
// Return type-level completions
}
}
// Check imports
for import in file.imports() {
...
}
// Check if prefix is a variable
let indexed = offset as usize >= 2 && file.source.as_bytes()[offset as usize - 2] == b']';
if let Some(type_id) = resolve_variable_type(prefix, file, offset, &snapshot, indexed) {
let items = get_instance_completions(&type_id, &snapshot, same_module);
return Ok(Some(CompletionResponse::Array(items)));
}
}
return Ok(Some(CompletionResponse::Array(vec![])));
}
So if resolve_variable_type returns None, we return empty completions. That's what's happening.
Now, why does resolve_variable_type return None for function parameters?
Let me trace through resolve_variable_type step by step:
pub(crate) fn resolve_variable_type(
var_name: &str, // "ex"
file: &syntax::program::File,
offset: u32,
snapshot: &AnalysisSnapshot,
indexed: bool, // false
) -> Option<String> {
let binding =
snapshot.facts().bindings.values().find(|b| {
b.name == var_name && b.span.file_id == file.id && b.span.byte_offset < offset
})?; // Is there a binding for "ex"?
let expression = find_expression_at(&file.items, binding.span.byte_offset)?;
// This returns Expression::Function for a parameter binding
let borrowed_ty = match expression {
...
Expression::Function { params, .. } => {
let param = params.iter().find(|p| match &p.pattern {
Pattern::Identifier { identifier, .. } => identifier == var_name,
...
})?;
Some(¶m.ty)
}
_ => None,
};
...
}
For this to return None, either:
- No binding named "ex" is found
find_expression_at returns None
- The expression is not a Function/Lambda
- The param "ex" is not found in the function's params
type_name returns None for the param's type
Let me check each of these:
- Is there a binding for "ex"? The semantic analyzer should register function parameter bindings. Let me verify.
Actually, let me check if maybe the issue is different. Maybe detect_dot_context IS finding a DotAccess expression, but the type resolution is failing.
Looking at detect_dot_context:
let Expression::DotAccess {
expression, member, ..
} = find_expression_at(&file.items, offset.saturating_sub(1))?
else {
return None;
};
If the parser creates a DotAccess for ex., then expression is the Identifier ex and member is empty.
Then:
if let Some(type_id) = type_name(&ty) {
return Some(DotContext::Instance(type_id));
}
Where ty = expression.get_type(). The type of ex (an Identifier expression) should be the interface type.
But wait - is ex even typed? When you have a function parameter with type annotation Example, the identifier ex in the function body should have its type resolved to the interface type. But is this resolved in the AST?
Let me check what expression.get_type() returns for an Identifier expression...
Actually, I think the issue might be that when the cursor is at ex., the parser might not create a DotAccess expression. If the member is empty, the parser might just parse ex as an Identifier and leave the dot as an error or ignore it.
If the parser doesn't create a DotAccess, then detect_dot_context returns None (because the match fails), and we fall through to the fallback logic.
In the fallback, resolve_variable_type is called. For this to work, the binding "ex" needs to be found, and its type needs to be resolved.
Hmm, let me check if the issue is that in standalone mode (no project), the module ID might be different from what I expect. Let me check what module ID is used for standalone files...
Actually, I realize I should just look at this more systematically. Let me check what the actual issue is by examining the code path.
Let me think about what could cause get_instance_completions to return empty:
pub(crate) fn get_instance_completions(
type_id: &str, // e.g., "main.Example"
snapshot: &AnalysisSnapshot,
same_module: bool,
) -> Vec<CompletionItem> {
let mut items = Vec::new();
// Only adds struct fields, not interface methods
if let Some(syntax::program::Definition {
body: syntax::program::DefinitionBody::Struct { fields, .. },
..
}) = snapshot.definitions().get(type_id) {
// Add fields
}
// Look for methods
let method_prefix = format!("{type_id}.");
for (qname, definition) in snapshot.definitions().iter() {
if let Some(method_name) = qname.strip_prefix(method_prefix.as_str())
&& !method_name.contains('.')
&& matches!(definition.body, DefinitionBody::Value { .. })
&& is_instance_method(definition.ty(), type_id)
&& (same_module || definition.visibility().is_public())
{
items.push(...);
}
}
items
}
So for interface methods to be returned:
- The definition must be in
snapshot.definitions() with key {type_id}.{method_name}
- The body must be
DefinitionBody::Value
is_instance_method must return true
- Visibility must be correct
The is_instance_method function checks if the first parameter type equals type_id:
fn is_instance_method(ty: &syntax::types::Type, type_id: &str) -> bool {
let func_ty = match ty {
Type::Forall { body, .. } => body,
other => other,
};
match func_ty {
Type::Function { params, .. } if !params.is_empty() => {
type_name(¶ms[0]).is_some_and(|name| name == type_id)
}
_ => false,
}
}
This calls type_name(¶ms[0]) to get the first parameter's type name. If the first parameter's type is a Type::Nominal { id: qualified_name, .. }, then type_name returns the qualified name.
But what if the first parameter's type is something else? Like a Type::Parameter (generic type parameter)?
For interface methods, the self parameter might be typed differently than regular methods. Let me check...
In the interface registration code:
if is_instance_method && has_unannotated_self {
fn_ty = fn_ty.with_replaced_first_param(&interface_ty);
}
So the first parameter is replaced with interface_ty. But what is interface_ty?
let interface_ty = store
.get_type(&qualified_name)
.expect("interface type scheme must exist")
.clone();
store.get_type() returns a type from the store. What kind of type is this?
Let me check what get_type returns for interface types...
Actually, I think I need to look at the actual type of interface_ty more carefully. It might be a Type::Scheme or similar wrapper that contains the actual type.
Wait, I see that method_ty might go through additional transformations. Let me look at what wrap_with_impl_generics does and how method_ty is computed...
Actually, let me step back and think about this differently. The issue is that completions don't work for interfaces. The most likely causes are:
- The type of the variable
ex is not resolved (so resolve_variable_type returns None)
- The interface methods are not registered with the correct qualified name
- The
is_instance_method check fails because the first parameter type doesn't match
Let me check #2 first - are interface methods registered correctly?
Interface methods are registered as:
let method_qualified_name = format!("{}.{}.{}", module_id, interface_name, method_name);
And instance methods from impl blocks are registered as:
let qualified_name = format!("{}.{}", type_name, fn_sig.name);
let module_qualified_name = Symbol::from_parts(&module_id, &qualified_name);
So impl methods are registered as {module_id}.{type_name}.{method_name}, and interface methods are registered as {module_id}.{interface_name}.{method_name}. These should be the same format!
Wait, actually looking at impl method registration more carefully:
let qualified_name = format!("{}.{}", type_name, fn_sig.name);
let module_qualified_name = Symbol::from_parts(&module_id, &qualified_name);
Where type_name is from receiver_ty.get_name(). For a struct Point, type_name would be "Point". So the qualified name would be "Point.method", and the module_qualified_name would be "main.Point.method".
For interface methods:
let method_qualified_name = format!("{}.{}.{}", module_id, interface_name, method_name);
Where interface_name is the interface name. So for interface Example, it would be "main.Example.example".
These should be the same format! So #2 shouldn't be the issue.
Let me check #3 - does is_instance_method match?
For is_instance_method to return true, type_name(¶ms[0]) must return the same string as type_id.
The type_id passed to get_instance_completions comes from resolve_variable_type or detect_dot_context. For a variable of interface type, this should be the qualified name like "main.Example".
The first parameter of the interface method type should be the interface type. But what is the actual type?
Let me check what interface_ty is when it's substituted for self:
let interface_ty = store.get_type(&qualified_name).clone();
store.get_type returns a Type. For an interface, this might be a Type::Nominal { id: qualified_name, .. }.
So type_name(¶ms[0]) should return the qualified name, which should match type_id.
Hmm, but wait - there might be a difference. The interface_ty is the type stored in the semantic store. But when it's used in fn_ty.with_replaced_first_param(&interface_ty), is it cloned correctly?
Actually, let me look at the actual definition of with_replaced_first_param:
Actually, this is getting too complex. Let me try a different approach. Let me look at what happens when we complete on a struct type parameter vs an interface type parameter:
Working case (struct):
struct Point { x: int, y: int }
impl Point { fn dist(self) -> int { ... } }
fn main() {
let p = &Point { x: 1, y: 2 }
p.dist()
}
In this case:
p is a Ref<Point>
resolve_variable_type finds the binding for p
- The expression is
Let { binding, value, ... }
type_name unwraps Ref and returns "main.Point" or "prelude.Ref" - wait, Ref is handled by unwrapping:
Type::Compound { kind: CompoundKind::Ref, args } => args.first().and_then(type_name)
- So
type_id = "main.Point" or whatever the module is
get_instance_completions("main.Point", ...) finds methods with prefix "main.Point."
is_instance_method checks if first param type is "main.Point" - yes!
Interface case:
interface Example { fn example(self, name: string) -> string }
fn example_call(ex: Example) -> string {
ex.
}
In this case:
ex is of type Example (interface)
resolve_variable_type tries to find the binding for ex
- The binding's span is at the parameter declaration
find_expression_at at the binding's span returns... the Function expression (since the parameter is within the function's span)
- The match arm for Function finds the param and returns its type
- The param's type should be the interface type
type_name should return the qualified name
Wait, but I think the issue might be that the parameter's type isn't a Nominal type. When you write ex: Example in a type annotation, the type Example is resolved to a Nominal type during semantic analysis. But what if it's not resolved properly?
Actually, let me check if maybe the issue is simpler. Let me look at what detect_dot_context returns when the member is empty.
Wait, I think I should check if detect_dot_context is even being reached. When the cursor is at ex., is the offset correct?
Looking at the test:
let response = client.completion(TEST_URI, 5, 5).await;
Line 5 (0-indexed), character 5. The source is:
interface Example {
fn example(self, name: string) -> string
}
fn example_call(ex: Example) -> string {
ex.
}
Line 0: interface Example {
Line 1: fn example(self, name: string) -> string
Line 2: }
Line 3: `` (empty)
Line 4: fn example_call(ex: Example) -> string {
Line 5: ex.
Line 6: }
Line 5 is ex.. Character 5 would be right after the dot (2 spaces + ex + . = 5 characters, so character 5 is the position after the dot).
So the cursor is right after the dot. The offset would be the byte offset of the position right after the dot.
detect_dot_context looks for a DotAccess at offset - 1, which is the position of the dot.
If the parser doesn't create a DotAccess expression (because the member is empty), then find_expression_at at the dot position might return None or might return the parent Block.
Actually, wait. If the parser DOES create a DotAccess with an empty member, then:
expression is the Identifier ex
member is empty
Then detect_dot_context continues:
if let Expression::Identifier { value, .. } = expression.as_ref() {
for prefix in [file.module_id.as_str(), "prelude"] {
let qualified = format!("{prefix}.{value}");
if let Some(definition) = snapshot.definitions().get(qualified.as_str())
&& definition.is_type_definition()
{
return Some(DotContext::TypeLevel(qualified));
}
}
}
This checks if ex is a type definition (like module.Example). Since ex is a variable, not a type, this check fails.
Then:
let ty = expression.get_type();
if let Some(type_id) = type_name(&ty) {
return Some(DotContext::Instance(type_id));
}
This gets the type of ex. If ex has a type, type_name should return the qualified name.
So the issue might be that expression.get_type() for the Identifier ex doesn't return the interface type!
Let me check what type the Identifier expression has. In the AST, an Identifier expression has a ty field. But this might be the type that was inferred during semantic analysis, not the type annotation.
For a function parameter like ex: Example, the variable ex used in the function body should have its type resolved to the interface type. But is this reflected in the Identifier expression's ty field?
Actually, when you use a variable like ex in an expression, the Identifier expression's ty should be set during type inference. So ex.get_type() should return the interface type.
But wait - in the case where the cursor is right after ex. with an empty member, is there even an Identifier expression for ex? The parser might not create one if the expression is incomplete.
Hmm, actually I think the parser DOES create a DotAccess expression for ex. even with an empty member. Let me check the parser code...
Actually, I don't think I can check the parser code easily. Let me try a different approach.
Let me check if maybe the issue is in detect_dot_context returning None when the DotAccess expression has an empty member, and the fallback code not working.
Actually wait, I just realized something. Let me re-read detect_dot_context:
if !member.is_empty() {
if !matches!(
get_root_expression(expression),
Expression::Identifier {
binding_id: None,
..
}
) {
let ty = expression.get_type();
return type_name(&ty).map(DotContext::Instance);
}
return None;
}
This block handles the case when member.is_empty() is FALSE (i.e., member is NOT empty). It's inside the if !member.is_empty() block.
So when member.is_empty() is TRUE (which is our case), this block is SKIPPED, and we continue to:
if let Expression::Identifier { value, .. } = expression.as_ref() {
...
}
let ty = expression.get_type();
if let Some(type_id) = type_name(&ty) {
return Some(DotContext::Instance(type_id));
}
This is the code that runs when member IS empty. So:
- Check if expression is an Identifier and if it's a type-level access
- Get the type of the expression and return it
So the issue is in type_name(&ty) for the type of ex.
What is expression.get_type() for the Identifier ex?
If ex is the base expression of a DotAccess (ex.something), then expression in detect_dot_context is the Identifier ex. Its type should be the interface type.
But what if the type is not resolved? For example, if the semantic analyzer hasn't resolved the type annotation Example to a qualified type?
Let me check if maybe the issue is that in standalone mode, the interface type isn't properly resolved.
Actually, I think I need to check what type the expression has. Let me look at how types are assigned to Identifier expressions during semantic analysis...
Actually, I've been going around in circles. Let me try to make a hypothesis and test it.
Hypothesis: The issue is that detect_dot_context successfully returns a DotContext::Instance(type_id), but get_instance_completions returns empty because is_instance_method doesn't match for interface methods.
The reason is_instance_method might not match is that the first parameter type of interface methods is not a Nominal type with the qualified name, but rather some other type representation.
Let me check what type the self parameter has for interface methods...
Looking at the registration code:
let interface_ty = store.get_type(&qualified_name).clone();
...
if is_instance_method && has_unannotated_self {
fn_ty = fn_ty.with_replaced_first_param(&interface_ty);
}
store.get_type(&qualified_name) returns the type of the interface from the store. This might be a Type::Scheme or a Type::Nominal. Let me check...
Actually, I think store.get_type returns a Type that represents the type scheme, which might be wrapped in a Forall or similar.
Wait, but with_replaced_first_param should work with any type. The question is what type is stored.
Let me look at with_replaced_first_param:
<tool_call>
<function=bash_terminal>
<parameter=command>
grep -rn "with_replaced_first_param" /lisette/crates/
</tool_call>