Skip to content

Commit 474947c

Browse files
committed
Add gf and <C-W><C-F> keymaps for jumping to modules from import lines
1 parent 564a203 commit 474947c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

autoload/hdevtools.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ function! hdevtools#prepare_shutdown()
2424
endif
2525
endfunction
2626

27+
function! hdevtools#go_file(opencmd)
28+
" Get the import declaration under the cursor
29+
let l:module_name = matchstr(getline("."), '^import\s\+\(qualified\s\+\)\=\zs\(\w\|\.\)\+\ze')
30+
if l:module_name ==# ''
31+
call hdevtools#print_warning("Cursor not on a Haskell import declaration")
32+
return
33+
endif
34+
35+
let l:cmd = hdevtools#build_command('modulefile', shellescape(l:module_name))
36+
let l:output = system(l:cmd)
37+
38+
let l:lines = split(l:output, '\n')
39+
40+
if v:shell_error != 0
41+
for l:line in l:lines
42+
call hdevtools#print_error(l:line)
43+
endfor
44+
return
45+
endif
46+
47+
exe a:opencmd fnameescape(l:lines[0])
48+
endfunction
49+
2750
function! hdevtools#info(identifier)
2851
let l:identifier = a:identifier
2952

ftplugin/haskell/hdevtools.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ else
2626
let b:undo_ftplugin = ''
2727
endif
2828

29+
nnoremap <buffer> <silent> gf :call hdevtools#go_file("e")<CR>
30+
nnoremap <buffer> <silent> <C-W><C-F> :call hdevtools#go_file("sp")<CR>
31+
2932
command! -buffer -nargs=0 HdevtoolsType echo hdevtools#type()[1]
3033
command! -buffer -nargs=0 HdevtoolsClear call hdevtools#type_clear()
3134
command! -buffer -nargs=? HdevtoolsInfo call hdevtools#info(<q-args>)

0 commit comments

Comments
 (0)