Skip to content

Signature help #547

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

Merged
merged 13 commits into from
Dec 10, 2017
Merged

Signature help #547

merged 13 commits into from
Dec 10, 2017

Conversation

phil-nelson
Copy link
Contributor

@phil-nelson phil-nelson commented Dec 4, 2017

This is an alternative to the existing signature help PR, which I didn't realise existed when I initially did this work. Since it doesn't seem to quite be there, I thought I would raise this as I am keen to see signatureHelp be part of php-language-server.

I would have helped out with the work on the other branch if I knew it existed but I didn't, so this is an alternative implementation. I believe it has a few of benefits:

  • Works for constructors
  • Implements active signature
  • Gives more information/doc for each parameter

Here is an example of it in action:

signaturehelp

I am open to suggestions on how to better display the signature help (params/docs/anythign else)

@codecov
Copy link

codecov bot commented Dec 4, 2017

Codecov Report

Merging #547 into master will increase coverage by 1.49%.
The diff coverage is 99.21%.

@@             Coverage Diff              @@
##             master     #547      +/-   ##
============================================
+ Coverage     79.36%   80.86%   +1.49%     
- Complexity      836      877      +41     
============================================
  Files            56       61       +5     
  Lines          1900     2028     +128     
============================================
+ Hits           1508     1640     +132     
+ Misses          392      388       -4
Impacted Files Coverage Δ Complexity Δ
src/Definition.php 100% <ø> (ø) 6 <0> (ø) ⬇️
src/Protocol/ParameterInformation.php 100% <100%> (ø) 1 <1> (?)
src/DefinitionResolver.php 85.04% <100%> (+1.02%) 303 <0> (+1) ⬆️
src/Server/TextDocument.php 75.18% <100%> (+0.96%) 56 <1> (+1) ⬆️
src/Protocol/SignatureInformation.php 100% <100%> (ø) 1 <1> (?)
src/Protocol/SignatureHelp.php 100% <100%> (ø) 1 <1> (?)
src/LanguageServer.php 78.18% <100%> (+0.4%) 27 <0> (ø) ⬇️
src/SignatureInformationFactory.php 100% <100%> (ø) 10 <10> (?)
src/SignatureHelpProvider.php 98.66% <98.66%> (ø) 26 <26> (?)
... and 5 more

Copy link
Owner

@felixfbecker felixfbecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what the benefit of lazy-loading the signature help is? Hovers are kept in the index too. If we want to do static type analysis in the the future, we will need the signature to be stored in the index too.

: 0;

// Get information from the item being called to build the signature information
$calledDoc = $this->documentLoader->getOrLoad($def->symbolInformation->location->uri)->wait();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never use wait except in tests, it blocks the event loop. Make it a coroutine and yield the Promise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'm still getting my head around this event loop business. I've updated this to wrap this function in a coroutine.

++$i;
}
}
if (is_null($found)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use === null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

];
}

private function createSignatureHelp(array $info): SignatureHelp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to add constructors to SignatureHelp etc. so we don’t need this factory here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added constructors and utilised them (I actually found this style of OO with public members a bit strange but just copied the existing style). I still like to have this creator as otherwise we end up constructing lots of objects in the data providers and it becomes harder to maintain - if a constructor changed there would be a lot of rework.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the constructors directly - especially after your PR, you can get signature help for the constructor parameters, but you can't for the array hashes ;)
That's how it's done in all the other tests too.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason to make the members private and write getters and setters for them as they represent the JSON that gets sent over the wire (which only has public properties). They are generally dumb value objects that don't contain any complex state that needs to be kept private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, makes sense - updated now, thanks

@phil-nelson
Copy link
Contributor Author

@felixfbecker I have updated this PR to store signatureInformation in the index

@felixfbecker felixfbecker merged commit a40cf73 into felixfbecker:master Dec 10, 2017
@felixfbecker
Copy link
Owner

Awesome work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants