mirror of
https://github.com/danog/psalm.git
synced 2024-12-03 10:07:52 +01:00
Merge pull request #10230 from ging-dev/lsp
feat(LSP): Improve the autocomplete for nested array shape
This commit is contained in:
commit
2d3a625379
@ -480,6 +480,17 @@ class ArrayFetchAnalyzer
|
|||||||
|
|
||||||
$key_values = [];
|
$key_values = [];
|
||||||
|
|
||||||
|
if ($codebase->store_node_types
|
||||||
|
&& !$context->collect_initializations
|
||||||
|
&& !$context->collect_mutations
|
||||||
|
) {
|
||||||
|
$codebase->analyzer->addNodeType(
|
||||||
|
$statements_analyzer->getFilePath(),
|
||||||
|
$stmt->var,
|
||||||
|
$array_type->getId(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($stmt->dim instanceof PhpParser\Node\Scalar\String_) {
|
if ($stmt->dim instanceof PhpParser\Node\Scalar\String_) {
|
||||||
$value_type = Type::getAtomicStringFromLiteral($stmt->dim->value);
|
$value_type = Type::getAtomicStringFromLiteral($stmt->dim->value);
|
||||||
if ($value_type instanceof TLiteralString) {
|
if ($value_type instanceof TLiteralString) {
|
||||||
|
@ -1380,6 +1380,39 @@ class CompletionTest extends TestCase
|
|||||||
$this->assertCount(2, $completion_items);
|
$this->assertCount(2, $completion_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCompletionOnNestedArrayKey(): void
|
||||||
|
{
|
||||||
|
$codebase = $this->codebase;
|
||||||
|
$config = $codebase->config;
|
||||||
|
$config->throw_exception = false;
|
||||||
|
|
||||||
|
$this->addFile(
|
||||||
|
'somefile.php',
|
||||||
|
'<?php
|
||||||
|
$my_array = ["foo" => ["bar" => 1]];
|
||||||
|
$my_array["foo"][]
|
||||||
|
',
|
||||||
|
);
|
||||||
|
|
||||||
|
$codebase->file_provider->openFile('somefile.php');
|
||||||
|
$codebase->scanFiles();
|
||||||
|
$this->analyzeFile('somefile.php', new Context());
|
||||||
|
|
||||||
|
$completion_data = $codebase->getCompletionDataAtPosition('somefile.php', new Position(2, 33));
|
||||||
|
$this->assertSame(
|
||||||
|
[
|
||||||
|
'array{bar: 1}',
|
||||||
|
'[',
|
||||||
|
92,
|
||||||
|
],
|
||||||
|
$completion_data,
|
||||||
|
);
|
||||||
|
|
||||||
|
$completion_items = $codebase->getCompletionItemsForArrayKeys($completion_data[0]);
|
||||||
|
|
||||||
|
$this->assertCount(1, $completion_items);
|
||||||
|
}
|
||||||
|
|
||||||
public function testTypeContextForFunctionArgument(): void
|
public function testTypeContextForFunctionArgument(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user