Phpactor 2024.03.09

Last modified 2024/03/09 14:57

I have tagged Phpactor 2024.03.09.

The last Phpactor release was about 3 months ago. This release has a large number of improvements and bug fixes from around 9 individual contributors.

UTF-16 support

It turns out that the language server protocol expects everything to be in UTF-16. This was a problem because Phpactor rather expected everything to be in UTF-8. This problem happened when converting to or from an LSP position.

In LSP positions are provided as Position(line,character) where character is the character offset in code units. This corresponds neither to byte offset or to individual characters. For example the code unit for 😺 has 4 bytes which is 4 UTF-8 code units, but only 2 UTF-16 code units.

This should resolve long standing issues reported by users using multi-byte characters.

Contextual Class Completion

Phapctor now makes some effort to filter classes in the parameter position when completing. It’s far from perfect at the moment

contextual completion showing only instances of Widget

Above the ->widgets method accepts instances of Widget so now Phpactor will filter the results to only suggest those classes.

More work needs to be done on this feature however.

Phpactor is killing my CPU: Includes

An issue was raised which rather alarmingly claimed that Phapctor was eating up several CPUs at 100%. It happened on a legacy code base which used many includes and requires and the user(S) reported that a diagnostics pass couild take up to a minute.

Phpactor has long had some basic support for processing include statements and merging the outgoing frame into the scope where the include was called.

On testing this feature with an example (in Oscommerce) it took around 10 secconds, disabling the include processing from Phpactor reduced it to around 4 seconds. I also noticed that the include processor really didn’t seem to work. None of the expected variables were imported into the frame.

Rather than wasting lots of time trying to fix the include processing that presumably hasn’t worked for years I decided to remove it completely in the interests of performance.

Phpactor is killing my CPU: Diagnostics

The other Phpactor (haha) contributing to the performance issues the diagnostics engine spinning up too many processes and doing this very eagerly.

The language server “diagnostics engine” has been refactored a number of times since it was created. It turns out that providing non-blocking diagnostics from a number of sources (e.g. phpactor, phpstan, psalm. php-cs-fixer) is actually a complete pain in the bum.

The last time it was refactored it was made to be eager and it would optimistically perform the diagnostics as soon as a document update was received. Typically this resulted in faster feedback, but obviously it incldues potential waste as many runs would be invalidated if the text document had been updated in the time since they were started.

This time the behavior has changed again. Diagnostics will be triggered after the user has stopped typing (i.e. since we recieved an update) for a configurable amount of time (default 1 second). After that we launch all the linters in parallel.

In addition we now only process one file at a time and we should be better at not showing stale diagnsotics (in case you ever noticed diagnostics appearing for issues that have already been fixed).

Windows Compatibitliy Improvements

Phpactor has never, to my knowledge, worked with Windows. That is slowly changing thanks to the work of @MatmaRex who has made a large effort in the past month to get the tests passing on Windows.

At the point that the tests pass (if we get there) I’ll add a CI integration for Windows and, hopefully, some day, Phpactor will work natively on Windows.

Phpactor is on the VSCode Marketplace

@Zobo has done an amazing job on getting the VS-Code Extension on the visual-studio marketplace.

vscode marketplace

Hopefully this makes it easier for users to complain about Phpactor. Thanks Zobo.

Summary

These are just 4 of the 41 changes changes in the CHANGELOG. The past 3 months have been relatively busy.

The major pain point with Phpactor continues to be it’s static-analysis performance (although it is basically fine in most cases). I purchased a book to help provide me with some new insights into program analysis in general.

book principles of program analysis principles of program analysis

Unfortunately I have no formal math training, so it’s pretty hard going, but if I skip past the formulas there are lots of good ideas to explore.