Beispiel #1
0
class ErrorView(OnePerWindow):

    error_type_display = {
        'error': 'Error',
        'warning': 'Warning',
        'failure': 'Test Failure'
    }

    def __init__(self, window):
        self.window = window
        self.settings = SBTSettings(window)
        self.panel = self.window.get_output_panel('sbt_error')
        self.panel.set_read_only(True)
        self.panel.settings().set('line_numbers', False)
        self.panel.settings().set('gutter', False)
        self.panel.settings().set('scroll_past_end', False)
        self.panel.set_syntax_file("Packages/SublimeSBT/SBTError.hidden-tmLanguage")
        self._update_panel_colors()
        self.settings.add_on_change(self._update_panel_colors)

    def show(self):
        self._update_panel_colors()
        self.window.run_command('show_panel', {'panel': 'output.sbt_error'})

    def hide(self):
        self.window.run_command('hide_panel', {'panel': 'output.sbt_error'})

    def show_error(self, error):
        self.show()
        self.panel.run_command('sbt_show_error_text',
                               {'text': self._error_text(error)})
        self.panel.sel().clear()
        self.panel.show(0)

    def clear(self):
        self.panel.run_command('sbt_show_error_text', {'text': ''})
        self.panel.sel().clear()

    def _error_text(self, error):
        banner = ' -- %s --' % type(self).error_type_display[error.error_type]
        return '%s\n%s' % (banner, error.text)

    def _update_panel_colors(self):
        self.panel.settings().set('color_scheme', self.settings.get('color_scheme'))
Beispiel #2
0
class ErrorView(object):

    error_views = {}

    @classmethod
    def get_error_view(cls, window):
        if window.id() not in cls.error_views:
            cls.error_views[window.id()] = ErrorView(window)
        return cls.error_views[window.id()]

    def __init__(self, window):
        self.window = window
        self.settings = SBTSettings(window)
        self.panel = self.window.get_output_panel('sbt_error')
        self.panel.set_read_only(True)
        self._update_panel_colors()
        self.settings.add_on_change(self._update_panel_colors)
        self._type_display = {
            'error': 'Error',
            'warning': 'Warning',
            'failure': 'Test Failure'
        }

    def show(self):
        self._update_panel_colors()
        self.window.run_command('show_panel', {'panel': 'output.sbt_error'})

    def hide(self):
        self.window.run_command('hide_panel', {'panel': 'output.sbt_error'})

    def show_error(self, error):
        banner = ' -- %s --' % self._type_display[error.error_type]
        text = '%s\n\n%s' % (banner, error.text)
        self.show()
        self.panel.run_command('sbt_show_error_text', {'text': text})
        self.panel.sel().clear()
        self.panel.show(0)

    def _update_panel_colors(self):
        self.panel.settings().set('color_scheme', self.settings.get('color_scheme'))
