Beispiel #1
0
    def complete(self, code, cursor_pos):
        NO_SUGGESTIONS = {
            'matches': [],
            'cursor_end': cursor_pos,
            'cursor_start': cursor_pos,
            'metadata': {},
            'status': 'ok',
        }
        prev_char = code[cursor_pos - 1:cursor_pos]

        if prev_char in string.whitespace:
            return NO_SUGGESTIONS

        m = self.parse(code, cursor_pos)
        if m is None:
            return NO_SUGGESTIONS

        matches = []

        if isinstance(m, Standalone):
            matches += self.complete_keyword(m.value)
            matches += self.complete_local_identifier(code, m.value)
            matches += self.complete_global_variable(m.value)

        elif isinstance(m, ConstantMethod):
            matches += self.complete_obj_method(m.const, m.prefix)

        elif isinstance(m, ObjectIndexedComplete):
            return NO_SUGGESTIONS

        elif hasattr(m, 'names_chain'):
            names_chain = self.lua.table_from(m.names_chain)

            if isinstance(m, ObjectAttribute):
                matches += self.complete_any_attribute(names_chain, m.prefix)

            if isinstance(m, ObjectAttributeIndexed):
                matches += [
                    "%s%s]" % (el, m.quote)
                    for el in self.complete_any_attribute(
                        names_chain, m.prefix)
                ]

            elif isinstance(m, ObjectMethod):
                matches += self.complete_method(names_chain, m.prefix)

            elif isinstance(m, SplashMethod):
                matches += [
                    el for el in self.complete_method(names_chain, m.prefix)
                    if el not in DONT_SUGGEST_METHODS
                ]

            elif isinstance(m, SplashAttribute):
                matches += [
                    el
                    for el in self.complete_non_method(names_chain, m.prefix)
                    if not el.startswith("_")
                ]

        return {
            'matches': list(dedupe(matches)),
            'cursor_end': cursor_pos,
            'cursor_start': cursor_pos - len(getattr(m, "prefix", "")),
            'metadata': {},
            'status': 'ok',
        }
Beispiel #2
0
    def complete(self, code, cursor_pos):
        NO_SUGGESTIONS = {
            'matches': [],
            'cursor_end': cursor_pos,
            'cursor_start': cursor_pos,
            'metadata': {},
            'status': 'ok',
        }
        prev_char = code[cursor_pos-1:cursor_pos]

        if prev_char in string.whitespace:
            return NO_SUGGESTIONS

        m = self.parse(code, cursor_pos)
        if m is None:
            return NO_SUGGESTIONS

        matches = []

        if isinstance(m, Standalone):
            matches += self.complete_keyword(m.value)
            matches += self.complete_local_identifier(code, m.value)
            matches += self.complete_global_variable(m.value)

        elif isinstance(m, ConstantMethod):
            matches += self.complete_obj_method(m.const, m.prefix)

        elif isinstance(m, ObjectIndexedComplete):
            return NO_SUGGESTIONS

        elif hasattr(m, 'names_chain'):
            names_chain = self.lua.table_from(m.names_chain)

            if isinstance(m, ObjectAttribute):
                matches += self.complete_any_attribute(names_chain, m.prefix)

            if isinstance(m, ObjectAttributeIndexed):
                matches += [
                    "%s%s]" % (el, m.quote)
                    for el in self.complete_any_attribute(names_chain, m.prefix)
                ]

            elif isinstance(m, ObjectMethod):
                matches += self.complete_method(names_chain, m.prefix)

            elif isinstance(m, SplashMethod):
                matches += [
                    el for el in self.complete_method(names_chain, m.prefix)
                    if "private" not in el
                ]

            elif isinstance(m, SplashAttribute):
                matches += [
                    el for el in self.complete_non_method(names_chain, m.prefix)
                    if not el.startswith("_")
                ]

        return {
            'matches': list(dedupe(matches)),
            'cursor_end': cursor_pos,
            'cursor_start': cursor_pos - len(getattr(m, "prefix", "")),
            'metadata': {},
            'status': 'ok',
        }