felixfbecker / php-language-server

PHP Implementation of the VS Code Language Server Protocol 🆚↔🖥
ISC License
1.15k stars 185 forks source link

variables - unused and undefined #374

Open felixfbecker opened 7 years ago

felixfbecker commented 7 years ago

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

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

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

str commented 7 years ago
Suver1 commented 6 years ago

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

felixfbecker commented 6 years ago

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

TysonAndre commented 6 years ago

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.

JonGarbayo commented 6 years ago

Any news on this feature :) ?

felixfbecker commented 6 years ago

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

JonGarbayo commented 6 years ago

Sorry, it was just in case you forgot ;)

felixfbecker commented 6 years ago

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

oscar-gardiazabal commented 5 years ago

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

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