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

Method build_server_key_completions

src/completion/array_shape.rs:399–437  ·  view source on GitHub ↗

Build completion items for `$_SERVER` superglobal keys.

(
        &self,
        ctx: &ArrayKeyContext,
        content: &str,
        position: Position,
    )

Source from the content-addressed store, hash-verified

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 ///

Callers 1

Calls 4

compute_edit_rangeMethod · 0.80
iterMethod · 0.80
pushMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected