Skip to content

Commit 51999e8

Browse files
authored
Add 'intero' filetype, use for syntax highlighting (parsonsmatt#135)
* Add 'intero' filetype, use for syntax highlighting * Add some comments * Ignore haskell syntax matches in the prompt * Rudimentary highlighting for GHC output * Highlight suggestions from GHC
1 parent 33f7ca9 commit 51999e8

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

autoload/intero/process.vim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ function! s:start_buffer(height) abort
188188
set bufhidden=hide
189189
set noswapfile
190190
set hidden
191+
set filetype=intero
191192
let l:buffer_id = bufnr('%')
192193
let g:intero_job_id = b:terminal_job_id
193194
quit
@@ -196,10 +197,6 @@ function! s:start_buffer(height) abort
196197
endfunction
197198

198199
function! s:on_stdout(jobid, lines, event) abort
199-
if !exists('g:intero_prompt_regex')
200-
let g:intero_prompt_regex = '[^-]> '
201-
endif
202-
203200
for l:line_seg in a:lines
204201
let s:current_line = s:current_line . l:line_seg
205202

plugin/intero.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ if !exists('g:intero_started')
1515
let g:intero_started = 0
1616
endif
1717

18+
if !exists('g:intero_prompt_regex')
19+
let g:intero_prompt_regex = '[^-]> '
20+
endif
21+
1822
" Starts the Intero process in the background.
1923
command! -nargs=0 -bang InteroStart call intero#process#start()
2024
" Kills the Intero process.

syntax/intero.vim

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""""""""""
2+
" Syntax:
3+
"
4+
" Custom syntax highlighting for GHCi in the embeded terminal window.
5+
"""""""""""
6+
7+
" Because we have some regex that use non-ASCII characters
8+
scriptencoding utf-8
9+
10+
syntax include @haskell syntax/haskell.vim
11+
12+
" Try to distinguish between GHC output and GHCi prompt lines, so that we can
13+
" enable Haskell highlighting on the GHCi prompts.
14+
exe 'syntax region GhciLine matchgroup=GhciLinePrompt start=/^'.g:intero_prompt_regex.'/ matchgroup=NONE end=/\n/ oneline keepend contains=@haskell,GhciCommand,GhciLoadCommand'
15+
syntax match GhciCommand /:[a-z-]\+/ contained
16+
syntax match GhciLoadCommand /:l.*/ contained contains=GhciCommand
17+
18+
" ----- GHC output ----------------------------------------------------------
19+
" Some rather ad-hoc regexes for GHC output.
20+
21+
" For when the modules are loaded / reloaded by GHCi.
22+
syntax region GhciSteps start=/^\[\s*\d\+ of \s*\d\+\]/ end=/)/
23+
syntax region GhciOk start=/^Ok, modules loaded:/ end=/\.$/
24+
25+
" Experimentally, it seems like GHC outputs "expected/actual" results in one
26+
" of two formats. Ideally, we'd have match group names describing when one
27+
" format isused over another.
28+
syntax region GhciExpectedActual1 start=/\(expected\|actual\) type/ end=// keepend contains=GhciQuotedType
29+
syntax region GhciQuotedType start=// end=// contained keepend
30+
syntax region GhciExpectedActual2 matchgroup=Constant start=/\(Expected\|Actual\) type: / end=/$/
31+
32+
syntax match GhciCause /^\s*• \(Probable\|Possible\) cause: .*$/
33+
syntax match GhciFix /^\s*\(Probable\|Possible\) fix: .*$/
34+
syntax region GhciPerhapsRegion matchgroup=GhciPerhapsYouMeant start=/^\z(\s*\)Perhaps you meant/ matchgroup=NONE end=/^\z1\S/ contains=GhciPerhapsSuggestion
35+
syntax region GhciPerhapsSuggestion start=// end=// contained keepend
36+
37+
38+
" ----- Default highlight groups --------------------------------------------
39+
" Used only if the user's colorscheme doesn't provide its own defaults.
40+
" In particular, you can configure these for yourself in your vimrc!
41+
42+
" We ignore the prompt GHCi prompts without ANSI color codes don't pick up
43+
" styles from the underlying Haskell syntax groups.
44+
hi def link GhciLinePrompt Ignore
45+
hi def link GhciCommand PreProc
46+
hi def link GhciLoadCommand Constant
47+
48+
hi def link GhciExpectedActual1 Constant
49+
hi def link GhciQuotedType Type
50+
hi def link GhciExpectedActual2 Type
51+
52+
hi def link GhciSteps Comment
53+
hi def link GhciOk Statement
54+
55+
hi def link GhciCause Underlined
56+
hi def link GhciFix Underlined
57+
hi def link GhciPerhapsYouMeant Underlined
58+
hi def link GhciPerhapsSuggestion Statement
59+

0 commit comments

Comments
 (0)