Esempio n. 1
0
    def tscomplete(self, args):
        line = self.vim.current.window.cursor[0]
        col = self.vim.current.window.cursor[1] + 1
        file = self.relative_file()

        if len(args) > 1:
            prefix = args[0]
            col = args[1][0]
        else:
            prefix = args
        self.reload()

        data = client.completions(file, line, col, prefix)
        if len(data) == 0:
            return []

        if len(data) > self.vim.vars["nvim_typescript#max_completion_detail"]:
            filtered = []
            for entry in data:
                if entry["kind"] != "warning":
                    filtered.append(entry)
            return [
                utils.convert_completion_data(e, self.vim) for e in filtered
            ]
        names = []
        for entry in data:
            if (entry["kind"] != "warning"):
                names.append(entry["name"])
        detailed_data = client.completion_entry_details(file, line, col, names)
        if len(detailed_data) == 0:
            return []
        return [
            utils.convert_detailed_completion_data(e, self.vim)
            for e in detailed_data
        ]
Esempio n. 2
0
    def tsomnifunc(self, args):

        line = self.vim.eval("line('.')")
        col = self.vim.eval("col('.')")

        if args[0]:
            line_str = self.vim.current.line
            m = re.search(r"\w*$", line_str)
            return m.start() if m else -1

        else:

            prefix = args[1]
            file = self.relative_file()

            if self._client.server_handle is not None:

                if time(
                ) - self._last_input_reload > RELOAD_INTERVAL or re.search(
                        r"\w*\.", args[1]):
                    self._last_input_reload = time()
                    self.reload()

                data = self._client.completions(file, line, col, prefix)
                self.log(data)
                if len(data) == 0:
                    return []

                if len(data) > self.vim.vars[
                        "nvim_typescript#max_completion_detail"]:
                    filtered = []
                    for entry in data:
                        if entry["kind"] != "warning":
                            filtered.append(entry)
                        return [
                            utils.convert_completion_data(e, self.vim)
                            for e in filtered
                        ]

                names = []
                for entry in data:
                    if (entry["kind"] != "warning"):
                        names.append(entry["name"])

                detailed_data = self._client.completion_entry_details(
                    file, line, col, names)

                if len(detailed_data) == 0:
                    return []

                return [
                    utils.convert_detailed_completion_data(e,
                                                           self.vim,
                                                           isDeoplete=False)
                    for e in detailed_data
                ]
Esempio n. 3
0
    def gather_candidates(self, context):
        """
        Main deoplete method
        returns completions from client.py
        """
        # reload if last reload expired or input completion is a method extraction
        # pylint: disable=locally-disabled, line-too-long

        try:

            if time() - self._last_input_reload > RELOAD_INTERVAL or re.search(
                    r"\w*\.", context["input"]):
                self._last_input_reload = time()
                self.reload()

            data = self._client.completions(
                file=self.relative_file(),
                line=context["position"][1],
                offset=context["complete_position"] + 1,
                prefix=context["complete_str"])
            # self.log(data)
            if len(data) == 0:
                return []

            if len(data) > self._max_completion_detail:
                filtered = []
                for entry in data:
                    if entry["kind"] != "warning":
                        filtered.append(entry)
                return [convert_completion_data(e, self.vim) for e in filtered]

            names = []
            maxNameLength = 0

            for entry in data:
                if entry["kind"] != "warning":
                    names.append(entry["name"])
                    maxNameLength = max(maxNameLength, len(entry["name"]))

            detailed_data = self._client.completion_entry_details(
                file=self.relative_file(),
                line=context["position"][1],
                offset=context["complete_position"] + 1,
                entry_names=names)

            if len(detailed_data) == 0:
                return []

            return [
                convert_detailed_completion_data(e, self.vim, isDeoplete=True)
                for e in detailed_data
            ]
        except:
            e = sys.exc_info()[0]
            error(self.vim, "<p>Error: %s</p>" % e)
            return []
    def gather_candidates(self, context):
        """
        Main deoplete method
        returns completions from client.py
        """
        # reload if last reload expired or input completion is a method extraction
        # pylint: disable=locally-disabled, line-too-long

        try:
            if time() - self._last_input_reload > RELOAD_INTERVAL or re.search(r"\w*\.", context["input"]):
                self._last_input_reload = time()
                self.reload()

            data = self._client.completions(
                file=self.relative_file(),
                line=context["position"][1],
                offset=context["complete_position"] + 1,
                prefix=context["complete_str"]
            )
            # self.log(data)
            if len(data) == 0:
                return []

            if len(data) > self._max_completion_detail:
                filtered = []
                for entry in data:
                    if entry["kind"] != "warning":
                        filtered.append(entry)
                return [convert_completion_data(e, self.vim) for e in filtered]

            names = []
            maxNameLength = 0

            for entry in data:
                if entry["kind"] != "warning":
                    names.append(entry["name"])
                    maxNameLength = max(maxNameLength, len(entry["name"]))

            detailed_data = self._client.completion_entry_details(
                file=self.relative_file(),
                line=context["position"][1],
                offset=context["complete_position"] + 1,
                entry_names=names
            )

            if len(detailed_data) == 0:
                return []

            return [convert_detailed_completion_data(e, self.vim, isDeoplete=True) for e in detailed_data]
        except:
        #     e = sys.exc_info()[0]
        #     error(self.vim, "<p>Error: %s</p>" % e)
            return []
