Beispiel #1
0
class QCompleter(Completer):
    """Completer for the q language"""
    def __init__(self):
        namespace = q(r'\d')
        res = q('.Q.res')
        dot_q = q('1_key .q')
        self.path_completer = PathCompleter()
        self.words_info = [(list(res), 'k'), (list(dot_q), 'q'),
                           (list(q.key(namespace)), str(namespace))]

    def get_completions(self, document, complete_event):
        """Yield completions"""
        # Detect a file handle
        m = HSYM_RE.match(document.text_before_cursor)
        if m:
            text = m.group(1)
            doc = Document(text, len(text))
            for c in self.path_completer.get_completions(doc, complete_event):
                yield c
        else:
            # Get word/text before cursor.
            word_before_cursor = document.get_word_before_cursor(False)
            for words, meta in self.words_info:
                for a in words:
                    if a.startswith(word_before_cursor):
                        yield Completion(a,
                                         -len(word_before_cursor),
                                         display_meta=meta)
Beispiel #2
0
 def get_path_matches(self, _, word_before_cursor):
     completer = PathCompleter(expanduser=True)
     document = Document(text=word_before_cursor,
                         cursor_position=len(word_before_cursor))
     for c in completer.get_completions(document, None):
         yield Match(completion=c, priority=(0, ))
Beispiel #3
0
 def get_path_matches(self, _, word_before_cursor):
     completer = PathCompleter(expanduser=True)
     document = Document(text=word_before_cursor,
                         cursor_position=len(word_before_cursor))
     for c in completer.get_completions(document, None):
         yield Match(completion=c, priority=(0,))