Skip to content
Browse files

add autocomplete output panel on error messages (issue #42)

  • Loading branch information...
1 parent f29f651 commit 2877e36e7e20d092c8cc7e83f1a0c182fc4e5e3f @ostinelli committed Oct 10, 2012
View
90 sublimerl_autocompiler.py
@@ -0,0 +1,90 @@
+# ==========================================================================================================
+# SublimErl - A Sublime Text 2 Plugin for Erlang Integrated Testing & Code Completion
+#
+# Copyright (C) 2012, Roberto Ostinelli <roberto@ostinelli.net>.
+# All rights reserved.
+#
+# BSD License
+#
+# Redistribution and use in source and binary forms, with or without modification, are permitted provided
+# that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
+# following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
+# the following disclaimer in the documentation and/or other materials provided with the distribution.
+# * Neither the name of the authors nor the names of its contributors may be used to endorse or promote
+# products derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+# ==========================================================================================================
+
+# imports
+import sublime, sublime_plugin
+import os, threading
+from sublimerl_core import SUBLIMERL, SublimErlProjectLoader
+
+
+# test runner
+class SublimErlAutocompiler(SublimErlProjectLoader):
+
+ def __init__(self, view):
+ # init super
+ SublimErlProjectLoader.__init__(self, view)
+ # init
+ self.panel_name = 'sublimerl_autocompiler'
+ self.panel_buffer = ''
+ # setup panel
+ self.setup_panel()
+
+ def setup_panel(self):
+ self.panel = self.window.get_output_panel(self.panel_name)
+ self.panel.settings().set("syntax", os.path.join(SUBLIMERL.plugin_path, "theme", "SublimErlAutocompile.hidden-tmLanguage"))
+ self.panel.settings().set("color_scheme", os.path.join(SUBLIMERL.plugin_path, "theme", "SublimErlAutocompile.hidden-tmTheme"))
+
+ def update_panel(self):
+ if len(self.panel_buffer):
+ panel_edit = self.panel.begin_edit()
+ self.panel.insert(panel_edit, self.panel.size(), self.panel_buffer)
+ self.panel.end_edit(panel_edit)
+ self.panel.show(self.panel.size())
+ self.panel_buffer = ''
+ self.window.run_command("show_panel", {"panel": "output.%s" % self.panel_name})
+
+ def hide_panel(self):
+ self.window.run_command("hide_panel")
+
+ def log(self, text):
+ self.panel_buffer += text
+ sublime.set_timeout(self.update_panel, 0)
+
+ def compile(self):
+ retcode, data = self.compile_source(skip_deps=True)
+ if retcode != 0:
+ self.log(data)
+ else:
+ sublime.set_timeout(self.hide_panel, 0)
+
+# listener
+class SublimErlAutocompilerListener(sublime_plugin.EventListener):
+
+ # CALLBACK ON VIEW SAVE
+ def on_post_save(self, view):
+ # ensure context matches
+ caret = view.sel()[0].a
+ if not ('source.erlang' in view.scope_name(caret) and sublime.platform() != 'windows'): return
+ # init
+ autocompiler = SublimErlAutocompiler(view)
+ # compile saved file & reload completions
+ class SublimErlThread(threading.Thread):
+ def run(self):
+ # compile
+ autocompiler.compile()
+ SublimErlThread().start()
View
2 sublimerl_completion.py
@@ -213,8 +213,6 @@ def on_post_save(self, view):
# compile saved file & reload completions
class SublimErlThread(threading.Thread):
def run(self):
- # compile
- completions.compile_source(skip_deps=True)
# trigger event to reload completions
completions.generate_project_completions()
SublimErlThread().start()
View
1 sublimerl_core.py
@@ -262,6 +262,7 @@ def compile_source(self, skip_deps=False):
# compile to ebin
options = 'skip_deps=true' if skip_deps else ''
retcode, data = self.execute_os_command('%s compile %s' % (SUBLIMERL.rebar_path, options), dir_type='project', block=True, log=False)
+ return (retcode, data)
def shellquote(self, s):
return SUBLIMERL.shellquote(s)
View
7 sublimerl_tests_integration.py
@@ -44,7 +44,7 @@ def __init__(self, view):
# init
self.initialized = False
- self.panel_name = 'sublimerl'
+ self.panel_name = 'sublimerl_tests'
self.panel_buffer = ''
# don't proceed if a test is already running
@@ -62,9 +62,8 @@ def __init__(self, view):
def setup_panel(self):
self.panel = self.window.get_output_panel(self.panel_name)
- # TODO: have this set as relative path
- self.panel.settings().set("syntax", os.path.join(SUBLIMERL.plugin_path, "theme", "SublimErl.hidden-tmLanguage"))
- self.panel.settings().set("color_scheme", os.path.join(SUBLIMERL.plugin_path, "theme", "SublimErl.hidden-tmTheme"))
+ self.panel.settings().set("syntax", os.path.join(SUBLIMERL.plugin_path, "theme", "SublimErlTests.hidden-tmLanguage"))
+ self.panel.settings().set("color_scheme", os.path.join(SUBLIMERL.plugin_path, "theme", "SublimErlTests.hidden-tmTheme"))
def update_panel(self):
if len(self.panel_buffer):
View
31 theme/SublimErlAutocompile.hidden-tmLanguage
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>name</key>
+ <string>SublimErlAutocomplete</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>comment</key>
+ <string>autocompile description</string>
+ <key>match</key>
+ <string>==> TDD \(compile\)</string>
+ <key>name</key>
+ <string>autocompile.desc</string>
+ </dict>
+ <dict>
+ <key>comment</key>
+ <string>autocompile fail</string>
+ <key>match</key>
+ <string>ERROR: compile failed while processing .*</string>
+ <key>name</key>
+ <string>autocompile.fail</string>
+ </dict>
+ </array>
+ <key>scopeName</key>
+ <string>autocompile.erlang</string>
+ <key>uuid</key>
+ <string>72174d10-bb12-11e0-962b-111111111359</string>
+</dict>
+</plist>
View
54 theme/SublimErlAutocompile.hidden-tmTheme
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>comment</key>
+ <string>SublimErlAutocomplete Theme</string>
+ <key>name</key>
+ <string>SublimErlAutocomplete</string>
+ <key>settings</key>
+ <array>
+ <dict>
+ <key>settings</key>
+ <dict>
+ <key>background</key>
+ <string>#000000</string>
+ <key>caret</key>
+ <string>#A7A7A7</string>
+ <key>foreground</key>
+ <string>#f4f4f4</string>
+ <key>invisibles</key>
+ <string>#CAE2FB3D</string>
+ <key>lineHighlight</key>
+ <string>#FFFFFF0D</string>
+ <key>selection</key>
+ <string>#6f6f6f</string>
+ </dict>
+ </dict>
+ <dict>
+ <key>name</key>
+ <string>autocompile fail</string>
+ <key>scope</key>
+ <string>autocompile.fail</string>
+ <key>settings</key>
+ <dict>
+ <key>foreground</key>
+ <string>#c23621</string>
+ </dict>
+ </dict>
+ <dict>
+ <key>name</key>
+ <string>autocompile description</string>
+ <key>scope</key>
+ <string>autocompile.desc</string>
+ <key>settings</key>
+ <dict>
+ <key>foreground</key>
+ <string>#33bbc8</string>
+ </dict>
+ </dict>
+ </array>
+ <key>uuid</key>
+ <string>72174d10-bb12-11e0-962b-111111111358</string>
+</dict>
+</plist>
View
2 theme/SublimErl.hidden-tmLanguage → theme/SublimErlTests.hidden-tmLanguage
@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>name</key>
- <string>SublimErl</string>
+ <string>SublimErlTests</string>
<key>patterns</key>
<array>
<dict>
View
4 theme/SublimErl.hidden-tmTheme → theme/SublimErlTests.hidden-tmTheme
@@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>comment</key>
- <string>SublimErl Theme</string>
+ <string>SublimErlTests Theme</string>
<key>name</key>
- <string>SublimErl</string>
+ <string>SublimErlTests</string>
<key>settings</key>
<array>
<dict>

0 comments on commit 2877e36

Please sign in to comment.
Something went wrong with that request. Please try again.