Skip to content
Merged
163 changes: 108 additions & 55 deletions autoload/phpactor.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""
" @section Introduction, intro
" @library
" @order intro config completion commands mappings
"
" Phpactor is a auto-completion, refactoring and code-navigation tool for PHP.
Expand Down Expand Up @@ -187,41 +186,82 @@ function! phpactor#ImportMissingClasses()
call phpactor#rpc("import_missing_classes", {"source": phpactor#_source(), "path": expand('%:p')})
endfunction

function! phpactor#_GotoDefinitionTarget(target)
""
" @default target=`edit`
" @default mods=''
"
" Goto the definition of the symbol under the cursor.
" Open the definition in the [target] window, see @section(window-target) for
" the list of possible targets.
" [mods] is a string containing |<mods>| values separated by a space.
"
" Examples:
" >
" " Opens in the current buffer
" call phpactor#GotoDefinition()
"
" " Opens in a vertical split opened on the right side
" call phpactor#GotoDefinition('split', 'vertical botright')
"
" " Opens in a new tab
" call phpactor#GotoDefinition('tabnew')
" <
function! phpactor#GotoDefinition(...)
let target = !empty(a:0 ? a:1 : '') ? a:1 : 'edit'
let mods = a:0 > 1 ? a:2 : ''

call phpactor#rpc("goto_definition", {
\"offset": phpactor#_offset(),
\"source": phpactor#_source(),
\"path": expand('%:p'),
\"target": a:target,
\'language': &ft})
\ "offset": phpactor#_offset(),
\ "source": phpactor#_source(),
\ "path": expand('%:p'),
\ 'language': &ft,
\ }, {
\ "target": target,
\ "mods": mods,
\ })
endfunction
function! phpactor#GotoDefinition()
call phpactor#_GotoDefinitionTarget('focused_window')
endfunction
function! phpactor#GotoImplementations()

""
" @usage [target] [mods]
"
" Same as @function(phpactor#GotoDefinition) but goto the implementation of
" the symbol under the cursor.
"
" If there is more than one result the quickfix strategy will be used and [target]
" will be ignored, see @setting(g:phpactorQuickfixStrategy).
function! phpactor#GotoImplementations(...)
let target = !empty(a:0 ? a:1 : '') ? a:1 : 'edit'
let mods = a:0 > 1 ? a:2 : ''

call phpactor#rpc("goto_implementation", {
\"offset": phpactor#_offset(),
\"source": phpactor#_source(),
\"path": expand('%:p'),
\"target": 'focused_window',
\'language': &ft})
endfunction
function! phpactor#GotoDefinitionVsplit()
call phpactor#_GotoDefinitionTarget('vsplit')
endfunction
function! phpactor#GotoDefinitionHsplit()
call phpactor#_GotoDefinitionTarget('hsplit')
endfunction
function! phpactor#GotoDefinitionTab()
call phpactor#_GotoDefinitionTarget('new_tab')
\ "offset": phpactor#_offset(),
\ "source": phpactor#_source(),
\ "path": expand('%:p'),
\ 'language': &ft,
\ }, {
\ "target": target,
\ "mods": mods,
\ })
endfunction

function! phpactor#GotoType()
""
" @usage [target] [mods]
"
" Same as @function(phpactor#GotoDefinition) but goto the type of
" the symbol under the cursor.
function! phpactor#GotoType(...)
let target = !empty(a:0 ? a:1 : '') ? a:1 : 'edit'
let mods = a:0 > 1 ? a:2 : ''

call phpactor#rpc('goto_type', {
\'offset': phpactor#_offset(),
\'source': phpactor#_source(),
\'path': expand('%:p'),
\'language': &filetype})
\ 'offset': phpactor#_offset(),
\ 'source': phpactor#_source(),
\ 'path': expand('%:p'),
\ 'language': &ft,
\ }, {
\ "target": target,
\ "mods": mods,
\ })
endfunction

