Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autoload/phpactor/input.vim
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function! phpactor#input#list(label, choices, multi, ResultHandler)
let choices = sort(keys(a:choices))

try
let strategy = phpactor#input#list#strategy()
let strategy = g:phpactorInputListStrategy
call call(strategy, [a:label, choices, a:multi, a:ResultHandler])
catch /E117/
redraw!
Expand Down
22 changes: 2 additions & 20 deletions autoload/phpactor/input/list.vim
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
function! phpactor#input#list#strategy()
" Hack to not use FZF in collections
" see https://github.com/phpactor/phpactor/pull/843
if g:_phpactorRpcActionIsCollection == v:true
return "phpactor#input#list#inputlist"
endif

if has_key(g:, 'phpactorInputListStrategy')
return g:phpactorInputListStrategy
endif

if has_key(g:, 'phpactorCustomInputListStrategy')
let g:phpactorInputListStrategy = g:phpactorCustomInputListStrategy
else
let g:phpactorInputListStrategy = s:auto_detect_strategy()
endif

return g:phpactorInputListStrategy
endfunction

function! phpactor#input#list#inputlist(label, choices, multi, ResultHandler)
echo a:label
let choice = inputlist(s:add_number_to_choices(a:choices))
Expand All @@ -29,6 +9,8 @@ function! phpactor#input#list#inputlist(label, choices, multi, ResultHandler)
call a:ResultHandler(a:choices[choice - 1])
endfunction

