Skip to content

Commit

Permalink
Check for CMake error + hide panel before running (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
niosus authored Apr 13, 2020
1 parent 0162f83 commit 0a63f04
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions plugin/flags_sources/bazel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Bazel():
@staticmethod
def generate_compdb(view):
"""Generate the compilation database."""
OutputPanelHandler.hide_panel()
output = ''
workspace_file = File.search(
'WORKSPACE', TreeSearchScope(path.dirname(view.file_name())))
Expand Down
9 changes: 8 additions & 1 deletion plugin/flags_sources/cmake_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def __compile_cmake(cmake_file, cmake_binary, prefix_paths, flags,
if not cmake_file or not cmake_file.loaded():
return None

OutputPanelHandler.hide_panel()

if not prefix_paths:
prefix_paths = []
if not flags:
Expand Down Expand Up @@ -227,7 +229,12 @@ def __compile_cmake(cmake_file, cmake_binary, prefix_paths, flags,
log.debug(' running command: %s', cmake_cmd)
output_text = Tools.run_command(
command=cmake_cmd, cwd=tempdir, env=updated_environment)
log.debug("cmake produced output: \n%s", output_text)
log.debug("Cmake produced output: \n%s", output_text)
if "CMake Error" in output_text:
error_msg = "Error in file:\n{}\n\n{}".format(
cmake_file.full_path, output_text)
OutputPanelHandler.show(error_msg)
return None
database_path = path.join(tempdir, CompilationDb._FILE_NAME)
if not path.exists(database_path):
log.error(
Expand Down
7 changes: 7 additions & 0 deletions plugin/utils/output_panel_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ class OutputPanelHandler():
"""Handle the output panel."""
_PANEL_TAG = "ECC"

@staticmethod
def hide_panel():
"""Hide the output panel."""
window = sublime.active_window()
window.run_command(
"hide_panel", {"panel": "output." + OutputPanelHandler._PANEL_TAG})

@staticmethod
def show(text):
"""Show the panel with text."""
Expand Down
12 changes: 11 additions & 1 deletion tests/test_output_panel_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ def tearDown(self):
window.run_command("show_panel", {"panel": "output.UnitTesting"})

def test_panel_creation(self):
"""Test that we can convert time to seconds."""
"""Test that we can open a panel."""
OutputPanelHandler.show("hello world")
window = sublime.active_window()
self.assertIsNotNone(window.active_panel())
self.assertEquals(window.active_panel(), "output.ECC")
panel_view = window.find_output_panel(OutputPanelHandler._PANEL_TAG)
contents = panel_view.substr(sublime.Region(0, panel_view.size()))
self.assertEquals(contents, "hello world")

def test_panel_closing(self):
"""Test that we can close a panel."""
OutputPanelHandler.show("hello world")
window = sublime.active_window()
self.assertEquals(window.active_panel(), "output.ECC")
OutputPanelHandler.hide_panel()
self.assertIsNone(window.active_panel())

0 comments on commit 0a63f04

Please sign in to comment.