Php-language-server: variables - unused and undefined

Created on 9 May 2017  Â·  9Comments  Â·  Source: felixfbecker/php-language-server

_From @manwe-pl on May 9, 2017 13:27_

Hi. Thanks for the extension. Two ideas from IntelliJ that you might consider:

  • highlighting unused variables (declared but never used after that),
  • highlighting undeclared variables, that are used (like if(… = $foo) without $foo = …).

_Copied from original issue: felixfbecker/vscode-php-intellisense#120_

feature help wanted

Most helpful comment

This feature is the reason why i still use PhpStorm instead VSCode for PHP.

All 9 comments

  • highlighting unused namespaces

This feature is the reason why i still use PhpStorm instead VSCode for PHP.

Please don't +1 issues. It clutters the thread without adding value to the discussion and spams maintainers with notifications. Use GitHub reactions to upvote features.
image

highlighting undeclared variables, that are used (like if(… = $foo) without $foo = …).

This will have a small number of false positives for parameter references, which would become much smaller if type checking and possibly control flow analysis were introduced (E.g. $closure($arg, $outputReference); would warn about $outputReference being undeclared. Another example: $x would be undefined for if (cond()) { $x = 2; if(CONST) {return;} else {throw new Exception('message');} } call_function_using($x);).)

highlighting unused variables (declared but never used after that),

There's an open source plugin for a different project. That plugin performs unused variable detection, and only unused variable detection (Has some issues understanding references, loops and complex nested expressions right now, and is somewhat messy). It's a completely different AST format. An easy to implement (but slow) solution would be to convert the tolerant-php-parser AST to the other AST type that the mentioned plugin expects. A better solution would be to reimplement based on that design, targeting tolerant-php-parser. (The plugin is Apache licensed, the project the plugin is for is MIT licensed)

This feature (unused and undefined detection) is the reason why i still use PhpStorm instead VSCode for PHP.

Until this issue is closed, this can be worked around by running both felixfbecker/php-language-server and another language server with the desired diagnostics, and disabling any redundant/conflicting features such as syntax error detection.

Any news on this feature :) ?

@JonGarbayo if there were news they would be posted here. Please use the subscribe feature, no need for polling ;)

Sorry, it was just in case you forgot ;)

This feature won't be implemented unless someone submits a PR, so there is no need to remind me personally ;)

This feature is the reason why i still use PhpStorm instead VSCode for PHP.

https://github.com/sirbrillig/phpcs-variable-analysis

Was this page helpful?
0 / 5 - 0 ratings