Skip to content
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

NodeDataProvider empty in LSP #3216

Closed
joehoyle opened this issue Apr 23, 2020 · 4 comments
Closed

NodeDataProvider empty in LSP #3216

joehoyle opened this issue Apr 23, 2020 · 4 comments

Comments

@joehoyle
Copy link
Contributor

joehoyle commented Apr 23, 2020

I have a custom plugin that makes use of the Psalm\Internal\Provider\NodeDataProvider for some custom return type logic via AfterFunctionCallAnalysisInterface.

As I understand it, afterFunctionCallAnalysis is passed an expression, where I'm looking at the type of the second param on a function call. That second param is of type PhpParser\Node\Name. afterFunctionCallAnalysis needs to provide return_type_candidate with a Union containing that type. However, the "type" I get from the FuncCall expression is the PhpParser type.

I had been using StatementsSource::getNodeTypeProvider::getType() which appears to be able to map a PhpParser expression or node name to a Psalm Type. This works well when running psalm from the command line.

However, when running via the LSP, it seems that the StatementsSource::getNodeTypeProvider->node_types is an empty SplObjectStorage object. Perhaps this is to do with how the file contents is passed to the LSP, and given (perhaps) that file is in memory rather than on-disk, then there's some different behavior where the current file does not appear to be tokenized (or something!).

Could anyone provide me some guidance on why the LSP behavior I'm seeing here is different from the Psalm CLI. Thanks!

@psalm-github-bot
Copy link

Hey @joehoyle, can you reproduce the issue on https://psalm.dev ?

@joehoyle
Copy link
Contributor Author

joehoyle commented Apr 23, 2020 via email

@muglug
Copy link
Collaborator

muglug commented Apr 24, 2020

@joehoyle I'd use the (more-recently-added) FunctionReturnTypeProviderInterface to give Psalm return type suggestions for functions. You should find it simpler to use!

@joehoyle
Copy link
Contributor Author

@muglug Thanks! I'll give that a go, will re-open if I see the same issue there.

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

No branches or pull requests

2 participants