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

Explore language server compatibility #521

Closed
muglug opened this issue Feb 17, 2018 · 3 comments

Comments

@muglug
Copy link
Member

commented Feb 17, 2018

This is a v3 feature, may never happen. But it'd be cool.

@muglug muglug added this to the Server mode milestone Feb 17, 2018

@TysonAndre

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2018

I think that using a PHP wrapper of psalm (That invokes ./psalm manually via system()/proc_open()), it would be feasible for projects that have a working autoloader (E.g. the composer autoloader for src/)

  • The wrapper would need virtually no knowledge of psalm's internals (Except maybe to avoid unnecessarily starting psalm for a change to an irrelevant file)

However, two (or one) CLI options would have to be added, and there would need to be some work on writing a wrapper:

  • --analyze-file path/to/file1.php [--analyze-file path/to/file2.php]. A CLI option that would limit <projectFiles> to the specified file names, excluding other files and directories.
    (Psalm should ignore files that weren't in the original projectFiles files or directories, e.g. vendor, .txt files, etc)

  • --override-file-contents {"path/to/file1.php":"raw_contents"}


E.g. as an experiment:

     <projectFiles>
-        <directory name="src" />
-        <directory name="tests" />
-        <directory name="examples" />
-        <ignoreFiles>
-            <file name="src/Psalm/CallMap.php" />
-            <directory name="src/Psalm/Stubs" />
-            <directory name="tests/stubs" />
-        </ignoreFiles>
+       <file name="src/Psalm/CodeLocation.php" />
     </projectFiles>

Command used: ./psalm src/Psalm/CodeLocation.php (I haven't looked into why I had to pass CodeLocation twice)

Time needed to analyze src/Psalm/CodeLocation with a modified psalm invocation and CLI command: 0.20 seconds (That can be reduced to 0.15 with igbinary)
Time needed for a full psalm analysis of psalm itself: 5.23 seconds

  • Hopefully, even if analyzing a much larger project that takes minutes to analyze, analyzing a single file (or 3 files) would still take around 0.20 seconds)

php-language-server can be used as a base (Or this project forked from php-language-server to focus on linting)

didOpen/didChange/didClose/didChangedWatchedFiles could be used as a base.

Aside: If psalm takes 0.20 seconds to analyze a small set of files (or even 1 second), it may receive events faster than it can respond. https://github.com/phan/phan/blob/df577b0699869df888d33c7d18d1f451d8264378/src/Phan/LanguageServer/LanguageServer.php#L140-L183 (Separate events for 'message' and for 'readMessageGroup' are one way to mitigate that).

@muglug

This comment has been minimized.

Copy link
Member Author

commented Feb 18, 2018

This is what I have at the moment: https://github.com/vimeo/psalm/compare/server

Running ./psalm --server puts it into a mode where you can query node types via telnet. Shouldn't be too much work to have it spit out errors there.

@muglug

This comment has been minimized.

Copy link
Member Author

commented Feb 18, 2018

After banging my head against many walls, that branch has something that works with LSP, thanks in no small part to Phan's version of Felix's code. Very far to go though.

@muglug muglug removed this from the Server mode milestone Feb 20, 2018

@muglug muglug moved this from To Do to In progress in Language Server Protocol support Feb 20, 2018

@muglug muglug added the enhancement label Mar 2, 2018

@muglug muglug closed this in #1006 Oct 17, 2018

Language Server Protocol support automation moved this from In progress to Done Oct 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2 participants
You can’t perform that action at this time.