-
Notifications
You must be signed in to change notification settings - Fork 185
Signature help #250
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
Signature help #250
Changes from 22 commits
ddf8274
f9240cd
6bca8df
67be71a
1e109a3
fdda97c
16c7560
3b4e0c3
a7c094e
8995611
8fbbf3d
d433ae4
75e5e24
6980fb5
b0f3952
1b68c73
96948c4
9e822fb
df0c9d4
412a884
549645b
1f20605
32b9984
d4d0c47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
function helpFunc1(int $count = 0) | ||
{ | ||
} | ||
|
||
helpFunc1() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
function helpFunc2(int $count = 0) | ||
{ | ||
} | ||
|
||
helpFunc2( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
class HelpClass1 | ||
{ | ||
public function method(string $param = "") | ||
{ | ||
} | ||
public function test() | ||
{ | ||
$this->method(); | ||
} | ||
} | ||
|
||
$a = new HelpClass1; | ||
$a->method(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
class HelpClass2 | ||
{ | ||
protected function method(string $param = "") | ||
{ | ||
} | ||
public function test() | ||
{ | ||
$this->method(1,1); | ||
} | ||
} | ||
$a = new HelpClass2; | ||
$a | ||
->method( | ||
1, | ||
array(), |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class HelpClass3 | ||
{ | ||
public static function method(string $param = "") | ||
{ | ||
} | ||
} | ||
|
||
HelpClass3::method() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class HelpClass4 | ||
{ | ||
public static function method(string $param = "") | ||
{ | ||
} | ||
} | ||
|
||
HelpClass4::method(1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
use PhpParser\PrettyPrinter\Standard as PrettyPrinter; | ||
use phpDocumentor\Reflection\{Types, Type, Fqsen, TypeResolver}; | ||
use LanguageServer\Protocol\SymbolInformation; | ||
use LanguageServer\Protocol\ParameterInformation; | ||
use LanguageServer\Index\ReadableIndex; | ||
|
||
class DefinitionResolver | ||
|
@@ -131,6 +132,18 @@ public function createDefinitionFromNode(Node $node, string $fqn = null): Defini | |
$def->type = $this->getTypeFromNode($node); | ||
$def->declarationLine = $this->getDeclarationLineFromNode($node); | ||
$def->documentation = $this->getDocumentationFromNode($node); | ||
$def->parameters = []; | ||
if ($node instanceof Node\FunctionLike) { | ||
foreach ($node->getParams() as $param) { | ||
if (!$param->getAttribute('parentNode')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @felixfbecker I could not figure out why those instances do not have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every node except the root node should have a parentNode |
||
$param->setAttribute('parentNode', $node); | ||
} | ||
$def->parameters[] = new ParameterInformation( | ||
$this->prettyPrinter->prettyPrint([$param]), | ||
$this->getDocumentationFromNode($param) | ||
); | ||
} | ||
} | ||
return $def; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,16 @@ class SignatureInformation | |
* @var ParameterInformation[]|null | ||
*/ | ||
public $parameters; | ||
|
||
/** | ||
* @param string $label The label of this signature. Will be shown in the UI. | ||
* @param string|null $documentation The human-readable doc-comment of this signature. | ||
* @param ParameterInformation[]|null $parameters The parameters of this signature. | ||
*/ | ||
public function __construct(string $label = null, string $documentation = null, array $parameters = []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default value for |
||
{ | ||
$this->label = $label; | ||
$this->documentation = $documentation; | ||
$this->parameters = $parameters; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
ParameterInformation[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want me to build the objects here? Won't that use more memory than plain strings, which are converted to ParameterInformation when needed?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand your code correctly this string array only contains the pretty-printed parameter node. That means you cannot construct the
documentation
property from it, which you need to read from the@param
tag. Of course as a new feature it is expected to use more memory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I currently populate only the label (using this string). I will add the documentation and construct
ParameterInformation
objects - of course that would mean an object for every parameter of every method / function in the project. I will test and let you know how it impacts memory usage.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixfbecker the impact was not significant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI we already keep
Hover
andSymbolInformation
in memory. I thought about changingDefinition
so that it contains just the data necessary to construct those and then build them from this, but I would prefer to first implement the features and then improve perf.If memory usage is too high the implementation would not save anything in
Definition
and load the document on demand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave out the docs first but lets use objects from the start on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is already done, and the docs are in place as well. I added a comment for you though -
Param
nodes do not have aparentNode
attribute - I could not fix it - the attribute was added inReferenceAdder
but then was not available at a later point.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixfbecker anything I can help with here?