Skip to content

Commit bcab2b7

Browse files
committed
Merge remote-tracking branch 'origin/fix-detect_module'
2 parents e297f4b + 28f4e0c commit bcab2b7

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

after/ftplugin/haskell/ghcmod.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ let b:undo_ftplugin .= join(map([
6060
\ ], '"delcommand " . v:val'), ' | ')
6161
let b:undo_ftplugin .= ' | unlet b:did_ftplugin_ghcmod'
6262

63+
" Ensure syntax highlighting for ghcmod#detect_module()
64+
syntax sync fromstart
65+
6366
function! s:echo(msg)
6467
if !empty(a:msg)
6568
echo a:msg

autoload/ghcmod.vim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,15 @@ function! ghcmod#type_clear()"{{{
138138
endfunction"}}}
139139

140140
function! ghcmod#detect_module()"{{{
141-
let l:max_lineno = min([line('$'), 11])
142-
for l:lineno in range(1, l:max_lineno)
141+
let l:regex = '^\C\s*module\s\+\zs[A-Za-z0-9.]\+'
142+
for l:lineno in range(1, line('$'))
143143
let l:line = getline(l:lineno)
144-
let l:mod = matchstr(l:line, 'module \zs[A-Za-z0-9.]\+')
145-
if !empty(l:mod)
146-
return l:mod
144+
let l:pos = match(l:line, l:regex)
145+
if l:pos != -1
146+
let l:synname = synIDattr(synID(l:lineno, l:pos+1, 0), 'name')
147+
if l:synname !~# 'Comment'
148+
return matchstr(l:line, l:regex)
149+
endif
147150
endif
148151
let l:lineno += 1
149152
endfor

0 commit comments

Comments
 (0)