eagletmt / ghcmod-vim

Happy Haskell programming on Vim, powered by ghc-mod
http://www.vim.org/scripts/script.php?script_id=4473
433 stars 59 forks source link

ghcmod#type: Cannot guess type #24

Closed gertcuykens closed 11 years ago

gertcuykens commented 11 years ago

Can you make ghcmod errors also appear in the statusline pleas so you do not have to press enter and the buffer does not jump 3 lines up and back down again?

ghcmod#type: Cannot guess type

Press ENTER or type command to continue
eagletmt commented 11 years ago

I will remove the need to press enter when :GhcModType fails.

But error indications in status bar is not in ghcmod-vim's scope. If you want, you should define such command by yourself. For example, you might define :GhcModTypeWithStatusBar and setup 'statusline' in your vimrc like this.

let &statusline = '[%{GhcModTypeLastStatus()}] ' . &statusline
function! GhcModTypeLastStatus()
  return get(w:, 'ghcmod_type_last_status', 1) ? 'ghcmod#type OK' : 'ghcmod#type FAIL'
endfunction

command! GhcModTypeWithStatusBar call s:type_with_status_bar()
function! s:type_with_status_bar()
  let [l:_, l:type] = ghcmod#type()
  if empty(l:type)
    " ghcmod#type() failed
    let w:ghcmod_type_last_status = 0
  else
    let w:ghcmod_type_last_status = 1
    echo l:type
  endif
endfunction
gertcuykens commented 11 years ago

commit works perfect for ghcmod#type: Cannot guess type thx :)

Can you also do it for modified buffers?

ghcmod#type: the buffer has been modified but not written
Int
Press ENTER or type command to continue

Replacing it by

Int (colored in red)

GhcModInfo in statusline would also be nice?

test :: Int     -- Defined at /home/gert/test.hs:11:1

Press ENTER or type command to continue
eagletmt commented 11 years ago

I don't think it is a good idea to suppress that warning message. Why do not you want to call ghcmod#type() before you save it?

gertcuykens commented 11 years ago

Its not really suppressing more like compacting :) When it does this 3 line gui jump it feels like a popup from a browser :) For me it would be more gui friendly if there are no 3 line popup's unless you do like :Errors to open up a 3 line buffer if the one statusline subscription is not clear. But just using colors or extra symbols * is all you need to indicate the same thing on one statusline without a popup :)

eagletmt commented 11 years ago

It is a WARNING message. If you feel inconvenienced, it is my intention. Save the buffer before calling ghcmod#type() because ghc-mod reads source code from a file, not from a buffer. Otherwise tell me why you don't want to save.

gertcuykens commented 11 years ago

Let say you are programing a mars rover that takes 7 minutes to save :) Please take a look at syntastic it has plenty of warning and error messages but it always sticks to the status line saved or not, unless you open :Errors

eagletmt commented 11 years ago

It's not convincing :-p

I had a look at syntastic. What the :Errors command does is to show errors/warnings from checkers (compilers) in the location window, isn't it? The warning message discussing here is from Vim plugin itself. Such message is not suitable for location window.

gertcuykens commented 11 years ago

Yes, fair enough :) What about just the warning message and discard the ghcmod#type result so you end up with just one line ghcmod#type: the buffer has been modified but not written thats also fine for me :) O and make it the same red layout as the other warning messages example ghcmod#type: Cannot guess type so all warnings are consistent 1 liners?

eagletmt commented 11 years ago

Then what about the following behavior?

When the buffer is modified,

gertcuykens commented 11 years ago

That would be nice :) Also check if the warning is the same style / color as the other once.

eagletmt commented 11 years ago

Done. The message is highlighted as WarningMsg if ! is given, otherwise it is highlighted as ErrorMsg.

gertcuykens commented 11 years ago

Works thx :) Can you also make a :GhcModInfo :GhcModInfo!

ghcmod#info: the buffer has been modified but not written
Dummy:0:0:Error:Could not find module `Main'
It is not a module in the current program, or in any known package.
Press ENTER or type command to continue

So you end up with

ghcmod#info: the buffer has been modified but not written

or in case of code that can not be compiled

ghcmod#info: Could not find module `Main'
eagletmt commented 11 years ago

I'm making a big change of code base while most of command compatibilities are kept. I will add :GhcModInfo! after that.

But I won't truncate messages from ghc-mod. When ghc-mod info fails due to a compilation error or something, :GhcModInfo and :GhcMondInfo! will produce multiple lines.

Could not find module `Main'
It is not a module in the current program, or in any known package.

If you don't like it, define a new command in your vimrc. It's easier than persuading me :-)