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

Gh 2434 callable crash #2438

Merged
merged 2 commits into from
Nov 22, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Bug fixes:
- Fix incorrect enum import #2400
- Fix undefined var false positive for arra unpacking #2403
- Fix autoloading class conflcits with test files #2535 @gerardroche
- Fix crash on resolveItem() caused by race condition (?) #2434

Features:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,19 @@ public function completion(CompletionParams $params, CancellationToken $token):
*/
public function resolveItem(RequestMessage $request): Promise
{
/** @phpstan-ignore-next-line */
return call(function () use ($request) {
/** @phpstan-ignore-next-line */
$item = CompletionItem::fromArray($request->params);
$item = $this->resolve[$item->data]($item);
return $item;

if (!(is_string($item->data) || is_int($item->data)) || !array_key_exists($item->data, $this->resolve)) {
return $item;
}
/** @phpstan-ignore-next-line - shouldn't happen but playing safe */
if (null === $this->resolve[$item->data]) {
return $item;
}
return $this->resolve[$item->data]($item);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ public function testResolveCompletionItem(): void
self::assertEquals('documentation now', $response->result->documentation->value);
}

public function testResolveCompletionItemWithNoPreviousCompletion(): void
{
$tester = $this->create([]);
$response = $tester->requestAndWait(
'completionItem/resolve',
new CompletionItem('hello'),
);
self::assertNotNull($response);
self::assertInstanceOf(CompletionItem::class, $response->result);
}

public function testHandleAnIncompleteListOfSuggestions(): void
{
$tester = $this->create([
Expand Down Expand Up @@ -481,6 +492,7 @@ private function createCompletor(array $suggestions, bool $isIncomplete = false)
{
return new class($suggestions, $isIncomplete) implements Completor {
public function __construct(
/** @var Suggestion[] */
private array $suggestions,
private bool $isIncomplete
) {
Expand Down