1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Add lookup for builtin functions

This commit is contained in:
Matthew Brown 2019-07-18 23:30:44 -04:00
parent 5583ae842e
commit 8d63d5dc4e
3 changed files with 21 additions and 10 deletions

View File

@ -19,6 +19,7 @@ use function preg_match;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Analyzer\Statements\Block\ForeachAnalyzer;
use Psalm\Internal\Analyzer\TypeAnalyzer;
use Psalm\Internal\Codebase\CallMap;
use Psalm\Internal\Provider\ClassLikeStorageProvider;
use Psalm\Internal\Provider\FileProvider;
use Psalm\Internal\Provider\FileReferenceProvider;
@ -1195,11 +1196,11 @@ class Codebase
}
/**
* @param array{0: string} $argument_location
* @param string $function_symbol
*/
public function getSignatureInformation(array $argument_location) : ?\LanguageServerProtocol\SignatureInformation
public function getSignatureInformation(string $function_symbol) : ?\LanguageServerProtocol\SignatureInformation
{
list($function_symbol) = $argument_location;
$params = null;
if (strpos($function_symbol, '::') !== false) {
$declaring_method_id = $this->methods->getDeclaringMethodId($function_symbol);
@ -1213,11 +1214,21 @@ class Codebase
} else {
try {
$function_storage = $this->functions->getStorage(null, $function_symbol);
} catch (\Exception $exception) {
return null;
}
$params = $function_storage->params;
$params = $function_storage->params;
} catch (\Exception $exception) {
if (CallMap::inCallMap($function_symbol)) {
$callables = CallMap::getCallablesFromCallMap($function_symbol);
if (!$callables || !$callables[0]->params) {
return null;
}
$params = $callables[0]->params;
} else {
return null;
}
}
}
$signature_label = '(';

View File

@ -274,7 +274,7 @@ class TextDocument
return new Success(new \LanguageServerProtocol\SignatureHelp());
}
$signature_information = $this->codebase->getSignatureInformation($argument_location);
$signature_information = $this->codebase->getSignatureInformation($argument_location[0]);
if (!$signature_information) {
return new Success(new \LanguageServerProtocol\SignatureHelp());

View File

@ -329,7 +329,7 @@ class SymbolLookupTest extends \Psalm\Tests\TestCase
[new Position(10, 40), 'B\A::staticfoo', 0, 1],
#[new Position(12, 28), 'B\foo', 0, 1],
[new Position(14, 30), 'B\A::__construct', 0, 0],
#[new Position(16, 31), 'strlen', 0, 1],
[new Position(16, 31), 'strlen', 0, 1],
];
}
@ -390,7 +390,7 @@ class SymbolLookupTest extends \Psalm\Tests\TestCase
$this->assertSame($expected_symbol, $symbol);
$this->assertSame($expected_argument_number, $argument_number);
$symbol_information = $codebase->getSignatureInformation($reference_location);
$symbol_information = $codebase->getSignatureInformation($reference_location[0]);
if ($expected_param_count === null) {
$this->assertNull($symbol_information);