MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / emit_parameter_hints

Method emit_parameter_hints

src/inlay_hints.rs:109–253  ·  view source on GitHub ↗

Emit parameter-name and by-reference hints for a single call site.

(
        &self,
        call_site: &CallSite,
        content: &str,
        range: Range,
        ctx: &FileContext,
        hints: &mut Vec<InlayHint>,
    )

Source from the content-addressed store, hash-verified

107
108 /// Emit parameter-name and by-reference hints for a single call site.
109 fn emit_parameter_hints(
110 &self,
111 call_site: &CallSite,
112 content: &str,
113 range: Range,
114 ctx: &FileContext,
115 hints: &mut Vec<InlayHint>,
116 ) {
117 // Build a synthetic position from the call site's start so that
118 // resolve_callable_target has a cursor context.
119 let position = offset_to_position(content, call_site.args_start as usize);
120
121 let resolved = match self.resolve_callable_target(
122 &call_site.call_expression,
123 content,
124 position,
125 ctx,
126 ) {
127 Some(r) => r,
128 None => return,
129 };
130
131 let params = &resolved.parameters;
132 if params.is_empty() {
133 return;
134 }
135
136 let range_start = position_to_offset(content, range.start);
137 let range_end = position_to_offset(content, range.end);
138
139 // Build a set of parameter names consumed by named arguments so
140 // positional arguments can be mapped to the remaining parameters.
141 let named_consumed: std::collections::HashSet<&str> = call_site
142 .named_arg_names
143 .iter()
144 .map(|n| n.as_str())
145 .collect();
146
147 // Parameters not consumed by named args, in declaration order.
148 // Each positional argument is assigned to the next entry in this
149 // list. For variadic parameters the last entry is reused.
150 let remaining_params: Vec<usize> = params
151 .iter()
152 .enumerate()
153 .filter(|(_, p)| {
154 let name = p.name.strip_prefix('$').unwrap_or(&p.name);
155 !named_consumed.contains(name)
156 })
157 .map(|(i, _)| i)
158 .collect();
159
160 let mut positional_counter: usize = 0;
161
162 for (arg_idx, &arg_offset) in call_site.arg_offsets.iter().enumerate() {
163 // Skip arguments outside the viewport range.
164 if arg_offset < range_start || arg_offset > range_end {
165 continue;
166 }

Callers 1

handle_inlay_hintsMethod · 0.80

Calls 13

offset_to_positionFunction · 0.85
should_suppress_hintFunction · 0.85
is_obvious_single_paramFunction · 0.85
iterMethod · 0.80
as_strMethod · 0.80
filterMethod · 0.80
containsMethod · 0.80
lastMethod · 0.80
pushMethod · 0.80
position_to_offsetFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected