Skip to content
Permalink
Browse files

Only add newlines to function signature on hover (#1834)

Most editors do not render the newlines for autocompletions which makes
things look worse.
  • Loading branch information...
iluuu1994 authored and muglug committed Jun 22, 2019
1 parent caca3e5 commit 78588ced164edeadcd442b4bc4c8e76d5a6123dd
Showing with 14 additions and 7 deletions.
  1. +2 −2 src/Psalm/Codebase.php
  2. +12 −5 src/Psalm/Storage/FunctionLikeStorage.php
@@ -941,7 +941,7 @@ public function getSymbolInformation(string $file_path, string $symbol)
$storage = $this->methods->getStorage($declaring_method_id);
return '<?php ' . $storage;
return '<?php ' . $storage->getSignature(true);
}
list(, $symbol_name) = explode('::', $symbol);
@@ -974,7 +974,7 @@ public function getSymbolInformation(string $file_path, string $symbol)
if (isset($file_storage->functions[$function_id])) {
$function_storage = $file_storage->functions[$function_id];
return '<?php ' . $function_storage;
return '<?php ' . $function_storage->getSignature(true);
}
return null;
@@ -171,15 +171,22 @@ class FunctionLikeStorage
public function __toString()
{
$symbol_text = 'function ' . $this->cased_name . '(' . (!empty($this->params) ? PHP_EOL : '') . implode(
',' . PHP_EOL,
return $this->getSignature(false);
}
public function getSignature(bool $allow_newlines = false): string
{
$newlines = $allow_newlines && !empty($this->params);
$symbol_text = 'function ' . $this->cased_name . '(' . ($newlines ? PHP_EOL : '') . implode(
',' . ($newlines ? PHP_EOL : ' '),
array_map(
function (FunctionLikeParameter $param) : string {
return ' ' . ($param->type ?: 'mixed') . ' $' . $param->name;
function (FunctionLikeParameter $param) use ($newlines) : string {
return ($newlines ? ' ' : '') . ($param->type ?: 'mixed') . ' $' . $param->name;
},
$this->params
)
) . (!empty($this->params) ? PHP_EOL : '') . ') : ' . ($this->return_type ?: 'mixed');
) . ($newlines ? PHP_EOL : '') . ') : ' . ($this->return_type ?: 'mixed');
if (!$this instanceof MethodStorage) {
return $symbol_text;

0 comments on commit 78588ce

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