Skip to content

Commit

Permalink
Fix warning highlighting.
Browse files Browse the repository at this point in the history
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
nh2 committed Jan 13, 2013
1 parent c18e1b0 commit 97b57c9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Cabal.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"caption": "Cabal: Build",
"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"
Expand All @@ -23,6 +27,10 @@
"caption": "Cabal-Dev: Build",
"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"
Expand Down
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"caption": "SublimeHaskell: Build",
"command": "sublime_haskell_build"
},
{
"caption": "SublimeHaskell: Typecheck build (no codegen)",
"command": "sublime_haskell_build"
},
{
"caption": "SublimeHaskell: Clean",
"command": "sublime_haskell_clean"
Expand Down
26 changes: 26 additions & 0 deletions SublimeHaskell.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
28 changes: 23 additions & 5 deletions cabalbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'}
}
Expand Down Expand Up @@ -166,7 +172,7 @@ def run(self):

class SublimeHaskellBuild(SublimeHaskellBaseCommand):
def run(self):
self.build('build')
self.build('build_then_warnings')


class SublimeHaskellRebuild(SublimeHaskellBaseCommand):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down

2 comments on commit 97b57c9

@gseitz
Copy link

@gseitz gseitz commented on 97b57c9 Jan 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is awesome!

@mvoidex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

Please sign in to comment.