Build completion items for `$_SERVER` superglobal keys.
(
&self,
ctx: &ArrayKeyContext,
content: &str,
position: Position,
)
| 397 | |
| 398 | /// Build completion items for `$_SERVER` superglobal keys. |
| 399 | fn build_server_key_completions( |
| 400 | &self, |
| 401 | ctx: &ArrayKeyContext, |
| 402 | content: &str, |
| 403 | position: Position, |
| 404 | ) -> Vec<CompletionItem> { |
| 405 | let (range, _) = self.compute_edit_range(ctx, content, position); |
| 406 | let quote = ctx.quote_char.unwrap_or('\''); |
| 407 | let mut items = Vec::new(); |
| 408 | |
| 409 | for (sort_idx, &(key, detail)) in SERVER_KEYS.iter().enumerate() { |
| 410 | // Filter by partial key prefix. |
| 411 | if !ctx.partial_key.is_empty() |
| 412 | && !key |
| 413 | .to_lowercase() |
| 414 | .starts_with(&ctx.partial_key.to_lowercase()) |
| 415 | { |
| 416 | continue; |
| 417 | } |
| 418 | |
| 419 | let new_text = if ctx.quote_char.is_some() { |
| 420 | format!("{}{}]", key, quote) |
| 421 | } else { |
| 422 | format!("{}{}{}]", quote, key, quote) |
| 423 | }; |
| 424 | |
| 425 | items.push(CompletionItem { |
| 426 | label: key.to_string(), |
| 427 | kind: Some(CompletionItemKind::FIELD), |
| 428 | detail: Some(detail.to_string()), |
| 429 | filter_text: Some(key.to_string()), |
| 430 | text_edit: Some(CompletionTextEdit::Edit(TextEdit { range, new_text })), |
| 431 | sort_text: Some(format!("{:04}", sort_idx)), |
| 432 | ..CompletionItem::default() |
| 433 | }); |
| 434 | } |
| 435 | |
| 436 | items |
| 437 | } |
| 438 | |
| 439 | /// Compute the `TextEdit` range for an array key completion. |
| 440 | /// |
no test coverage detected