Ejemplo n.º 1
0
    def __call__(self, results):
        with editor_context.autocomplete_context as actx:

            formatted = []
            item = ''
            for c in results.results:
                if not c.element:
                    continue
                if c.element.kind == ElementKind.FUNCTION or c.element.kind == ElementKind.METHOD or c.element.kind == ElementKind.SETTER:
                    # TODO(guillermooo): insert only req params.
                    # formatted.append([_FUNCTION.format(c.completion, c.element.parameters, c.returnType), c.completion + '(${1:%s})$0' % c.element.parameters[1:c.requiredParameterCount]])
                    formatted.append([self._FUNCTION.format(c.completion, c.element.parameters, c.returnType), c.completion + '(${1:%s})$0' % c.element.parameters[1:-1]])
                elif c.element.kind == ElementKind.GETTER or c.element.kind == ElementKind.FIELD:
                    formatted.append([self._PROPERTY.format(c.completion, c.returnType), c.completion])
                elif c.element.kind == ElementKind.CONSTRUCTOR:
                    formatted.append([self._CONSTRUCTOR.format(c.completion) + c.element.parameters, c.completion + '(${1:%s})$0' % c.element.parameters[1:-1]])
                else:
                    formatted.append([self._OTHER.format(c.completion), c.completion])

            actx.set_results(get_active_view(), results.results)
            actx.formatted_results = formatted

            if not actx.results:
                return

        v = get_active_view()
        if v:
            v.run_command('auto_complete')
Ejemplo n.º 2
0
def clear_ui():
    '''Remove UI decoration.
    '''
    _logger.debug('erasing errors from view')
    v = get_active_view()
    v.erase_regions(DAS_UI_REGIONS_ERRORS)
    v.erase_regions(DAS_UI_REGIONS_WARNINGS)
    v.erase_regions(DAS_UI_REGIONS_INFOS)
Ejemplo n.º 3
0
def clear_ui():
    '''Remove UI decoration.
    '''
    _logger.debug('erasing errors from view')
    v = get_active_view()
    v.erase_regions(DAS_UI_REGIONS_ERRORS)
    v.erase_regions(DAS_UI_REGIONS_WARNINGS)
    v.erase_regions(DAS_UI_REGIONS_INFOS)
Ejemplo n.º 4
0
    def __call__(self, results):
        with editor_context.autocomplete_context as actx:

            formatted = []
            item = ''
            for c in results.results:
                if not c.element:
                    continue
                if c.element.kind == ElementKind.FUNCTION or c.element.kind == ElementKind.METHOD or c.element.kind == ElementKind.SETTER:
                    # TODO(guillermooo): insert only req params.
                    # formatted.append([_FUNCTION.format(c.completion, c.element.parameters, c.returnType), c.completion + '(${1:%s})$0' % c.element.parameters[1:c.requiredParameterCount]])
                    formatted.append([
                        self._FUNCTION.format(c.completion,
                                              c.element.parameters,
                                              c.returnType), c.completion +
                        '(${1:%s})$0' % c.element.parameters[1:-1]
                    ])
                elif c.element.kind == ElementKind.GETTER or c.element.kind == ElementKind.FIELD:
                    formatted.append([
                        self._PROPERTY.format(c.completion, c.returnType),
                        c.completion
                    ])
                elif c.element.kind == ElementKind.CONSTRUCTOR:
                    formatted.append([
                        self._CONSTRUCTOR.format(c.completion) +
                        c.element.parameters, c.completion +
                        '(${1:%s})$0' % c.element.parameters[1:-1]
                    ])
                else:
                    formatted.append(
                        [self._OTHER.format(c.completion), c.completion])

            actx.set_results(get_active_view(), results.results)
            actx.formatted_results = formatted

            if not actx.results:
                return

        v = get_active_view()
        if v:
            v.run_command('auto_complete')
Ejemplo n.º 5
0
def handle_formatting(result):
    v = get_active_view()

    v.sel().clear()

    for edit in result.edits:
        v.run_command('dart_replace_region', {
            'region': [edit.offset, edit.length],
            'text': edit.replacement
        })

    r = sublime.Region(result.selectionOffset,
                       result.selectionOffset + result.selectionLength)
    v.sel().add(r)
Ejemplo n.º 6
0
def handle_formatting(result):
    v = get_active_view()

    v.sel().clear()

    for edit in result.edits:
        v.run_command('dart_replace_region', {
            'region': [edit.offset, edit.length],
            'text': edit.replacement
            })

    r = sublime.Region(result.selectionOffset,
            result.selectionOffset + result.selectionLength)
    v.sel().add(r)