function! phpactor#Hover()
Expand Down Expand Up @@ -474,7 +514,7 @@ endfunction
" RPC -->-->-->-->-->--
"""""""""""""""""""""""

function! phpactor#rpc(action, arguments)
function! phpactor#rpc(action, arguments, ...)
" Remove any existing output in the message window
execute ':redraw'

Expand All @@ -496,7 +536,7 @@ function! phpactor#rpc(action, arguments)
endtry

let actionName = response['action']
let parameters = response['parameters']
let parameters = extend(copy(response['parameters']), a:0 ? a:1 : {})

let response = phpactor#_rpc_dispatch(actionName, parameters)

Expand Down Expand Up @@ -567,12 +607,13 @@ function! phpactor#_rpc_dispatch(actionName, parameters)

call s:openFileInSelectedTarget(
\ a:parameters["path"],
\ a:parameters["target"],
\ get(a:parameters, 'target'),
\ get(a:parameters, 'mods'),
\ get(a:parameters, "use_open_window", g:phpactorUseOpenWindows),
\ a:parameters["force_reload"]
\ )

if a:parameters["target"] == 'focused_window'
if a:parameters["target"] == 'edit'
let changedFileOrWindow = !s:isOpenInCurrentWindow(a:parameters["path"])
endif

Expand Down Expand Up @@ -698,7 +739,31 @@ function! phpactor#_rpc_dispatch(actionName, parameters)
throw "Do not know how to handle action '" . a:actionName . "'"
endfunction

function! s:openFileInSelectedTarget(filePath, target, useOpenWindow, forceReload)
""
" @section Window targets, window-targets
" @parentsection commands
"
" Phpactor provide a few window targets to use with some commands.
" See @command(PhpactorGotoDefinition) for an example of how to use them.
"
" Possible values are:
" * `e`, `edit`, `ex`
" * `new`, `vne`, `vnew`
" * `sp`, `split`, `vs`, `vsplit`
" * `vie`, `view`, `sv`, `sview`, `splitview`
" * `tabe`, `tabedit`, `tabnew`

function! phpactor#_window_targets() abort
return [
\ 'e', 'edit', 'ex',
\ 'new', 'vne', 'vnew',
\ 'sp', 'split', 'vs', 'vsplit',
\ 'vie', 'view', 'sv', 'sview', 'splitview',
\ 'tabe', 'tabedit', 'tabnew',
\ ]
endfunction

function! s:openFileInSelectedTarget(filePath, target, mods, useOpenWindow, forceReload)
let l:bufferNumber = bufnr(a:filePath . '$')

if v:true == a:useOpenWindow && -1 != l:bufferNumber
Expand All @@ -713,28 +778,16 @@ function! s:openFileInSelectedTarget(filePath, target, useOpenWindow, forceReloa
endif
endif

if a:target ==# 'focused_window'
call phpactor#_switchToBufferOrEdit(a:filePath)
if v:true == a:forceReload
exec 'e!'
endif
return
endif

if a:target ==# 'vsplit'
exec ':vsplit ' . a:filePath
return
endif

if a:target ==# 'hsplit'
exec ':split ' . a:filePath
return
if -1 == index(phpactor#_window_targets(), a:target)
echohl WarningMsg
echomsg printf('Error executing: %s %s %s', a:mods, a:target, a:filePath)
echomsg printf('Invalid target: %s', a:target)
echomsg printf('Valid targets are: %s', join(phpactor#_window_targets(), ', '))
echohl None
return
endif

if a:target ==# 'new_tab'
exec ':tabnew ' . a:filePath
return
endif
execute printf('%s %s %s', a:mods, a:target, a:filePath)
Comment thread
camilledejoye marked this conversation as resolved.
Resolved
endfunction

function! phpactor#_rpc_dispatch_input_handler(Next, parameters, parameterName, result)
Expand Down
72 changes: 55 additions & 17 deletions doc/phpactor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONTENTS *phpactor-contents*
2. Configuration...........................................|phpactor-config|
3. Completion..........................................|phpactor-completion|
4. Commands..............................................|phpactor-commands|
1. Window targets..............................|phpactor-window-targets|
5. Mappings..............................................|phpactor-mappings|

==============================================================================
Expand Down Expand Up @@ -175,25 +176,68 @@ COMMANDS *phpactor-commands*
:PhpactorClassNew *:PhpactorClassNew*
Create a new class. You will be offered a choice of templates.

:PhpactorGotoDefinition *:PhpactorGotoDefinition*
Goto the definition of the class, method or function under the cursor. Open
the definition in the current window.
:PhpactorGotoDefinition [target] *:PhpactorGotoDefinition*
[target] is `edit` if omitted.

Goto the definition of the symbol under the cursor. Opens in the [target]
window, see |phpactor-window-target| for the list of possible targets.
|<mods>| can be provided to the command to change how the window will be
opened.

Examples:
>
" Opens in the current buffer
PhpactorGotoDefinition

" Opens in a vertical split opened on the right side
botright PhpactorGotoDefinition vsplit
vertical botright PhpactorGotoDefinition split

" Opens in a new tab
PhpactorGotoDefinition tabnew
<

:PhpactorGotoDefinitionVsplit *:PhpactorGotoDefinitionVsplit*
deprecated, use |:PhpactorGotoDefinition| instead

As with |:PhpactorGotoDefinition| but open in a vertical split.

:PhpactorGotoDefinitionHsplit *:PhpactorGotoDefinitionHsplit*
As with |:PhpactorGotoDefinition| but open in a horizontal split.
deprecated, use |:PhpactorGotoDefinition| instead

As with |:PhpactorGotoDefinition| but open in an horizontal split.

:PhpactorGotoDefinitionTab *:PhpactorGotoDefinitionTab*
As with |:PhpactorGotoDefinition| but open in a new tab
deprecated, use |:PhpactorGotoDefinition| instead

As with |:PhpactorGotoDefinition| but open in a new tab.

:PhpactorGotoType [target] *:PhpactorGotoType*

Same as |:PhpactorGotoDefinition| but goto the type of the symbol under the
cursor.

:PhpactorGotoImplementations [target] *:PhpactorGotoImplementations*

Same as |:PhpactorGotoDefinition| but goto the implmentation of the symbol
under the cursor.

If there is more than one result the quickfix strategy will be used and
[target] will be ignored, see |g:phpactorQuickfixStrategy|.

==============================================================================
WINDOW TARGETS *phpactor-window-targets*


:PhpactorGotoType *:PhpactorGotoType*
Goto type (class) of the symbol under the cursor.
Phpactor provide a few window targets to use with some commands. See
|:PhpactorGotoDefinition| for an example of how to use them.

:PhpactorGotoImplementations *:PhpactorGotoImplementations*
Load all implementations of the class under the cursor into the quick-fix
list.
Possible values are:
* `e`, `edit`, `ex`
* `new`, `vne`, `vnew`
* `sp`, `split`, `vs`, `vsplit`
* `vie`, `view`, `sv`, `sview`, `splitview`
* `tabe`, `tabedit`, `tabnew`

==============================================================================
MAPPINGS *phpactor-mappings*
Expand All @@ -211,13 +255,7 @@ are available for you to copy:
au FileType php nmap <buffer> <Leader>mm :PhpactorContextMenu<CR>
au FileType php nmap <buffer> <Leader>nn :PhpactorNavigate<CR>
au FileType php,cucumber nmap <buffer> <Leader>o
\ :PhpactorGotoDefinition<CR>
au FileType php,cucumber nmap <buffer> <Leader>Oh
\ :PhpactorGotoDefinitionHsplit<CR>
au FileType php,cucumber nmap <buffer> <Leader>Ov
\ :PhpactorGotoDefinitionVsplit<CR>
au FileType php,cucumber nmap <buffer> <Leader>Ot
\ :PhpactorGotoDefinitionTab<CR>
\ :PhpactorGotoDefinition edit<CR>
au FileType php nmap <buffer> <Leader>K :PhpactorHover<CR>
au FileType php nmap <buffer> <Leader>tt :PhpactorTransform<CR>
au FileType php nmap <buffer> <Leader>cc :PhpactorClassNew<CR>
Expand Down
8 changes: 1 addition & 7 deletions ftplugin/php/mappings.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
" au FileType php nmap <buffer> <Leader>mm :PhpactorContextMenu<CR>
" au FileType php nmap <buffer> <Leader>nn :PhpactorNavigate<CR>
" au FileType php,cucumber nmap <buffer> <Leader>o
" \ :PhpactorGotoDefinition<CR>
" au FileType php,cucumber nmap <buffer> <Leader>Oh
" \ :PhpactorGotoDefinitionHsplit<CR>
" au FileType php,cucumber nmap <buffer> <Leader>Ov
" \ :PhpactorGotoDefinitionVsplit<CR>
" au FileType php,cucumber nmap <buffer> <Leader>Ot
" \ :PhpactorGotoDefinitionTab<CR>
" \ :PhpactorGotoDefinition edit<CR>
" au FileType php nmap <buffer> <Leader>K :PhpactorHover<CR>
" au FileType php nmap <buffer> <Leader>tt :PhpactorTransform<CR>
" au FileType php nmap <buffer> <Leader>cc :PhpactorClassNew<CR>
Expand Down
Loading