ghc-mod icon indicating copy to clipboard operation
ghc-mod copied to clipboard

Emacs ghc-mod hlint checking highlights at wrong position

Open veniversum opened this issue 10 years ago • 7 comments

When checking with hlint in emacs, the first line of the file is highlighted/underlined as a warning or error instead of the actual place for the suggestion.

Running ghc-mod lint filename.hs in console correctly generates list of suggestions with line numbers and positions, e.g.

filename.hs:31:16: Warning: xx Found: xx Why not: xx

but only the first line of the file is underlined in emacs and the warning shown while hovered over.

emacs version: 25.0.50.1 ghc-mod version: 5.4.0.0 hlint version: 1.9.21

veniversum avatar Oct 07 '15 14:10 veniversum

I'm experiencing the same thing. Did you ever find a fix?

jdreaver avatar Oct 31 '15 16:10 jdreaver

Usually this happens when the filenames don't match IIRC. Might that be the case?

DanielG avatar Nov 01 '15 21:11 DanielG

When you say filenames don't match, do you mean file name and module name?

I tried ghc-mod in a file called Temp.hs, but I started the file with module Main where because it is meant to be an executable.

Here is what I put in /tmp/Test.hs:

module Main where

import Data.Ma -- Error here

main :: IO ()
main = putStrLn "hello"

Here is what ghc-mod check reports on the command line:

 tmp $ ghc-mod check Test.hs
Test.hs:3:8:Could not find module ‘Data.Ma’Perhaps you meant  Data.Map (from containers-0.5.6.2
@conta_LKCPrTJwOTOLk4OU37YmeN)  Data.Eq (from base-4.8.1.0)  Data.Ix (from base-4.8.1.0)Use -v 
to see a list of the files searched for.  

However, the red squiggly line is in the top left.

jdreaver avatar Nov 02 '15 15:11 jdreaver

You'll want to start looking somewhere around here: https://github.com/kazu-yamamoto/ghc-mod/blob/master/elisp/ghc-check.el#L156

That's where the overlays are constructed. If you trace through that you should be able to figure out why (file-equal-p ofile file) doesn't hold, which is what I meant by "file names don't match". IIRC that's the bit that decides whether the info is for the current buffer's file or another one, in which case we highlight the first line in the buffer instead.

You can use C-h C-f to jump to the definition of ghc-check-highlight-original-buffer inside Emacs. Using C-u C-M-x while point is in that source file will instrument the function using EDebug which will then break on the next entry and allow you to step through the evaluation with SPC (while displaying the current value in the minibuffer). You can use q to exit EDebug and just C-M-x to re-evaluate the function without instrumentation, also while point is in the function's body.

DanielG avatar Nov 07 '15 20:11 DanielG

When debugging in EDebug, it steps directly from Line 157 to the end of Line 201. Is that expected behavior?

veniversum avatar Nov 19 '15 23:11 veniversum

Yup: if (buffer-live-p buf) is nil.

(defmacro ghc-with-current-buffer (buf &rest body)
  ;; (declare (indent 1))
  `(if (buffer-live-p ,buf)
       (with-current-buffer ,buf
     ,@body)))

DanielG avatar Nov 22 '15 21:11 DanielG

This issue seems to have been fixed.

veniversum avatar Nov 07 '16 17:11 veniversum