Ejemplo n.º 7
0
def handle_completions(results):
    show = False
    with editor_context.autocomplete_context as actx:

        _PROPERTY = '\u25CB {} \u2192 {}'
        _FUNCTION = '\u25BA {}{} \u2192 {}'
        _CONSTRUCTOR = '\u00A9 {}'
        _OTHER = '· {}'

        formatted = []
        item = ''
        for c in results.results:
            if not c.element:
                continue
            if c.element.kind == ElementKind.FUNCTION or c.element.kind == ElementKind.METHOD or c.element.kind == ElementKind.SETTER:
                # TODO(guillermooo): insert only req params.
                # formatted.append([_FUNCTION.format(c.completion, c.element.parameters, c.returnType), c.completion + '(${1:%s})$0' % c.element.parameters[1:c.requiredParameterCount]])
                formatted.append([
                    _FUNCTION.format(c.completion, c.element.parameters,
                                     c.returnType),
                    c.completion + '(${1:%s})$0' % c.element.parameters[1:-1]
                ])
            elif c.element.kind == ElementKind.GETTER or c.element.kind == ElementKind.FIELD:
                formatted.append([
                    _PROPERTY.format(c.completion, c.returnType), c.completion
                ])
            elif c.element.kind == ElementKind.CONSTRUCTOR:
                formatted.append([
                    _CONSTRUCTOR.format(c.completion) + c.element.parameters,
                    c.completion + '(${1:%s})$0' % c.element.parameters[1:-1]
                ])
            else:
                formatted.append([_OTHER.format(c.completion), c.completion])

        actx.results = results.results
        actx.formatted_results = formatted

        if actx.results:
            show = True

    if not show:
        return

    v = get_active_view()
    if v:
        v.run_command('auto_complete')
Ejemplo n.º 8
0
    def make(self):
        """Makes `ServerResponse`s forever.
        """
        while True:
            try:
                data = self.server.responses.get()
            except queue.Empty:
                # unreachable?
                _logger.error("unexpected empty queue in ResponseMaker")
                yield
                continue
            else:
                if data.get("_internal"):
                    _logger.info("ResponseMaker exiting by internal request")
                    yield data
                    break

                view = get_active_view()
                if self.server.request_ids.validate(view, data):
                    yield self.make_request(view, data)
                    continue

                yield event_classifier(data)
Ejemplo n.º 9
0
    def make(self):
        '''Makes `ServerResponse`s forever.
        '''
        while True:
            try:
                data = self.server.responses.get()
            except queue.Empty:
                # unreachable?
                _logger.error('unexpected empty queue in ResponseMaker')
                yield
                continue
            else:
                if data.get('_internal'):
                    _logger.info('ResponseMaker exiting by internal request')
                    yield data
                    break

                view = get_active_view()
                if self.server.request_ids.validate(view, data):
                    yield self.make_request(view, data)
                    continue

                yield event_classifier(data)
Ejemplo n.º 10
0
def handle_completions(results):
    show = False
    with editor_context.autocomplete_context as actx:

        _PROPERTY = '\u25CB {} \u2192 {}'
        _FUNCTION = '\u25BA {}{} \u2192 {}'
        _CONSTRUCTOR = '\u00A9 {}'
        _OTHER = '· {}'

        formatted = []
        item = ''
        for c in results.results:
            if not c.element:
                continue
            if c.element.kind == ElementKind.FUNCTION or c.element.kind == ElementKind.METHOD or c.element.kind == ElementKind.SETTER:
                # TODO(guillermooo): insert only req params.
                # formatted.append([_FUNCTION.format(c.completion, c.element.parameters, c.returnType), c.completion + '(${1:%s})$0' % c.element.parameters[1:c.requiredParameterCount]])
                formatted.append([_FUNCTION.format(c.completion, c.element.parameters, c.returnType), c.completion + '(${1:%s})$0' % c.element.parameters[1:-1]])
            elif c.element.kind == ElementKind.GETTER or c.element.kind == ElementKind.FIELD:
                formatted.append([_PROPERTY.format(c.completion, c.returnType), c.completion])
            elif c.element.kind == ElementKind.CONSTRUCTOR:
                formatted.append([_CONSTRUCTOR.format(c.completion) + c.element.parameters, c.completion + '(${1:%s})$0' % c.element.parameters[1:-1]])
            else:
                formatted.append([_OTHER.format(c.completion), c.completion])

        actx.results = results.results
        actx.formatted_results = formatted

        if actx.results:
            show = True

    if not show:
        return

    v = get_active_view()
    if v:
        v.run_command('auto_complete')
