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

Improved diagnostics #244

Closed
7 tasks done
bmewburn opened this issue Apr 22, 2017 · 10 comments
Closed
7 tasks done

Improved diagnostics #244

bmewburn opened this issue Apr 22, 2017 · 10 comments
Milestone

Comments

@bmewburn
Copy link
Owner

bmewburn commented Apr 22, 2017

Diagnostics are currently limited to explicit parse errors reported by bmewburn/php7parser. The diagnostics provider could be improved by providing diagnostics on:

@JapSeyz
Copy link

JapSeyz commented Dec 15, 2017

Is there anything we can do to help out?

@bmewburn
Copy link
Owner Author

bmewburn commented Dec 20, 2017

@JapSeyz thanks for the offer! You're welcome to create a PR for this or any other issue. I have been meaning to put together a contributing guideline with an overview on how it works. The diagnostics provider is pretty simple right now. It just traverses over the parse tree and creates diagnostics from the parse error nodes in the tree.

There is also 2 derived trees - a symbol (definitions) tree and a references tree. For unused variables and parameters a simple rule might even be that if there is only a single reference to a variable or parameter in a given scope then it is either unused or undefined (a reference is created for the definition/declaration too). I haven't given much thought to how this could all be structured in the diagnostics provider.

@MichalSchwarz
Copy link

Hi Guys . Do you think that implement it from scratch is the best solution? I see a insane lot of work ahead... What about find and use some existing static analysis tool? Is possible to connect some tool written eg. in PHP?

@bmewburn
Copy link
Owner Author

@MichalSchwarz, you're right it is a lot of work and there are probably other tools out there. The benefit of implementing from scratch is that the syntax tree can be reused. A separate lib would come with it's own parser etc which means more resources needed.

@mindplay-dk
Copy link

FWIW, most of the actual inspections in existing static analysis tools are not that complex - typically the framework is the complex part.

@bmewburn in #60:

I haven't done much work on this as I'm considering moving to a representation of the syntax tree that is easier to work with (ast instead of parse tree), plus there are improvements to the type inference to be made in cases where phpdoc and type hints are not available for function return type

I know just enough parser theory to break everything, so I think I'll stay away from this one.

I would like to help with the actual inspections, but if you're planning to change the code representation, it's probably premature to start working on those?

@bmewburn
Copy link
Owner Author

@mindplay-dk, correct. The syntax tree representation will be largely the same but I think it needs a transform applied to make accessing FQN and type info simpler.

@Snake231088
Copy link

Two ideas from IntelliJ that you might consider:

  • highlighting unused variables
  • highlighting undeclared variables

@Thijzer
Copy link

Thijzer commented Feb 26, 2019

Give me a sign if you need Guinea pig.

I'm a php developer on Arch Linux, most of my projects are Symfony based OO heavy, so a good working IDE is very important to me but I don't like to really to heavily on one tool "PhpStorm". I'm sure I can help if you can orchestrate something.

@altwohill
Copy link

Hi, I see that unused variables are listed as such when hovering over them, but there's nothing drawing me to it (no error shows for the line).
image

Is this on the roadmap for this ticket or should I create a new one?

@bmewburn
Copy link
Owner Author

bmewburn commented Nov 23, 2019

1.3 will add deprecated, undefined classes and methods/functions, stricter type checking for nullable and union types. Further diagnostics will be added in future releases.

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

No branches or pull requests

7 participants