def _item_format(self, item):
     text = item['type']
     if item['tail'] == 'position':
         text += " (*tail-position*)"
     if item['tail'] == 'call':
         text += " (*tail-call*)"
     return clean_whitespace(text)
    def show_errors(self, view):
        """
        Show a simple gutter icon for each parsing error.
        """

        view.erase_regions('ocaml-underlines-errors')

        errors = merlin_view(view).report_errors()

        error_messages = []
        underlines = []
        for e in errors:
            if 'start' in e and 'end' in e:
                pos_start = e['start']
                pos_stop = e['end']
                pnt_start = merlin_pos(view, pos_start)
                pnt_stop = merlin_pos(view, pos_stop)
                r = sublime.Region(pnt_start, pnt_stop)
                line_r = view.full_line(r)
                line_r = sublime.Region(line_r.a - 1, line_r.b)
                underlines.append(r)

                # Remove line and character number
                message = clean_whitespace(e['message'])
                error_messages.append((line_r, message))

        self.error_messages = error_messages
        flag = sublime.PERSISTENT | sublime.DRAW_SOLID_UNDERLINE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
        # add_regions(key, regions, scope, icon, flags)
        view.add_regions('ocaml-underlines-errors', underlines, 'invalid',
                         self.gutter_icon_path(), flag)
 def _item_format(self, item):
     text = item['type']
     if item['tail'] == 'position':
         text += " (*tail-position*)"
     if item['tail'] == 'call':
         text += " (*tail-call*)"
     return clean_whitespace(text)
    def on_query_completions(self, view, prefix, locations):
        """ Sublime autocomplete event handler. """

        # Expand the prefix with dots
        l = locations[0]
        line = view.substr(sublime.Region(view.line(l).a, l))

        try:
            prefix = re.findall(r"(([\w.]|->)+)", line)[-1][0]
        except IndexError:
            prefix = ""

        process = merlin_process(view.file_name())
        process.sync_buffer_to_cursor(view)

        default_return = ([], sublime.INHIBIT_WORD_COMPLETIONS)

        if self.cplns_ready:
            self.cplns_ready = None
            if self.completions:
                cplns, self.completions = self.completions, []
                return cplns

            return default_return

        if self.cplns_ready is None:
            self.cplns_ready = False
            line, col = view.rowcol(locations[0])
            result = process.complete_cursor(prefix, line + 1, col)
            self.cplns = [(clean_whitespace(r['name'] + '\t' + r['desc']), r['name']) for r in result['entries']]

            self.show_completions(view, self.cplns)

        return default_return
    def on_query_completions(self, view, prefix, locations):
        """ Sublime autocomplete event handler. """

        # Expand the prefix with dots
        l = locations[0]
        line = view.substr(sublime.Region(view.line(l).a, l))

        try:
            prefix = re.findall(r"(([\w.]|->)+)", line)[-1][0]
        except IndexError:
            prefix = ""

        merlin = merlin_view(view)
        merlin.sync()

        default_return = ([], sublime.INHIBIT_WORD_COMPLETIONS)

        if self.cplns_ready:
            self.cplns_ready = None
            if self.completions:
                cplns, self.completions = self.completions, []
                return cplns

            return default_return

        if self.cplns_ready is None:
            self.cplns_ready = False
            line, col = view.rowcol(locations[0])
            result = merlin.complete_cursor(prefix, line + 1, col)

            self.cplns = []
            for r in result['entries']:
                name = clean_whitespace(r['name'])
                desc = clean_whitespace(r['desc'])
                self.cplns.append(((name + '\t' + desc), name))

            self.show_completions(view, self.cplns)

        return default_return
    def on_query_completions(self, view, prefix, locations):
        """ Sublime autocomplete event handler. """

        # Expand the prefix with dots
        l = locations[0]
        line = view.substr(sublime.Region(view.line(l).a, l))

        try:
            prefix = re.findall(r"(([\w.]|->)+)", line)[-1][0]
        except IndexError:
            prefix = ""

        merlin = merlin_view(view)
        merlin.sync()

        default_return = ([], sublime.INHIBIT_WORD_COMPLETIONS)

        if self.cplns_ready:
            self.cplns_ready = None
            if self.completions:
                cplns, self.completions = self.completions, []
                return cplns

            return default_return

        if self.cplns_ready is None:
            self.cplns_ready = False
            line, col = view.rowcol(locations[0])
            result = merlin.complete_cursor(prefix, line + 1, col)

            self.cplns = []
            for r in result['entries']:
                name = clean_whitespace(r['name'])
                desc = clean_whitespace(r['desc'])
                self.cplns.append(((name + '\t' + desc), name))

            self.show_completions(view, self.cplns)

        return default_return