Skip to content

Commit 6d94615

Browse files
committed
Merge pull request #14 from ajnsit/master
Support for ghcmod's info command
2 parents 25b3502 + e7f2006 commit 6d94615

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

after/ftplugin/haskell/ghcmod.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ else
3131
endif
3232

3333
command! -buffer -nargs=0 GhcModType echo ghcmod#type()[1]
34+
command! -buffer -nargs=0 GhcModInfo echo ghcmod#info()
3435
command! -buffer -nargs=0 GhcModTypeClear call ghcmod#type_clear()
3536
command! -buffer -nargs=0 GhcModCheck call s:make('check')
3637
command! -buffer -nargs=0 GhcModLint call s:make('lint')
@@ -40,6 +41,7 @@ command! -buffer -nargs=0 GhcModCheckAndLintAsync call s:check_and_lint_async()
4041
command! -buffer -nargs=0 GhcModExpand call setqflist(ghcmod#expand()) | cwindow
4142
let b:undo_ftplugin .= join(map([
4243
\ 'GhcModType',
44+
\ 'GhcModInfo',
4345
\ 'GhcModTypeClear',
4446
\ 'GhcModCheck',
4547
\ 'GhcModLint',

autoload/ghcmod.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,35 @@ function! ghcmod#clear_highlight()"{{{
4848
endif
4949
endfunction"}}}
5050

51+
" Return the current haskell identifier
52+
function! ghcmod#getHaskellIdentifier()"{{{
53+
let c = col ('.')-1
54+
let l = line('.')
55+
let ll = getline(l)
56+
let ll1 = strpart(ll,0,c)
57+
let ll1 = matchstr(ll1,"[a-zA-Z0-9_'.]*$")
58+
let ll2 = strpart(ll,c,strlen(ll)-c+1)
59+
let ll2 = matchstr(ll2,"^[a-zA-Z0-9_'.]*")
60+
return ll1.ll2
61+
endfunction"}}}
62+
63+
function! ghcmod#info()"{{{
64+
if &l:modified
65+
call ghcmod#print_warning('ghcmod#info: the buffer has been modified but not written')
66+
endif
67+
let l:fexp = ghcmod#getHaskellIdentifier()
68+
let l:file = expand('%:p')
69+
if l:file ==# ''
70+
call ghcmod#print_warning("current version of ghcmod.vim doesn't support running on an unnamed buffer.")
71+
return ''
72+
endif
73+
let l:mod = ghcmod#detect_module()
74+
let l:cmd = ghcmod#build_command(['info', l:file, l:mod, l:fexp])
75+
let l:output = s:system(l:cmd)
76+
77+
return l:output
78+
endfunction"}}}
79+
5180
function! ghcmod#type()"{{{
5281
if &l:modified
5382
call ghcmod#print_warning('ghcmod#type: the buffer has been modified but not written')

doc/ghcmod.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ License |ghcmod-license|
1616
FEATURES *ghcmod-features*
1717

1818
- Displaying the type of sub-expressions (ghc-mod type)
19+
- Displaying the info for identifiers (ghc-mod info)
1920
- Displaying error/warning messages and their locations (ghc-mod check and
2021
ghc-mod lint)
2122
- Displaying the expansion of splices (ghc-mod expand)
@@ -47,6 +48,9 @@ If you'd like to give GHC options, set |g:ghcmod_ghc_options|.
4748
Sub-expressions are highlighted as |hl-Search| by default. You can
4849
customize it by setting |g:ghcmod_type_highlight|.
4950

51+
:GhcModInfo *:GhcModInfo*
52+
Information about the identifier under the cursor is echoed.
53+
5054
:GhcModTypeClear *:GhcModTypeClear*
5155
Clear the highlight created by |:GhcModType|.
5256

0 commit comments

Comments
 (0)