atom-ide-purescript
atom-ide-purescript copied to clipboard
Detect when a build is required
On Windows, if I do the following steps:
- Terminate all
psc-ide-server
processes - Make a new folder
- Do
pulp init
in the new folder - Open Atom
- Open the new folder in Atom (by dragging it onto the Atom window)
- Open src/Main.purs
- Save src/Main.purs (with no changes)
Then Atom reports as an error that Control.Monad.Eff is an unknown module. The error disappears after a short time.
If I then add
import Math (sqrt)
to the end of the imports, I again get the errorUnknown module Math
, as expected. If I now dobower install purescript-math --save-dev
, and save src/Main.purs again, the error should stop and compilation should be successful, but there's no change. For comparison, if I dopulp -w build --to bundle.js
in the same folder it builds successfully with no errors (just warnings about unused imports). I can add an index.html file, run lserver, and successfully run a bundle.js compiled with the Math module. The Atom package's build command is the default:pulp.cmd build --no-psa --json-errors
If I exit Atom and open it again, when I save Main.purs it builds successfully, with only warnings about redundant imports. It's good that I can work around the problem, but I shouldn't have to restart Atom to import a new module.
You have to run a pulp build
command before psc-ide can pick up your fresh dependencies. It's available inside atom behind the keybinding Ctrl-o b
or you can run it from the command palette searching for IdePureScript: Build
Edit: Once your dependencies are built, atom will keep them up to date and reflect changes right away, but the initial build needs to be triggered manually.
What @kRITZCREEK says is correct. Open to suggestions for better UX for this case - my concern is I don't want to automatically run a full build on save in certain cases that may not trigger correctly, and may not be obvious that/why it's happening.
A full build fixes the problem, thanks. I wasn't aware that there was a difference between the build-on-save and a full build. Some issues can be expanded to show additional information and possible fixes. Could something about making a full build be added to the unknown module error? At the moment it doesn't expand to anything.
If you have "Use fast rebuild" configured then a single-file rebuild will be done via psc-ide-server, which for larger projects is much faster than a full build.
The unknown module error is from the compiler itself, so this will not change, but what would be more realistic is detecting when there are no externs present (ie no/empty output dir) when doing a rebuild, and throw up some info somehow in this case. I'm not sure we can detect anything more subtle than this all/nothing though (other occasions you may need to do a full build due to making interdependent changes, installing further dependencies, etc).
I guess we could augment unknown module with a "full build" text or quick-fix action, but I'm not sure what the hit rate is for that - probably is a good chance that a rebuild might fix it? Or at least you would know whether it should.
From discussion there's a possibility this is something psc-ide might do in the future