class SbtView(OnePerWindow):

    settings = {
        "line_numbers": False,
        "gutter": False,
        "rulers": [],
        "word_wrap": False,
        "draw_centered": False,
        "highlight_line": False
    }

    @classmethod
    def is_sbt_view(cls, view):
        if view is not None:
            for window in maybe(view.window()):
                sbt_view = cls(window)
                return sbt_view.panel.id() == view.id()

    def __init__(self, window):
        self.window = window
        self.settings = SBTSettings(window)
        self.panel = self.window.get_output_panel('sbt')
        self.panel.set_syntax_file("Packages/SublimeSBT/SBTOutput.hidden-tmLanguage")
        for name, setting in SbtView.settings.items():
            self.panel.settings().set(name, setting)
        self._update_panel_colors()
        self.settings.add_on_change(self._update_panel_colors)
        self._output_size = 0
        self._set_running(False)

    def start(self):
        self.clear_output()
        self.show()
        self._set_running(True)

    def finish(self):
        self.show_output('\n -- Finished --\n')
        self._set_running(False)

    def show(self):
        self._update_panel_colors()
        self.window.run_command('show_panel', {'panel': 'output.sbt'})

    def hide(self):
        self.window.run_command('hide_panel', {'panel': 'output.sbt'})

    def focus(self):
        self.window.focus_view(self.panel)
        self.panel.show(self.panel.size())

    def show_output(self, output):
        output = self._clean_output(output)
        self.show()
        self._append_output(output)
        self._output_size = self.panel.size()
        self.panel.show(self.panel.size())

    def clear_output(self):
        self._erase_output(sublime.Region(0, self.panel.size()))

    def take_input(self):
        input_region = sublime.Region(self._output_size, self.panel.size())
        input = self.panel.substr(input_region)
        if sublime.platform() == 'windows':
            self._append_output('\n')
        else:
            self._erase_output(input_region)
        return input

    def delete_left(self):
        if self.panel.sel()[0].begin() > self._output_size:
            self.panel.run_command('left_delete')

    def delete_bol(self):
        if self.panel.sel()[0].begin() >= self._output_size:
            p = self.panel.sel()[-1].end()
            self._erase_output(sublime.Region(self._output_size, p))

    def delete_word_left(self):
        if self.panel.sel()[0].begin() > self._output_size:
            for r in self.panel.sel():
                p = max(self.panel.word(r).begin(), self._output_size)
                self.panel.sel().add(sublime.Region(p, r.end()))
            self._erase_output(*self.panel.sel())

    def delete_word_right(self):
        if self.panel.sel()[0].begin() >= self._output_size:
            for r in self.panel.sel():
                p = self.panel.word(r).end()
                self.panel.sel().add(sublime.Region(r.begin(), p))
            self._erase_output(*self.panel.sel())

    def update_writability(self):
        self.panel.set_read_only(not self._running or
                                 self.panel.sel()[0].begin() < self._output_size)

    def _set_running(self, running):
        self._running = running
        self.update_writability()

    def _append_output(self, output):
        self._run_command('sbt_append_output', output=output)

    def _erase_output(self, *regions):
        self._run_command('sbt_erase_output',
                          regions=[[r.begin(), r.end()] for r in regions])

    def _run_command(self, name, **kwargs):
        self.panel.set_read_only(False)
        self.panel.run_command(name, kwargs)
        self.update_writability()

    def _clean_output(self, output):
        return self._strip_codes(self._normalize_lines(output))

    def _normalize_lines(self, output):
        return output.replace('\r\n', '\n').replace('\033M', '\r')

    def _strip_codes(self, output):
        return re.sub(r'\033\[[0-9;]+[mK]', '', output)

    def _update_panel_colors(self):
        self.panel.settings().set('color_scheme', self.settings.get('color_scheme'))
Beispiel #4
0
class Project(object):

    projects = {}

    @classmethod
    def get_project(cls, window):
        if window.id() not in cls.projects:
            cls.projects[window.id()] = Project(window)
        return cls.projects[window.id()]

    def __init__(self, window):
        self.window = window
        self.settings = SBTSettings(window)
        self.error_report = ErrorReport()
        self.error_reporter = ErrorReporter(window,
                                            self.error_report,
                                            self.settings)

    def project_root(self):
        for folder in self.window.folders():
            if self._is_sbt_folder(folder):
                return folder

    def is_sbt_project(self):
        return self.project_root() is not None

    def is_play_project(self):
        if not self.is_sbt_project():
            return False
        build_path = os.path.join(self.project_root(), 'project', 'Build.scala')
        return os.path.exists(build_path) and self._is_play_build(build_path)

    def sbt_command(self):
        if self.is_play_project():
            return self.settings.play_command()
        else:
            return self.settings.sbt_command()

    def setting(self, name):
        return self.settings.get(name)

    def expand_filename(self, filename):
        if len(os.path.dirname(filename)) > 0:
            return filename
        else:
            return self._find_in_project(filename)

    def relative_path(self, filename):
        return os.path.relpath(filename, self.project_root())

    def open_project_file(self, filename, line):
        full_path = os.path.join(self.project_root(), filename)
        self.window.open_file('%s:%i' % (full_path, line),
                              sublime.ENCODED_POSITION)

    def _is_sbt_folder(self, folder):
        return (os.path.exists(os.path.join(folder, 'build.sbt')) or
                os.path.exists(os.path.join(folder, 'project', 'Build.scala')))

    def _is_play_build(self, build_path):
        try:
            build_file = open(build_path, 'r').readlines()
            for line in build_file:
                if re.search(r'\bPlayProject\b', line):
                    return True
            build_file.close()
        except:
            return False

    def _find_in_project(self, filename):
        for path, _, files in os.walk(self.project_root()):
            if filename in files:
                return os.path.join(path, filename)
