Skip to content

Commit

Permalink
Fixes #7246, wrap getTypeContextAtPosition in try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
tm1000 committed Dec 30, 2021
1 parent 7b18673 commit cb3cf88
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Psalm/Internal/LanguageServer/Server/TextDocument.php
Expand Up @@ -6,6 +6,7 @@

use Amp\Promise;
use Amp\Success;
use Exception;
use LanguageServerProtocol\CompletionList;
use LanguageServerProtocol\Hover;
use LanguageServerProtocol\Location;
Expand Down Expand Up @@ -276,14 +277,20 @@ public function completion(TextDocumentIdentifier $textDocument, Position $posit
return new Success([]);
}

$type_context = $this->codebase->getTypeContextAtPosition($file_path, $position);
try {
$type_context = $this->codebase->getTypeContextAtPosition($file_path, $position);

if (!$completion_data && !$type_context) {
error_log('completion not found at ' . $position->line . ':' . $position->character);
if (!$completion_data && !$type_context) {
error_log('completion not found at ' . $position->line . ':' . $position->character);

return new Success([]);
}
} catch(UnexpectedValueException $e) {
error_log('completion not found at ' . $position->line . ':' . $position->character.', Reason: '.$e->getMessage());
return new Success([]);
}


if ($completion_data) {
[$recent_type, $gap, $offset] = $completion_data;

Expand Down

0 comments on commit cb3cf88

Please sign in to comment.