Permalink
Browse files

Fix warning highlighting.

So far, we just did a normal, incremental cabal build,
which resulted in warnings only being generated once
and vanishing with the next save.

This adds a configurable new option which is now the default:
After running an incremental build, we can recompile everything
with -Wall (and -fno-code to make it faster).

This results in errors being shown fast as usual and code being built,
and warnings popping up slightly afterwards.

This is the new default for both autosave and the build command.

There are also some new options to run a "typecheck" build
that is faster by leaving out as much codegen as possible
(currently this is just -c for not linking).
  • Loading branch information...
1 parent c18e1b0 commit 97b57c9fd8d18f3377872636dcf7aa7dbd84a030 @nh2 nh2 committed Jan 13, 2013
Showing with 61 additions and 5 deletions.
  1. +8 −0 Cabal.sublime-commands
  2. +4 −0 Default.sublime-commands
  3. +26 −0 SublimeHaskell.sublime-settings
  4. +23 −5 cabalbuild.py
@@ -4,6 +4,10 @@
"command": "sublime_haskell_cabal_build"
},
{
+ "caption": "Cabal: Typecheck build (no codegen)",
+ "command": "sublime_haskell_cabal_check_build"
+ },
+ {
"caption": "Cabal: Clean",
"command": "sublime_haskell_cabal_clean"
},
@@ -24,6 +28,10 @@
"command": "sublime_haskell_cabal_dev_build"
},
{
+ "caption": "Cabal-Dev: Typecheck build (no codegen)",
+ "command": "sublime_haskell_cabal_dev_check_build"
+ },
+ {
"caption": "Cabal-Dev: Clean",
"command": "sublime_haskell_cabal_dev_clean"
},
@@ -26,6 +26,10 @@
"command": "sublime_haskell_build"
},
{
+ "caption": "SublimeHaskell: Typecheck build (no codegen)",
+ "command": "sublime_haskell_build"
+ },
+ {
"caption": "SublimeHaskell: Clean",
"command": "sublime_haskell_clean"
},
@@ -19,6 +19,32 @@
// Enable auto lint on save (as hints when building)
"enable_auto_lint": true,
+ // How to build the cabal project in order to obtain error messages.
+ // This option exists because `cabal build` is slow and cannot re-print
+ // warnings of already compiled modules.
+ // (Also see https://github.com/haskell/cabal/issues/1179, cabal 1.16).
+ //
+ // Possible values:
+ // - "normal"
+ // Uses a full `cabal build`, generating object files and binaries.
+ // If this takes too long for you, look at the other options.
+ // - "normal-then-warnings"
+ // Like "normal", but afterwards also collects project-wide warnings with
+ // `cabal build --ghc-options="-fforce-recomp -Wall -fno-code"`
+ // (this recompiles everything, but skips code generation for speed).
+ // - "typecheck"
+ // Performs a type check of the whole project, trying to not do any more
+ // than that in order to give faster feedback (that "normal").
+ // Currently uses `cabal build --ghc-options="-c"` to skip linking.
+ // - "typecheck-then-warnings"
+ // Like "typecheck", but afterwards collects warnings like
+ // "normal-then-warnings".
+ //
+ // Please note that it is currently impossible to properly use a `-fno-code`
+ // build on a cabal project that links a shared library; it errors too early.
+ // (https://github.com/haskell/cabal/issues/1176, cabal 1.16).
+ "auto_build_mode": "normal-then-warnings",
+
// Show output window on build/check/lint:
"show_output_window": true,
View
@@ -3,7 +3,7 @@
import sublime_plugin
from threading import Thread
-from sublime_haskell_common import log, get_cabal_project_dir_and_name_of_view, call_and_wait, get_setting, get_setting_async, set_setting, save_settings, get_haskell_command_window_view_file_project, attach_sandbox
+from sublime_haskell_common import log, get_cabal_project_dir_and_name_of_view, call_and_wait, get_setting, get_setting_async, set_setting, save_settings, get_haskell_command_window_view_file_project, attach_sandbox, output_error
from parseoutput import run_chain_build_thread
from autocomplete import autocompletion
@@ -18,6 +18,12 @@
'clean': {'steps': [['clean']], 'message': 'Cleaning'},
'configure': {'steps': [['configure']], 'message': 'Configure'},
'build': {'steps': [['build']], 'message': 'Building'},
+ 'typecheck': {'steps': [['build', '--ghc-options=-c']], 'message': 'Checking'},
+ # Commands with warnings:
+ # Run fast, incremental build first. Then build everything with -Wall and -fno-code
+ # If the incremental build fails, the second step is not executed.
+ 'build_then_warnings': {'steps': [['build'], ['build', '--ghc-options=-fforce-recomp -Wall -fno-code']], 'message': 'Building'},
+ 'typecheck_then_warnings': {'steps': [['build', '--ghc-options=-c'], ['build', '--ghc-options=-fforce-recomp -Wall -fno-code']], 'message': 'Checking'},
'rebuild': {'steps': [['clean'], ['configure'], ['build']], 'message': 'Rebuilding'},
'install': {'steps': [['install']], 'message': 'Installing'}
}
@@ -166,7 +172,7 @@ def run(self):
class SublimeHaskellBuild(SublimeHaskellBaseCommand):
def run(self):
- self.build('build')
+ self.build('build_then_warnings')
class SublimeHaskellRebuild(SublimeHaskellBaseCommand):
@@ -184,7 +190,19 @@ class SublimeHaskellBuildAuto(SublimeHaskellBaseCommand):
def run(self):
current_project_dir, current_project_name = get_cabal_project_dir_and_name_of_view(self.window.active_view())
if current_project_name and current_project_dir:
- run_build(self.window.active_view(), current_project_name, current_project_dir, 'build', None)
+ build_mode = get_setting('auto_build_mode')
+
+ build_command = {
+ 'normal': 'build',
+ 'normal-then-warnings': 'build_then_warnings',
+ 'typecheck': 'typecheck',
+ 'typecheck-then-warnings': 'typecheck_then_warnings',
+ }.get(build_mode)
+
+ if not build_command:
+ output_error(self.window, "SublimeHaskell: invalid auto_build_mode '%s'" % build_mode)
+
+ run_build(self.window.active_view(), current_project_name, current_project_dir, build_command, None)
class SublimeHaskellRun(SublimeHaskellBaseCommand):
@@ -285,7 +303,7 @@ def run(self):
class SublimeHaskellCabalBuild(SublimeHaskellBaseCommand):
def run(self):
- self.build('build', False)
+ self.build('build_then_warnings', False)
class SublimeHaskellCabalRebuild(SublimeHaskellBaseCommand):
@@ -312,7 +330,7 @@ def run(self):
class SublimeHaskellCabalDevBuild(SublimeHaskellBaseCommand):
def run(self):
- self.build('build', True)
+ self.build('build_then_warnings', True)
class SublimeHaskellCabalDevRebuild(SublimeHaskellBaseCommand):

2 comments on commit 97b57c9

@gseitz
gseitz commented on 97b57c9 Jan 14, 2013

This change is awesome!

@mvoidex
Member

Great, thanks!

Please sign in to comment.