atom-haskell-archive / haskell-ghc-mod

haskell-ghc-mod atom package
https://atom.io/packages/haskell-ghc-mod
MIT License
69 stars 20 forks source link

ghc-mod displays error when editing a non-existing file #60

Closed thblt closed 8 years ago

thblt commented 8 years ago

When editing a non-existing file (this may happen when invoking Atom from command-line, eg. atom nonexisting.sh), haskell-ghc-mod displays an error:

Haskell-ghc-mod: ghc-mod lint /path/to/nonexisting.hs failed with error code 1 ghc-mod: Couldn't find file: /path/to/nonexisting.hs

Although the error is normal, I believe it would be nicer to postpone linting and display a simple notification ("ghc-mod won't work until this file is saved.") rather than this quite alarming message that doesn't go away.

Thanks,

lierdakil commented 8 years ago

Actually, I believe that's a bug, since linting and checking a file that has not been saved should be possible. I think that should be happening only on empty nonexistent files, since Atom generally reports nonempty nonexistent files as "changed", and that should work. Please correct me if I'm wrong.

thblt commented 8 years ago

Thanks for your answer ! I've done some more testing:

Sorry, I haven't even tested if linting worked despite the error — my mistake.

The problem seems to be a bit more complicated than I initially reported. Ghc-mod behaves differently with non-existing files, depending on whether they've been named or not.

  1. If I create a new, nameless file (File/New File), and set its type to Haskell, I get neither linting nor error checking until I save it. I don't know if this is an Atom limitation, if it's the case please ignore it --- I'm very new to this editor.
  2. If I open a non-existing but named file (atom myfile.hs), I get linting, but no error checking. Checking starts immediately after the first save.

I tested with the following code:

a = (2)
a = (3)

In the first case (File/New File, set type to Haskell), I get neither linting nor error checking. In the second case, I get correct notices about the redundant parentheses, but nothing about the duplicate declaration of a, which only appears after I save the file.

lierdakil commented 8 years ago

Um. What version of ghc-mod do you use? Any named files should pretty much work with 5.4.0.0 and up. Not so sure about earlier versions (and 5.3.0.0 is pretty much broken, so I don't support it)

Also, "unnamed" files would be hard to check, due to some inherent limitations of GHC API (basically I'd have to guess filenames, which is less than optimal -- and I don't think that's really necessary to have this working anyway). More user-friendly message might be in order though.

thblt commented 8 years ago
$ ghc-mod --version
ghc-mod version 5.4.0.0 compiled by GHC 7.10.2

Installed with Homebrew's cabal, on OSX 10.11. Same behavior on Linux.

Also, "unnamed" files would be hard to check, due to some inherent limitations of GHC API (basically I'd have to guess filenames, which is less than optimal -- and I don't think that's really necessary to have this working anyway).

I agree with that.

lierdakil commented 8 years ago

Sorry about the holdup, I'm currently very short on time.

A couple more questions, if you don't mind. Do you use ide-haskell, or linter frontend? If latter, check is only performed on save, due to it being rather slow, while linting is on-the-fly. I probably should skip lints for empty buffers altogether. If former, then I'm not sure what's going on.

lierdakil commented 8 years ago

Okay, so 0.9.14 shouldn't attempt to lint empty buffers, which will suppress error message. Please confirm that it works out for you.

thblt commented 8 years ago

Thanks! I'm testing with 1.0.0 right now.

Just noticed a small cache issue: when reopening a file, the linting messages and errors appears as they were when it was last closed in Atom, even if it has been modified since.

Besides that, using Linter, everything seems to work : no error message when the file doesn't exist, linting on the fly, check on save.

Using IDE-Haskell, I'm only able to get linting and error checking on save. Maybe I'm missing a setting somewhere?

lierdakil commented 8 years ago

Sorry for late reply. I just released a version that has check/lint on change with ide-haskell. Bear in mind that checking on change can be very slow, so tread lightly. (you need to enable 'On Change Check/Lint' in haskell-ghc-mod settings, and it's not available for linter right now)

I believe cache issue is with linter package, although it can also happen with ide-haskell. I can't say I'm terribly inclined to fix this, due to it being basically self-correcting, and watching files for changes would be relatively hard (TL;DR not worth fixing IMO)

This issue can be closed I think.