Ejemplo n.º 11
0
    def __call__(self, errors):
        '''Show errors in the ui.

        @errors
          An instance of `ErrorInfoCollection`.
        '''
        view = get_active_view()

        # TODO(guillermooo): Use tokens to identify requests:file.
        if not self.compare_paths(errors.file, view.file_name()):
            _logger.debug('different view active - aborting')
            return

        panel = OutputPanel('dart.analyzer')

        analysis_errors = list(errors.errors)
        infos, warns, erros = self.group(analysis_errors)

        if len(infos + warns + erros) == 0:
            clear_ui()
            panel.hide()
            return

        info_regs = [self.error_to_region(view, item) for item in infos]
        warn_regs = [self.error_to_region(view, item) for item in warns]
        errs_regs = [self.error_to_region(view, item) for item in erros]

        _logger.debug('displaying errors to the user')

        self.add_regions(view, info_regs, warn_regs, errs_regs)

        all_sorted = sorted(infos + warns + erros,
                            key=lambda x: x.location.offset)
        all_errs = (self.to_compact_text(item) for item in all_sorted)

        # TODO(guillermooo): abstract out the panel stuff into a DartErrorPanel class.
        panel = OutputPanel('dart.analyzer')

        # Tried to use .sublime-settings for this, but it won't work well.
        errors_pattern = r'^\w+\|\w+\|(.+)\|(\d+)\|(\d+)\|(.+)$'
        panel.set('result_file_regex', errors_pattern)
        all_errs = list(all_errs)
        # Overwrite any previous text in the panel.

        # We get errors sometimes when writing error lines here.
        panel.write('\n'.join(all_errs))

        # TODO(guillermooo): remove this when .sublime-syntax has been fully
        # adopted.
        if sublime.version() >= '3084':
            panel.view.set_syntax_file(
                'Packages/Dart/Support/Analyzer Output.sublime-syntax')
        else:
            panel.view.set_syntax_file(
                'Packages/Dart/Support/Analyzer Output.tmLanguage')

        editor_context.errors = all_errs
        panel.show()

        try:
            view.show(view.sel()[0])
        except IndexError:
            pass

        sublime.status_message("Dart: Errors found")
Ejemplo n.º 12
0
 def send_get_version(self, view=None):
     view = get_active_view()
     req = ServerGetVersionParams().to_request(
         self.get_request_id(view, ServerGetVersionResult))
     _logger.info('sending get version request')
     self.requests.put(req, block=False)
Ejemplo n.º 13
0
 def send_get_version(self, view=None):
     view = get_active_view()
     req = ServerGetVersionParams().to_request(
             self.get_request_id(view, ServerGetVersionResult))
     _logger.info('sending get version request')
     self.requests.put(req, block=False)
Ejemplo n.º 14
0
    def __call__(self, errors):
        '''Show errors in the ui.

        @errors
          An instance of `ErrorInfoCollection`.
        '''
        view = get_active_view()

        # TODO(guillermooo): Use tokens to identify requests:file.
        if not self.compare_paths(errors.file, view.file_name()):
            _logger.debug('different view active - aborting')
            return

        panel = OutputPanel('dart.errors')

        analysis_errors = list(errors.errors)
        infos, warns, erros = self.group(analysis_errors)

        if len(infos + warns + erros) == 0:
            clear_ui()
            panel.hide()
            return

        info_regs = [self.error_to_region(view, item) for item in infos]
        warn_regs = [self.error_to_region(view, item) for item in warns]
        errs_regs = [self.error_to_region(view, item) for item in erros]

        _logger.debug('displaying errors to the user')

        self.add_regions(view, info_regs, warn_regs, errs_regs)

        all_sorted = sorted(infos + warns + erros, key=lambda x: x.location.offset)
        all_errs = (self.to_compact_text(item) for item in all_sorted)

        # TODO(guillermooo): abstract out the panel stuff into a DartErrorPanel class.
        panel = OutputPanel('dart.errors')

        # Tried to use .sublime-settings for this, but it won't work well.
        errors_pattern = r'^\w+\|\w+\|(.+)\|(\d+)\|(\d+)\|(.+)$'
        panel.set('result_file_regex', errors_pattern)
        all_errs = list(all_errs)
        # Overwrite any previous text in the panel.

        # We get errors sometimes when writing error lines here.
        panel.write('\n'.join(all_errs))

        # TODO(guillermooo): remove this when .sublime-syntax has been fully
        # adopted.
        if sublime.version() >= '3084':
            panel.view.set_syntax_file('Packages/Dart/Support/Analyzer Output.sublime-syntax')
        else:
            panel.view.set_syntax_file('Packages/Dart/Support/Analyzer Output.tmLanguage')

        editor_context.errors = all_errs
        # To show the panel, use the Command Palette or the key binding.
        # panel.show()

        try:
            view.show(view.sel()[0])
        except IndexError:
            pass

        sublime.status_message("Dart: Errors found")