Commit Graph

7 Commits

Author SHA1 Message Date
Camille Dejoye
2c997ed781 Fix PHP smart brace hook for static method 2020-11-17 13:48:57 +01:00
Camille Dejoye
7afc8ac1cd improvement: preserve the cursor position
The idea was to be able to keep the cursor on the same position than
before an operation.
To solve this issue I first extract the position of the cursor, this
position is given relative to the argument list. It contains the number
of the argument and a column number relative to the start of the
argument.
This way it is possible to position the cursor later on and I hope it
should be pretty easy for any extension to adapt it if needed since it's
provided in the container dictionary.
2020-06-13 13:11:24 +02:00
Camille Dejoye
b0e60c9cd1 improvement: globally initialize the settings
The settings were initialize in an autoload which is not a good
practice.
So I initialize them in the plugin directly, this way there are
initialize only once when the plugin is loaded and they can be access
anywhere without having to worry about what the default value.
2020-06-13 12:21:03 +02:00
Camille Dejoye
eff4334368 fix: execution order of post hooks
The hooks were executed in the same order regarding of if they were pre
or post hooks.
This is actually not a correct behavior, let's assume we want to create
a hook responsible for keeping the position of the cursor between
operations:
The pre hook will have to extract the current position of the cursor and
therefore should be the first one to be executed, let's say we gave it a
priority 0.
The post hook will have to reposition the cursor after the
transformation and therefore should be the last one to be executed.
That's why we need to reverse the order of the post hooks.
2020-06-13 11:28:30 +02:00
Camille Dejoye
12ea40a812 fix: php smart brace with return type hint 2020-06-07 17:00:00 +02:00
Camille Dejoye
0fc75c596c improvement: generalize the hook system
It is still not possible to override an existing hook but with this
system users can create new hooks really simply without having to update
any configuration since they will be autodetected.

The only missing thins is the possibility to disable hook, therefore it
is the responsibility of each hook to provide a way to the user to use
it or not.
2020-06-07 15:26:06 +02:00
Camille Dejoye
18621cafcb improvement: add a filetype hook for PHP
This solve the issue #19
I put it there as an example, it might be better in its own repository.
This way a user will be able to choose to use it or not, which will
allow them to be able to provide their own implementation.

This attempt only deal with methods.
Functions are not part of the PSR-2.
Closures should always have the opening brace on the same line as the
closing parenthesis, this extension is not a CS fixer and therefore as
no reason to deal with them.
2020-06-07 10:58:28 +02:00