class Project(OnePerWindow):
    def __init__(self, window):
        self.window = window
        self.settings = SBTSettings(window)
        self.error_report = ErrorReport()
        self.error_reporter = ErrorReporter(window, self.error_report,
                                            self.settings)

    def project_root(self):
        for folder in self.window.folders():
            if self._is_sbt_folder(folder):
                return folder

    def is_sbt_project(self):
        return self.project_root() is not None

    def is_play_project(self):
        for root in maybe(self.project_root()):
            if self._play_build_files(root):
                return True

    def sbt_command(self):
        if self.is_play_project():
            return self.settings.play_command()
        else:
            return self.settings.sbt_command()

    def setting(self, name):
        return self.settings.get(name)

    def expand_filename(self, filename):
        if len(os.path.dirname(filename)) > 0:
            return filename
        else:
            return self._find_in_project(filename)

    def relative_path(self, filename):
        return os.path.relpath(filename, self.project_root())

    def open_project_file(self, filename, line):
        full_path = os.path.join(self.project_root(), filename)
        self.window.open_file('%s:%i' % (full_path, line),
                              sublime.ENCODED_POSITION)

    def _is_sbt_folder(self, folder):
        if self._sbt_build_files(folder) or self._scala_build_files(folder):
            return True

    def _sbt_build_files(self, folder):
        return glob(os.path.join(folder, '*.sbt'))

    def _scala_build_files(self, folder):
        return glob(os.path.join(folder, 'project', '*.scala'))

    def _play_build_files(self, folder):
        return list(
            filter(self._is_play_build, self._scala_build_files(folder)))

    def _is_play_build(self, build_path):
        try:
            with open(build_path, 'r') as build_file:
                for line in build_file.readlines():
                    if re.search(r'\b(?:play\.|Play)Project\b', line):
                        return True
        except:
            return False

    def _find_in_project(self, filename):
        for path, _, files in os.walk(self.project_root()):
            if filename in files:
                return os.path.join(path, filename)