Esempio n. 5
0
 def tsomnifunc(self, args):
     line_str = self.vim.current.line
     line, offset = self.vim.current.window.cursor
     if args[0]:
         while offset > 0 and re.match('[\w\d]', line_str[offset - 1]):
             offset -= 1
         return offset
     else:
         if self._client.server_handle is not None:
             if time(
             ) - self._last_input_reload > RELOAD_INTERVAL or re.search(
                     r"\w*\.", args[1]):
                 self._last_input_reload = time()
                 self.reload()
             data = self._client.completions(self.relative_file(), line,
                                             offset + 1, args[1])
             if len(data) == 0:
                 return []
             if len(data) > self.vim.vars[
                     "nvim_typescript#max_completion_detail"]:
                 filtered = []
                 for entry in data:
                     if entry["kind"] != "warning":
                         filtered.append(entry)
                 return [
                     utils.convert_completion_data(e, self.vim)
                     for e in filtered
                 ]
             names = []
             for entry in data:
                 if (entry["kind"] != "warning"):
                     names.append(entry["name"])
             detailed_data = self._client.completion_entry_details(
                 self.relative_file(), line, offset + 1, names)
             if len(detailed_data) == 0:
                 return []
             return [
                 utils.convert_detailed_completion_data(e,
                                                        self.vim,
                                                        isDeoplete=False)
                 for e in detailed_data
             ]
    def tsomnifunc(self, args):
        """
        Omni func for completion
        """

        line = self.vim.eval("line('.')")
        col = self.vim.eval("col('.')")
        if args[0]:
            line_str = self.vim.current.line
            m = re.search(r"\w*$", line_str)
            return m.start() if m else -1
        else:
            prefix = args[1]
            file = self.relative_file()
            if self._client.server_handle is not None:
                if time() - self._last_input_reload > RELOAD_INTERVAL or re.search(r"\w*\.", args[1]):
                    self._last_input_reload = time()
                    self.reload()
                data = self._client.completions(file, line, col, prefix)
                if len(data) == 0:
                    return []
                if len(data) > self.vim.vars["nvim_typescript#max_completion_detail"]:
                    filtered = []
                    for entry in data:
                        if entry["kind"] != "warning":
                            filtered.append(entry)
                        return [utils.convert_completion_data(e, self.vim) for e in filtered]
                names = []
                for entry in data:
                    if (entry["kind"] != "warning"):
                        names.append(entry["name"])
                detailed_data = self._client.completion_entry_details(
                    file, line, col, names)
                if len(detailed_data) == 0:
                    return []
                return [utils.convert_detailed_completion_data(e, self.vim, isDeoplete=False) for e in detailed_data]
Esempio n. 7
0
    def on_cm_refresh(self, args):
        info = args[0]
        ctx = args[1]

        lnum = ctx['lnum']
        col = ctx['col']
        base = ctx['base']
        startcol = ctx['startcol']

        # recheck
        if self.vim.call('cm#context_changed', ctx):
            return

        max_detail = self.vim.vars["nvim_typescript#max_completion_detail"]

        self.reload()

        data = self._client.completions(file=self.relative_file(),
                                        line=lnum,
                                        offset=col,
                                        prefix=base)

        if len(data) == 0:
            return []

        matches = []
        if len(data) > max_detail:
            filtered = []
            for entry in data:
                if entry["kind"] != "warning":
                    filtered.append(entry)
            matches = [
                utils.convert_completion_data(e, self.vim) for e in filtered
            ]
            self.vim.call('cm#complete', info, ctx, startcol, matches)
            return

        names = []
        maxNameLength = 0

        for entry in data:
            if entry["kind"] != "warning":
                names.append(entry["name"])
                maxNameLength = max(maxNameLength, len(entry["name"]))

        detailed_data = self._client.completion_entry_details(
            file=self.relative_file(),
            line=lnum,
            offset=col,
            entry_names=names)

        if len(detailed_data) == 0:
            return

        matches = [
            utils.convert_detailed_completion_data(e,
                                                   self.vim,
                                                   isDeoplete=True)
            for e in detailed_data
        ]
        self.vim.call('cm#complete', info, ctx, startcol, matches)
    def on_cm_refresh(self, args):
        """
        For ncm
        """
        info = args[0]
        ctx = args[1]

        lnum = ctx['lnum']
        col = ctx['col']
        base = ctx['base']
        startcol = ctx['startcol']

        # recheck
        if self.vim.call('cm#context_changed', ctx):
            return

        max_detail = self.vim.vars["nvim_typescript#max_completion_detail"]

        self.reload()

        data = self._client.completions(
            file=self.relative_file(),
            line=lnum,
            offset=col,
            prefix=base
        )

        if len(data) == 0:
            return []

        matches = []
        if len(data) > max_detail:
            filtered = []
            for entry in data:
                if entry["kind"] != "warning":
                    filtered.append(entry)
            matches = [
                utils.convert_completion_data(e, self.vim)
                for e in filtered]
            self.vim.call('cm#complete', info, ctx, startcol, matches)
            return

        names = []
        maxNameLength = 0

        for entry in data:
            if entry["kind"] != "warning":
                names.append(entry["name"])
                maxNameLength = max(maxNameLength, len(entry["name"]))

        detailed_data = self._client.completion_entry_details(
            file=self.relative_file(),
            line=lnum,
            offset=col,
            entry_names=names
        )

        if len(detailed_data) == 0:
            return

        matches = [
            utils.convert_detailed_completion_data(e,
                                                   self.vim,
                                                   isDeoplete=True)
            for e in detailed_data]
        self.vim.call('cm#complete', info, ctx, startcol, matches)