Fix completion tests to handle receiving all items
parent
67081c4abe
commit
b5412621d6
|
@ -247,7 +247,8 @@ class CompletionProvider
|
|||
|
||||
foreach ($this->index->getDefinitions() as $fqn => $def) {
|
||||
$fqnStartsWithPrefix = strStartsWith($fqn, $prefix);
|
||||
if (($def->canBeInstantiated || ($def->isGlobal && !isset($creation))) && strStartsWith($fqn, $prefix)) {
|
||||
$fqnContainsPrefix = empty($prefix) || strpos($fqn, $prefix) !== false;
|
||||
if (($def->canBeInstantiated || ($def->isGlobal && !isset($creation))) && $fqnContainsPrefix) {
|
||||
if ($namespaceDefinition !== null && $namespaceDefinition->name !== null) {
|
||||
$namespacePrefix = (string)Tolerant\ResolvedName::buildName($namespaceDefinition->name->nameParts, $node->getFileContents());
|
||||
|
||||
|
@ -306,7 +307,7 @@ class CompletionProvider
|
|||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -53,7 +53,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(3, 7)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'testProperty',
|
||||
CompletionItemKind::PROPERTY,
|
||||
|
@ -77,7 +77,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(3, 6)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'testProperty',
|
||||
CompletionItemKind::PROPERTY,
|
||||
|
@ -101,7 +101,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(8, 5)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'$var',
|
||||
CompletionItemKind::VARIABLE,
|
||||
|
@ -133,7 +133,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(8, 6)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'$param',
|
||||
CompletionItemKind::VARIABLE,
|
||||
|
@ -155,7 +155,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(6, 10)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
// Global TestClass definition (inserted as \TestClass)
|
||||
new CompletionItem(
|
||||
'TestClass',
|
||||
|
@ -205,7 +205,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(6, 5)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'TestClass',
|
||||
CompletionItemKind::CLASS_,
|
||||
|
@ -226,7 +226,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(2, 14)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'staticTestProperty',
|
||||
CompletionItemKind::PROPERTY,
|
||||
|
@ -247,7 +247,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(2, 11)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'TEST_CLASS_CONST',
|
||||
CompletionItemKind::VARIABLE,
|
||||
|
@ -280,7 +280,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(2, 13)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'TEST_CLASS_CONST',
|
||||
CompletionItemKind::VARIABLE,
|
||||
|
@ -313,7 +313,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(2, 13)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'TEST_CLASS_CONST',
|
||||
CompletionItemKind::VARIABLE,
|
||||
|
@ -346,7 +346,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(6, 6)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'TestClass',
|
||||
CompletionItemKind::CLASS_,
|
||||
|
@ -367,7 +367,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(2, 1)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem('class', CompletionItemKind::KEYWORD, null, null, null, null, 'class '),
|
||||
new CompletionItem('clone', CompletionItemKind::KEYWORD, null, null, null, null, 'clone ')
|
||||
], true), $items);
|
||||
|
@ -381,7 +381,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(0, 0)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'<?php',
|
||||
CompletionItemKind::KEYWORD,
|
||||
|
@ -403,7 +403,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(0, 1)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'<?php',
|
||||
CompletionItemKind::KEYWORD,
|
||||
|
@ -425,7 +425,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(4, 6)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'SomeNamespace',
|
||||
CompletionItemKind::MODULE,
|
||||
|
@ -446,7 +446,7 @@ class CompletionTest extends TestCase
|
|||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(4, 8)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
$this->assertCompletionsListSubset(new CompletionList([
|
||||
new CompletionItem(
|
||||
'$abc2',
|
||||
CompletionItemKind::VARIABLE,
|
||||
|
@ -469,4 +469,12 @@ class CompletionTest extends TestCase
|
|||
)
|
||||
], true), $items);
|
||||
}
|
||||
|
||||
private function assertCompletionsListSubset(CompletionList $subsetList, CompletionList $list) {
|
||||
foreach ($subsetList->items as $expectedItem) {
|
||||
$this->assertContains($expectedItem, $list->items, null, null, false);
|
||||
}
|
||||
|
||||
$this->assertEquals($subsetList->isIncomplete, $list->isIncomplete);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue