Skip to content

Commit 8ed83dc

Browse files
committed
fix: wire config resolver into array shape key completion
The array shape completion path constructed its Loaders without the config_resolver closure, so variables assigned from config() calls did not offer array key completions even though hover showed the correct array shape type. Pass the config resolver through so $mysql['...'] offers the expected keys.
1 parent c7cd659 commit 8ed83dc

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

src/completion/array_shape.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ impl Backend {
534534
}
535535
};
536536
let function_loader = self.function_loader(file_ctx);
537+
let config_resolver = |key: &str| self.resolve_config_type(key);
537538
let resolved = crate::type_engine::variable::resolution::resolve_variable_types(
538539
var_name,
539540
effective_class,
@@ -543,6 +544,7 @@ impl Backend {
543544
&class_loader,
544545
Loaders {
545546
function_loader: Some(&function_loader),
547+
config_resolver: Some(&config_resolver),
546548
..Loaders::default()
547549
},
548550
);

tests/integration/completion_array_shapes.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6393,3 +6393,71 @@ async fn test_array_shape_attribute_union_with_false() {
63936393
_ => panic!("Expected CompletionResponse::Array"),
63946394
}
63956395
}
6396+
6397+
#[tokio::test]
6398+
async fn test_array_shape_key_completion_from_config_return_type() {
6399+
let (backend, _dir) = crate::common::create_psr4_workspace(
6400+
r#"{ "autoload": { "psr-4": { "App\\": "src/" } } }"#,
6401+
&[(
6402+
"config/database.php",
6403+
"<?php\nreturn [\n 'default' => env('DB_CONNECTION', 'mysql'),\n 'connections' => [\n 'mysql' => [\n 'host' => env('DB_HOST', '127.0.0.1'),\n 'port' => env('DB_PORT', 3306),\n ],\n ],\n];\n",
6404+
)],
6405+
);
6406+
6407+
let uri = Url::parse("file:///test_config_shape.php").unwrap();
6408+
let text = concat!(
6409+
"<?php\n",
6410+
"function test(): void {\n",
6411+
" $mysql = config('database.connections.mysql');\n",
6412+
" $mysql['\n",
6413+
"}\n",
6414+
);
6415+
6416+
backend
6417+
.did_open(DidOpenTextDocumentParams {
6418+
text_document: TextDocumentItem {
6419+
uri: uri.clone(),
6420+
language_id: "php".to_string(),
6421+
version: 1,
6422+
text: text.to_string(),
6423+
},
6424+
})
6425+
.await;
6426+
6427+
let result = backend
6428+
.completion(CompletionParams {
6429+
text_document_position: TextDocumentPositionParams {
6430+
text_document: TextDocumentIdentifier { uri },
6431+
position: Position {
6432+
line: 3,
6433+
character: 12,
6434+
},
6435+
},
6436+
work_done_progress_params: WorkDoneProgressParams::default(),
6437+
partial_result_params: PartialResultParams::default(),
6438+
context: None,
6439+
})
6440+
.await
6441+
.unwrap();
6442+
6443+
assert!(
6444+
result.is_some(),
6445+
"Should return completions for config array shape keys"
6446+
);
6447+
match result.unwrap() {
6448+
CompletionResponse::Array(items) => {
6449+
let labels: Vec<&str> = items.iter().map(|i| i.label.as_str()).collect();
6450+
assert!(
6451+
labels.contains(&"host"),
6452+
"Should suggest 'host' from config shape, got {:?}",
6453+
labels
6454+
);
6455+
assert!(
6456+
labels.contains(&"port"),
6457+
"Should suggest 'port' from config shape, got {:?}",
6458+
labels
6459+
);
6460+
}
6461+
_ => panic!("Expected CompletionResponse::Array"),
6462+
}
6463+
}

0 commit comments

Comments
 (0)