Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial revert "Fix auto completion by partial property or method" #10588

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Psalm/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,8 @@ public function getCompletionItemsForClassishThing(
/**
* @param list<CompletionItem> $items
* @return list<CompletionItem>
* @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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to keep the method to satisfy backward compatibility checks, but mark it @deprecated to be removed in Psalm 6.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll fix it. I didn't notice that a release had already been made. I thought this method was not yet in release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PossiblyUnusedMethod: Cannot find any calls to method Psalm\Codebase::filterCompletionItemsByBeginLiteralPart

another problem )))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problem is fixed by annotation @api...

{
Expand Down
3 changes: 0 additions & 3 deletions src/Psalm/Internal/LanguageServer/Server/TextDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down
196 changes: 0 additions & 196 deletions tests/LanguageServer/CompletionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Psalm\Tests\TestConfig;
use Psalm\Type;

use function array_map;
use function count;

class CompletionTest extends TestCase
Expand Down Expand Up @@ -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',
'<?php
namespace B;

class A {
public $aProp = 123;
public $bProp = 234;

public function bar() {
$this->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',
'<?php
namespace B;

class A {
public $aProp1 = 123;
public $aProp2 = 234;

public function bar() {
$this->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',
'<?php
namespace B;

class A {
public static $aProp = 123;
public static $bProp = 234;

public function bar() {
self::$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', '::', 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',
'<?php
namespace B;

class A {
public static $aProp = 123;
public static $bProp = 234;

public function bar() {
static::$aPr
}
}',
);

$codebase->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',
'<?php
namespace B;

class A {
public static $aProp1 = 123;
public static $aProp2 = 234;

public function bar() {
self::$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', '::', 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;
Expand Down
Loading