From 10402c426b86a0b49f35ab81585c660e94b4b726 Mon Sep 17 00:00:00 2001 From: Ivan Sidorov Date: Tue, 23 Jan 2024 07:25:51 +0000 Subject: [PATCH] Partial revert "Fix auto completion by partial property or method" Filtering is not necessary. Clients using LSP should filter the results themselves. That's what it says in the documentation. This reverts commit d6faff2844dbcd40df108052fbdd929bdeafc7a9. --- src/Psalm/Codebase.php | 2 + .../LanguageServer/Server/TextDocument.php | 3 - tests/LanguageServer/CompletionTest.php | 196 ------------------ 3 files changed, 2 insertions(+), 199 deletions(-) diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 993958e607a..db400c999c2 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -2039,6 +2039,8 @@ public function getCompletionItemsForClassishThing( /** * @param list $items * @return list + * @deprecated to be removed in Psalm 6 + * @api fix deprecation problem "PossiblyUnusedMethod: Cannot find any calls to method" */ public function filterCompletionItemsByBeginLiteralPart(array $items, string $literal_part): array { diff --git a/src/Psalm/Internal/LanguageServer/Server/TextDocument.php b/src/Psalm/Internal/LanguageServer/Server/TextDocument.php index 451da44e938..a4af46cacec 100644 --- a/src/Psalm/Internal/LanguageServer/Server/TextDocument.php +++ b/src/Psalm/Internal/LanguageServer/Server/TextDocument.php @@ -297,7 +297,6 @@ public function completion(TextDocumentIdentifier $textDocument, Position $posit try { $completion_data = $this->codebase->getCompletionDataAtPosition($file_path, $position); - $literal_part = $this->codebase->getBeginedLiteralPart($file_path, $position); if ($completion_data) { [$recent_type, $gap, $offset] = $completion_data; @@ -306,8 +305,6 @@ public function completion(TextDocumentIdentifier $textDocument, Position $posit ->textDocument->completion->completionItem->snippetSupport ?? false; $completion_items = $this->codebase->getCompletionItemsForClassishThing($recent_type, $gap, $snippetSupport); - $completion_items = - $this->codebase->filterCompletionItemsByBeginLiteralPart($completion_items, $literal_part); } elseif ($gap === '[') { $completion_items = $this->codebase->getCompletionItemsForArrayKeys($recent_type); } else { diff --git a/tests/LanguageServer/CompletionTest.php b/tests/LanguageServer/CompletionTest.php index 268f399821e..656951253d5 100644 --- a/tests/LanguageServer/CompletionTest.php +++ b/tests/LanguageServer/CompletionTest.php @@ -15,7 +15,6 @@ use Psalm\Tests\TestConfig; use Psalm\Type; -use function array_map; use function count; class CompletionTest extends TestCase @@ -726,201 +725,6 @@ public function baz() {} $this->assertSame('baz()', $completion_items[1]->insertText); } - public function testObjectPropertyOnAppendToEnd(): void - { - $codebase = $this->codebase; - $config = $codebase->config; - $config->throw_exception = false; - - $this->addFile( - 'somefile.php', - 'aPr - } - }', - ); - - $codebase->file_provider->openFile('somefile.php'); - $codebase->scanFiles(); - - $this->analyzeFile('somefile.php', new Context()); - - $position = new Position(8, 34); - $completion_data = $codebase->getCompletionDataAtPosition('somefile.php', $position); - $literal_part = $codebase->getBeginedLiteralPart('somefile.php', $position); - - $this->assertSame(['B\A&static', '->', 223], $completion_data); - - $completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1], true); - $completion_items = $codebase->filterCompletionItemsByBeginLiteralPart($completion_items, $literal_part); - $completion_item_texts = array_map(fn($item) => $item->insertText, $completion_items); - - $this->assertSame(['aProp'], $completion_item_texts); - } - - public function testObjectPropertyOnReplaceEndPart(): void - { - $codebase = $this->codebase; - $config = $codebase->config; - $config->throw_exception = false; - - $this->addFile( - 'somefile.php', - 'aProp2; - } - }', - ); - - $codebase->file_provider->openFile('somefile.php'); - $codebase->scanFiles(); - - $this->analyzeFile('somefile.php', new Context()); - - $position = new Position(8, 34); - $completion_data = $codebase->getCompletionDataAtPosition('somefile.php', $position); - $literal_part = $codebase->getBeginedLiteralPart('somefile.php', $position); - - $this->assertSame(['B\A&static', '->', 225], $completion_data); - - $completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1], true); - $completion_items = $codebase->filterCompletionItemsByBeginLiteralPart($completion_items, $literal_part); - $completion_item_texts = array_map(fn($item) => $item->insertText, $completion_items); - - $this->assertSame(['aProp1', 'aProp2'], $completion_item_texts); - } - - public function testSelfPropertyOnAppendToEnd(): void - { - $codebase = $this->codebase; - $config = $codebase->config; - $config->throw_exception = false; - - $this->addFile( - 'somefile.php', - 'file_provider->openFile('somefile.php'); - $codebase->scanFiles(); - - $this->analyzeFile('somefile.php', new Context()); - - $position = new Position(8, 34); - $completion_data = $codebase->getCompletionDataAtPosition('somefile.php', $position); - $literal_part = $codebase->getBeginedLiteralPart('somefile.php', $position); - - $this->assertSame(['B\A', '::', 237], $completion_data); - - $completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1], true); - $completion_items = $codebase->filterCompletionItemsByBeginLiteralPart($completion_items, $literal_part); - $completion_item_texts = array_map(fn($item) => $item->insertText, $completion_items); - - $this->assertSame(['$aProp'], $completion_item_texts); - } - - public function testStaticPropertyOnAppendToEnd(): void - { - $codebase = $this->codebase; - $config = $codebase->config; - $config->throw_exception = false; - - $this->addFile( - 'somefile.php', - 'file_provider->openFile('somefile.php'); - $codebase->scanFiles(); - - $this->analyzeFile('somefile.php', new Context()); - - $position = new Position(8, 36); - $completion_data = $codebase->getCompletionDataAtPosition('somefile.php', $position); - $literal_part = $codebase->getBeginedLiteralPart('somefile.php', $position); - - $this->assertSame(['B\A', '::', 239], $completion_data); - - $completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1], true); - $completion_items = $codebase->filterCompletionItemsByBeginLiteralPart($completion_items, $literal_part); - $completion_item_texts = array_map(fn($item) => $item->insertText, $completion_items); - - $this->assertSame(['$aProp'], $completion_item_texts); - } - - public function testStaticPropertyOnReplaceEndPart(): void - { - $codebase = $this->codebase; - $config = $codebase->config; - $config->throw_exception = false; - - $this->addFile( - 'somefile.php', - 'file_provider->openFile('somefile.php'); - $codebase->scanFiles(); - - $this->analyzeFile('somefile.php', new Context()); - - $position = new Position(8, 34); - $completion_data = $codebase->getCompletionDataAtPosition('somefile.php', $position); - $literal_part = $codebase->getBeginedLiteralPart('somefile.php', $position); - - $this->assertSame(['B\A', '::', 239], $completion_data); - - $completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1], true); - $completion_items = $codebase->filterCompletionItemsByBeginLiteralPart($completion_items, $literal_part); - $completion_item_texts = array_map(fn($item) => $item->insertText, $completion_items); - - $this->assertSame(['$aProp1', '$aProp2'], $completion_item_texts); - } - public function testCompletionOnNewExceptionWithoutNamespace(): void { $codebase = $this->codebase;