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

Add bindings for the command 'findsymbol' #17

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
41 changes: 38 additions & 3 deletions autoload/hdevtools.vim
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function! hdevtools#info(identifier)
endif

" Get the identifier under the cursor
let l:identifier = s:extract_identifier(getline("."), col("."))
let l:identifier = hdevtools#extract_identifier(getline("."), col("."))
endif

if l:identifier ==# ''
Expand Down Expand Up @@ -120,7 +120,42 @@ function! hdevtools#info(identifier)
highlight link HdevtoolsInfoLink Underlined
endfunction

function! s:extract_identifier(line_text, col)
function! hdevtools#findsymbol(identifier, srcFiles)
let l:identifier = a:identifier

" No identifier argument given, probably called from a keyboard shortcut
if l:identifier ==# ''
" Get the identifier under the cursor
let l:identifier = hdevtools#extract_identifier(getline("."), col("."))
endif

if l:identifier ==# ''
echo '-- No Identifier Under Cursor'
return []
endif

let l:srcParam = ''
for l:srcFile in a:srcFiles
let l:srcParam .= ' ' . shellescape(l:srcFile)
endfor

let l:cmd = hdevtools#build_command('findsymbol', shellescape(l:identifier) . ' ' . l:srcParam)
let l:output = system(l:cmd)
let l:lines = split(l:output, '\n')

" Check if the call to hdevtools info succeeded
if v:shell_error != 0
for l:line in l:lines
call hdevtools#print_error(l:line)
endfor
else
return l:lines
endif

return []
endfunction

function! hdevtools#extract_identifier(line_text, col)
if a:col > len(a:line_text)
return ''
endif
Expand Down Expand Up @@ -238,7 +273,7 @@ function! hdevtools#test_extract_identifier()
let l:start_index = match(l:test, '#') + 1
let l:end_index = match(l:test, '\%>' . l:start_index . 'c#') - 1
for l:i in range(l:start_index, l:end_index)
let l:result = s:extract_identifier(l:input, l:i)
let l:result = hdevtools#extract_identifier(l:input, l:i)
if l:expected !=# l:result
call hdevtools#print_error("TEST FAILED expected: (" . l:expected . ") got: (" . l:result . ") for column " . l:i . " of: " . l:input)
endif
Expand Down
4 changes: 3 additions & 1 deletion ftplugin/haskell/hdevtools.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ nnoremap <buffer> <silent> <C-W><C-F> :call hdevtools#go_file("sp")<CR>
command! -buffer -nargs=0 HdevtoolsType echo hdevtools#type()[1]
command! -buffer -nargs=0 HdevtoolsClear call hdevtools#type_clear()
command! -buffer -nargs=? HdevtoolsInfo call hdevtools#info(<q-args>)
command! -buffer -nargs=1 HdevtoolsFindsymbol call hdevtools#findsymbol(<q-args>, [])

let b:undo_ftplugin .= join(map([
\ 'HdevtoolsType',
\ 'HdevtoolsClear',
\ 'HdevtoolsInfo'
\ 'HdevtoolsInfo',
\ 'HdevtoolsFindsymbol'
\ ], '"delcommand " . v:val'), ' | ')
let b:undo_ftplugin .= ' | unlet b:did_ftplugin_hdevtools'