Skip to content
Permalink
Browse files

Add lookup for builtin functions

  • Loading branch information...
muglug committed Jul 19, 2019
1 parent 5583ae8 commit 8d63d5dc4ea733b5c75c0e9aaaa94b63e1f28016
@@ -19,6 +19,7 @@
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 @@ public function getFunctionArgumentAtPosition(string $file_path, Position $posit
}
/**
* @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 @@ public function getSignatureInformation(array $argument_location) : ?\LanguageSe
} else {
try {
$function_storage = $this->functions->getStorage(null, $function_symbol);
$params = $function_storage->params;
} catch (\Exception $exception) {
return null;
}
if (CallMap::inCallMap($function_symbol)) {
$callables = CallMap::getCallablesFromCallMap($function_symbol);
if (!$callables || !$callables[0]->params) {
return null;
}
$params = $function_storage->params;
$params = $callables[0]->params;
} else {
return null;
}
}
}
$signature_label = '(';
@@ -274,7 +274,7 @@ public function signatureHelp(TextDocumentIdentifier $textDocument, Position $po
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());
@@ -329,7 +329,7 @@ public function providerGetSignatureHelp(): array
[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 @@ function foo(string $a) {
$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);

0 comments on commit 8d63d5d

Please sign in to comment.
You can’t perform that action at this time.