Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Features:

Bug fixes:
- Fix parameter type resolution priority @dantleech
- Fix completion rendering when snippets are disabled @mamazu

## 2025.04.17.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ private function populateSuggestions(NodeContext $nodeContext, Type $type, bool
continue;
}

$snippet = null;
if ($this->snippetFormatter->canFormat($method)) {
$snippet = $completeOnlyName ? $method->name() : $this->snippetFormatter->format($method);
}

yield Suggestion::createWithOptions($method->name(), [
'type' => Suggestion::TYPE_METHOD,
'short_description' => fn () => $this->formatter->format($method),
Expand All @@ -157,7 +162,7 @@ private function populateSuggestions(NodeContext $nodeContext, Type $type, bool
$method->name()
), $method->docblock()->formatted(), $method));
},
'snippet' => $completeOnlyName ? $method->name() : $this->snippetFormatter->format($method),
'snippet' => $snippet,
]);
}

Expand Down
25 changes: 13 additions & 12 deletions lib/Completion/Core/Suggestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
use Closure;
use RuntimeException;

/** @phpstan-type SuggestionOptions array{
* short_description?:string|null|Closure,
* documentation?:string|null|Closure,
* type?:string|null,
* class_import?:string|null,
* name_import?:string|null,
* fqn?:string|null,
* label?:string|null,
* range?:Range|null,
* snippet?:string|null,
* priority?:int|null
* } */
class Suggestion
{
/**
Expand Down Expand Up @@ -66,18 +78,7 @@ public static function create(string $name): self
}

/**
* @param array{
* short_description?:string|null|Closure,
* documentation?:string|null|Closure,
* type?:string|null,
* class_import?:string|null,
* name_import?:string|null,
* fqn?:string|null,
* label?:string|null,
* range?:Range|null,
* snippet?:string|null,
* priority?:int|null
* } $options
* @param SuggestionOptions $options
*/
public static function createWithOptions(string $name, array $options): self
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@
use Phpactor\Completion\Bridge\TolerantParser\WorseReflection\WorseClassMemberCompletor;
use Generator;

/** @phpstan-import-type SuggestionOptions from Suggestion */
class WorseClassMemberCompletorTest extends TolerantCompletorTestCase
{
/**
* @dataProvider provideComplete
* @param array<SuggestionOptions> $expected
*/
public function testComplete(string $source, array $expected): void
{
$this->assertComplete($source, $expected);
}

/**
* @return Generator<string,array{string,array<int,array<string,string>>}>
* @return Generator<string,array{string,array<SuggestionOptions>}>
*/
public function provideComplete(): Generator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Phpactor\Completion\Tests\Integration\Bridge\TolerantParser\WorseReflection;

use Phpactor\Completion\Bridge\TolerantParser\TolerantCompletor;
use Phpactor\Completion\Core\Formatter\ObjectFormatter;
use Phpactor\ObjectRenderer\ObjectRendererBuilder;
use Phpactor\TextDocument\TextDocument;
use Phpactor\WorseReflection\Bridge\Phpactor\MemberProvider\DocblockMemberProvider;
use Phpactor\WorseReflection\ReflectorBuilder;
use Phpactor\Completion\Bridge\TolerantParser\WorseReflection\WorseClassMemberCompletor;
use Phpactor\Completion\Core\Suggestion;

/** @phpstan-import-type SuggestionOptions from Suggestion */
class WorseClassMemberCompletorTestWithoutSnippetFormatter extends WorseClassMemberCompletorTest
{
/**
* @dataProvider provideComplete
* @param array<SuggestionOptions> $expected
*/
public function testComplete(string $source, array $expected): void
{
// Expect all snippets to be null
foreach ($expected as &$suggestion) {
if (array_key_exists('snippet', $suggestion)) {
$suggestion['snippet'] = null;
}
}

$this->assertComplete($source, $expected);
}

protected function createTolerantCompletor(TextDocument $source): TolerantCompletor
{
$reflector = ReflectorBuilder::create()
->addMemberProvider(new DocblockMemberProvider())
->addSource($source)->build();

return new WorseClassMemberCompletor(
$reflector,
$this->formatter(),
new ObjectFormatter(),
ObjectRendererBuilder::create()->renderEmptyOnNotFound()->build()
);
}
}
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -795,11 +795,6 @@ parameters:
count: 1
path: lib/Completion/Tests/Integration/Bridge/TolerantParser/SourceCodeFilesystem/ScfClassCompletorTest.php

-
message: "#^Method Phpactor\\\\Completion\\\\Tests\\\\Integration\\\\Bridge\\\\TolerantParser\\\\WorseReflection\\\\WorseClassMemberCompletorTest\\:\\:testComplete\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#"
count: 1
path: lib/Completion/Tests/Integration/Bridge/TolerantParser/WorseReflection/WorseClassMemberCompletorTest.php

-
message: "#^Class Phpactor\\\\Completion\\\\Bridge\\\\TolerantParser\\\\WorseReflection\\\\WorseConstantCompletor does not have a constructor and must be instantiated without any parameters\\.$#"
count: 1
Expand Down Expand Up @@ -3805,11 +3800,6 @@ parameters:
count: 1
path: lib/Extension/LanguageServerReferenceFinder/LanguageServerReferenceFinderExtension.php

-
message: "#^Parameter \\#1 \\$workspace of class Phpactor\\\\Extension\\\\LanguageServerReferenceFinder\\\\Handler\\\\HighlightHandler constructor expects Phpactor\\\\LanguageServer\\\\Core\\\\Workspace\\\\Workspace, mixed given\\.$#"
count: 1
path: lib/Extension/LanguageServerReferenceFinder/LanguageServerReferenceFinderExtension.php

-
message: "#^Parameter \\#1 \\$workspace of class Phpactor\\\\Extension\\\\LanguageServerReferenceFinder\\\\Handler\\\\ReferencesHandler constructor expects Phpactor\\\\LanguageServer\\\\Core\\\\Workspace\\\\Workspace, mixed given\\.$#"
count: 1
Expand Down