" expreimental: this stategy currently does not work when used in a
" non-terminal RPC step - https://github.com/phpactor/phpactor/issues/845
function! phpactor#input#list#fzf(label, choices, multi, ResultHandler)
let options = [
\ '--tiebreak=index',
Expand Down
36 changes: 3 additions & 33 deletions autoload/phpactor/quickfix.vim
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
function! phpactor#quickfix#strategy() abort
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed auto-detection - I would prefer everybody had the same base experience - and right now the native capability is more stable.

if (g:PhpactorQuickfixStrategy == v:null)
return s:auto_detect_strategy()
endif

let Strategy = g:PhpactorQuickfixStrategy

if type(function('tr')) == type(Strategy)
return Strategy
endif

if type('') != type(Strategy) || 0 == count(['fzf', 'vim'], Strategy)
echoerr 'Invalid strategy provided, check the value of "g:PhpactorQuickfixStrategy"'

return s:auto_detect_strategy()
endif

return function('phpactor#quickfix#'. Strategy)
endfunction

function! s:auto_detect_strategy()
let strategy = 'vim'

if exists("*fzf#complete")
let strategy = 'fzf'
endif

return function('phpactor#quickfix#'. strategy)
endfunction

function! phpactor#quickfix#vim(entries) abort
call setqflist(a:entries)
cw
endfunction

function! phpactor#quickfix#build(entries) abort
try
let Strategy = phpactor#quickfix#strategy()
call call(Strategy, [a:entries])
let strategy = g:phpactorQuickfixStrategy
call call(strategy, [a:entries])
catch /E117/
redraw!
echo 'The strategy "'. string(Strategy) .'" is unknown, check the value of "g:PhpactorQuickfixStrategy".'
echo 'The strategy "'. string(strategy) .'" is unknown, check the value of "g:phpactorQuickfixStrategy".'
endtry
endfunction

Expand Down
3 changes: 3 additions & 0 deletions couscous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ menu:
rpc:
text: RPC Protocol
relativeUrl: rpc.html
experimental-vim-plugin:
text: VIM plugin experimental
relativeUrl: vim-plugin/experimental.html
119 changes: 5 additions & 114 deletions doc/vim-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ your `.vimrc` to change the PHP binary:
let g:phpactorPhpBin = "/usr/bin/local/php7.0"
```


Configuration
-------------

Expand All @@ -174,32 +173,18 @@ The plugin has some configuration options:
let g:phpactorPhpBin = 'php'
let g:phpactorBranch = 'master'
let g:phpactorOmniAutoClassImport = v:true
let g:phpactorInputListStrategy = 'inputlist|fzf'
let g:phpactorQuickfixStrategy = 'vim|fzf|Funcref'

" Example of implementation with vim's inputlist() function
function! InputListCustomStrategy(label, choices, ResultHandler)
echo a:label
let choice = inputlist(s:add_number_to_choices(a:choices))

if (choice == 0)
throw "cancelled"
endif

call a:ResultHandler(a:choices[choice - 1])
endfunction

let g:phpactorCustomInputListStrategy = 'InputListCustomStrategy'
let g:phpactorInputListStrategy = 'phpactor#quickfix#vim'
let g:phpactorQuickfixStrategy = 'phpactor#input#list#inputlist'
```

- `g:phpactorPhpBin`: PHP executable to use.
- `g:phpactorBranch`: Phpactor branch (default is `master`, use `develop` for
bleeding edge).
- `g:phpactorOmniAutoClassImport`: Automatically import classes when
completing class names with OmniComplete.
- `g:phpactorInputListStrategy`: Select a strategy for the [Input
List](#input-list).
- `g:phpactorCustomInputListStrategy`: Specify your own strategy.
- `g:phpactorInputListStrategy`: Specify a callback to provide a custom input list (see [experimental](/vim-plugin/experimental.html').
- `g:phpactorQuickfixStrategy`: Specify a callback to provide a custom
quickfix implementation (see [experimental](/vim-plugin/experimental.html')

Extensions
----------
Expand Down Expand Up @@ -299,97 +284,3 @@ should see something like the following:
Method "execute":
[r]eplace_references, (f)ind_references, (g)enerate_method, g(o)to_definition:
```

Input List
----------

The input list is the window shown to let you choose an item among a list.

### Strategies

This plugin provides two strategy to handle input lists:

- `inputlist`: Vim's internal `inputlist()` function.
- `fzf`: Fuzzy finder using [Fzf](https://github.com/junegunn/fzf) plugin.

You can choose between those strategies by specifying the option
[g:phpactorInputListStrategy](#configuration).

### Input list strategies auto-detection

When no strategy is defined the plugin will default to the `fzf` strategy if
the [Fzf](https://github.com/junegunn/fzf) plugin is loaded or to `inputlist`
if it's not.

### FZF Multi-selection

Some refactorings will allow you to select multiple entires (for example
[override
method](https://phpactor.github.io/phpactor/refactorings.html#override-method).
Use `<tab>` to toggle selection and CTRL-A/CTRL-D to select all/select none.

See the
[Fzf](https://github.com/junegunn/fzf) documentation for more details.

Quickfix List
-------------

The quickfix list is used to show a list of positions in files and access them
quickly. Phpactor use it for example to show the result of `find references`.

### Strategies

This plugin provides two strategy to handle input lists:

- `vim`: Vim's basic quickfix.
- `fzf`: Use [fzf](#fzf) to show allow you to filter the results.

With the [fzf](#fzf) strategy you will still be able to get the result inside
the quickfix by selecting the elements you are interested in and pressing
`ctrl-q` to populate the quickfix with your selection and open it.

You can use your own strategy by providing a `Funcref` to the
`g:phpactorQuickfixStrategy` variable. When calling a strategy the list of
positions is given as a list that is directly usable by the function
`setqflist()`. Not all the keys are provided, depending on the context, so
you should always check if the information you want is really defined before
using it.

Extras
------

In order to get the best experience we suggest you install a few extra tools.

[fzf](https://github.com/junegunn/fzf)
--------------------------------------

This is actually not a vim plugin but a tool for the command-line.
It's shipped with a vim plugin that allows to use it inside Vim.

If you have it installed and properly configured for Vim then `Phpactor` will
use of it to provide enhance functionalities, for instance:

- [inputlist](#input-list)
- [quickfix](#quickfix-list)

[fzf.vim](https://github.com/junegunn/fzf.vim)
----------------------------------------------

This is the actual [fzf](https://github.com/junegunn/fzf) plugin for vim. It
requires you to have [fzf](https://github.com/junegunn/fzf) installed and
configured.

This plugin will allow us to use improved functionalities inside Vim. If you
want to enjoy the full possibilities of both `fzf` and `Phpactor` we strongly
recommand you to install it!

[bat](https://github.com/sharkdp/bat)
---

This is also a tool for the command-line and not a Vim plugin. It's meant to be
used instead of the command `cat` and bring a lot to the table. It can be use
as a powerful substitute for `cat` providing syntax highlighting and git
integration, among other things.

It's used by default, among other possible tools, by `fzf` to print the preview
window. Allowing you to have a preview of your files with syntaxic coloration!
49 changes: 49 additions & 0 deletions doc/vim-plugin/experimental.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Experimental
============

FZF and BAT
-----------

Experimental functionality with FZF and BAT depends on:

- [fzf](https://github.com/junegunn/fzf)
- [bat](https://github.com/sharkdp/bat)

In addition FZF support requires the FZF VIM plugin:

[fzf.vim](https://github.com/junegunn/fzf.vim)

### FZF Choice Selection

Some refactorings will allow you to select multiple entires (for example
[override
method](https://phpactor.github.io/phpactor/refactorings.html#override-method).

FZF provides a fuzzy search interface and the possiblity to select multiple
entries at once.

Use `<tab>` to toggle selection and CTRL-A/CTRL-D to select all/select none.

See the [Fzf](https://github.com/junegunn/fzf) documentation for more details.

Enable this feature by configuring FZF as the `inputlist` strategy in your
`.vimrc':

```
let g:phpactorInputListStrategy = 'phpactor#input#list#fzf'
```

### FZF Qucikfix with BAT preview

The VIM quickfix list is used to navigate through a set of references (where a
reference is a file / character position).

The FZF strategy provides a layer on top this to allow you to efficiently
filter, preview and select only those entries you want to navigate to to the
quickfix list.

Enable it as follows:

```
let g:phpactorQuickfixStrategy = 'phpactor#quickfix#fzf'
```
14 changes: 6 additions & 8 deletions plugin/phpactor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ let g:phpactorInitialCwd = getcwd()
let g:phpactorCompleteLabelTruncateLength=50
let g:_phpactorCompletionMeta = {}

" hack to avoid calling fzf strategy when using a collection
" see: https://github.com/phpactor/phpactor/pull/843
let g:_phpactorRpcActionIsCollection = v:false

if !exists('g:phpactorPhpBin')
let g:phpactorPhpBin = 'php'
endif
Expand All @@ -37,8 +33,12 @@ if !exists('g:phpactorCompletionIgnoreCase')
let g:phpactorCompletionIgnoreCase = 1
endif

if !exists('g:PhpactorQuickfixStrategy')
let g:PhpactorQuickfixStrategy = v:null
if !exists('g:phpactorQuickfixStrategy')
let g:phpactorQuickfixStrategy = 'phpactor#quickfix#vim'
endif

if !exists('g:phpactorInputListStrategy')
let g:phpactorInputListStrategy = 'phpactor#input#list#inputlist'
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved these configurations to the main phpactor.vim so all configs are in the same place, and made them more explicitly callbacks.

endif

if g:phpactorOmniAutoClassImport == v:true
Expand Down Expand Up @@ -546,9 +546,7 @@ function! phpactor#_rpc_dispatch(actionName, parameters)
" >> collection
if a:actionName == "collection"
for action in a:parameters["actions"]
let g:_phpactorRpcActionIsCollection = v:true
let result = phpactor#_rpc_dispatch(action["name"], action["parameters"])
let g:_phpactorRpcActionIsCollection = v:false

if !empty(result)
return result
Expand Down