Beispiel #6
0
class SbtView(object):

    sbt_views = {}

    @classmethod
    def get_sbt_view(cls, window):
        if window.id() not in cls.sbt_views:
            cls.sbt_views[window.id()] = SbtView(window)
        return cls.sbt_views[window.id()]

    @classmethod
    def is_sbt_view(cls, view):
        if view is not None:
            for window in maybe(view.window()):
                sbt_view = cls.get_sbt_view(window)
                return sbt_view.panel.id() == view.id()

    def __init__(self, window):
        self.window = window
        self.settings = SBTSettings(window)
        self.panel = self.window.get_output_panel('sbt')
        self._update_panel_colors()
        self.settings.add_on_change(self._update_panel_colors)
        self._output_size = 0
        self._set_running(False)

    def start(self):
        self.clear_output()
        self.show()
        self._set_running(True)

    def finish(self):
        self.show_output('\n -- Finished --\n')
        self._set_running(False)

    def show(self):
        self._update_panel_colors()
        self.window.run_command('show_panel', {'panel': 'output.sbt'})

    def hide(self):
        self.window.run_command('hide_panel', {'panel': 'output.sbt'})

    def focus(self):
        self.window.focus_view(self.panel)
        self.panel.show(self.panel.size())

    def show_output(self, output):
        output = self._clean_output(output)
        self.show()
        self._append_output(output)
        self._output_size = self.panel.size()
        self.panel.show(self.panel.size())

    def clear_output(self):
        self._erase_output(sublime.Region(0, self.panel.size()))

    def take_input(self):
        input_region = sublime.Region(self._output_size, self.panel.size())
        input = self.panel.substr(input_region)
        self._erase_output(input_region)
        return input

    def delete_left(self):
        if self.panel.sel()[0].begin() > self._output_size:
            self.panel.run_command('left_delete')

    def delete_bol(self):
        if self.panel.sel()[0].begin() >= self._output_size:
            p = self.panel.sel()[-1].end()
            self._erase_output(sublime.Region(self._output_size, p))

    def delete_word_left(self):
        if self.panel.sel()[0].begin() > self._output_size:
            for r in self.panel.sel():
                p = max(self.panel.word(r).begin(), self._output_size)
                self.panel.sel().add(sublime.Region(p, r.end()))
            self._erase_output(*self.panel.sel())

    def delete_word_right(self):
        if self.panel.sel()[0].begin() >= self._output_size:
            for r in self.panel.sel():
                p = self.panel.word(r).end()
                self.panel.sel().add(sublime.Region(r.begin(), p))
            self._erase_output(*self.panel.sel())

    def update_writability(self):
        self.panel.set_read_only(not self._running or
                                 self.panel.sel()[0].begin() < self._output_size)

    def _set_running(self, running):
        self._running = running
        self.update_writability()

    def _append_output(self, output):
        edit = self._begin_edit()
        for i, s in enumerate(output.split('\r')):
            if i > 0:
                self.panel.replace(edit, self.panel.line(self.panel.size()), s)
            else:
                self.panel.insert(edit, self.panel.size(), s)
        self._end_edit(edit)

    def _begin_edit(self):
        self.panel.set_read_only(False)
        return self.panel.begin_edit()

    def _end_edit(self, edit):
        self.panel.end_edit(edit)
        self.update_writability()

    def _erase_output(self, *regions):
        edit = self._begin_edit()
        for r in reversed(regions):
            self.panel.erase(edit, r)
        self._end_edit(edit)

    def _clean_output(self, output):
        return self._strip_codes(self._normalize_lines(output))

    def _normalize_lines(self, output):
        return output.replace('\r\n', '\n').replace('\033M\033[2K', '\r')

    def _strip_codes(self, output):
        return re.sub('\\033\[[0-9;]+m', '', output)

    def _update_panel_colors(self):
        self.panel.settings().set('color_scheme', self.settings.get('color_scheme'))
Beispiel #7
0
class Project(OnePerWindow):

    def __init__(self, window):
        self.window = window
        self.settings = SBTSettings(window)
        self.error_report = ErrorReport()
        self.error_reporter = ErrorReporter(window,
                                            self.error_report,
                                            self.settings)

    def project_root(self):
        for folder in self.window.folders():
            if self._is_sbt_folder(folder):
                return folder

    def is_sbt_project(self):
        return self.project_root() is not None

    def is_play_project(self):
        for root in maybe(self.project_root()):
            if self._play_build_files(root):
                return True

    def sbt_command(self):
        if self.is_play_project():
            return self.settings.play_command()
        else:
            return self.settings.sbt_command()

    def setting(self, name):
        return self.settings.get(name)

    def expand_filename(self, filename):
        if len(os.path.dirname(filename)) > 0:
            return filename
        else:
            return self._find_in_project(filename)

    def relative_path(self, filename):
        return os.path.relpath(filename, self.project_root())

    def open_project_file(self, filename, line):
        full_path = os.path.join(self.project_root(), filename)
        self.window.open_file('%s:%i' % (full_path, line),
                              sublime.ENCODED_POSITION)

    def _is_sbt_folder(self, folder):
        if self._sbt_build_files(folder) or self._scala_build_files(folder):
            return True

    def _sbt_build_files(self, folder):
        return glob(os.path.join(folder, '*.sbt'))

    def _scala_build_files(self, folder):
        return glob(os.path.join(folder, 'project', '*.scala'))

    def _play_build_files(self, folder):
        return list(filter(self._is_play_build, self._scala_build_files(folder)))

    def _is_play_build(self, build_path):
        try:
            with open(build_path, 'r') as build_file:
                for line in build_file.readlines():
                    if re.search(r'\b(?:play\.|Play)Project\b', line):
                        return True
        except:
            return False

    def _find_in_project(self, filename):
        for path, _, files in os.walk(self.project_root()):
            if filename in files:
                return os.path.join(path, filename)