Exemplo n.º 1
0
    def gather_candidates(self, context):
        line = context['position'][1]
        candidates = []

        # lines above
        words = parse_buffer_pattern(
            reversed(getlines(self.vim, max([1, line - LINES_ABOVE]), line)),
            context['keyword_patterns'],
            context['complete_str'])
        candidates += [{'word': x, 'menu': 'A'} for x in words]

        # grab ':changes' command output
        p = re.compile(r'[\s\d]+')
        lines = set()
        for change_line in [x[p.search(x).span()[1]:] for x
                            in self.vim.call(
                                'execute', 'changes').split('\n')
                            if p.search(x)]:
            if change_line and change_line != '-invalid-':
                lines.add(change_line)

        words = parse_buffer_pattern(lines,
                                     context['keyword_patterns'],
                                     context['complete_str'])
        candidates += [{'word': x, 'menu': 'C'} for x in words]

        # lines below
        words = parse_buffer_pattern(
            getlines(self.vim, line, line + LINES_BELOW),
            context['keyword_patterns'],
            context['complete_str'])
        candidates += [{'word': x, 'menu': 'B'} for x in words]

        return candidates
Exemplo n.º 2
0
    def gather_candidates(self, context):
        line = context['position'][1]
        candidates = []

        # lines above
        words = parse_buffer_pattern(
            reversed(getlines(self.vim, max([1, line - LINES_ABOVE]), line)),
            context['keyword_patterns'])
        candidates += [{'word': x, 'menu': 'A'} for x in words]

        # grab ':changes' command output
        p = re.compile(r'[\s\d]+')
        lines = set()
        for change_line in [x[p.search(x).span()[1]:] for x
                            in self.vim.call(
                                'execute', 'changes').split('\n')
                            if p.search(x)]:
            if change_line and change_line != '-invalid-':
                lines.add(change_line)

        words = parse_buffer_pattern(lines, context['keyword_patterns'])
        candidates += [{'word': x, 'menu': 'C'} for x in words]

        # lines below
        words = parse_buffer_pattern(
            getlines(self.vim, line, line + LINES_BELOW),
            context['keyword_patterns'])
        candidates += [{'word': x, 'menu': 'B'} for x in words]

        return candidates
Exemplo n.º 3
0
 def gather_candidates(self, context):
     return [{'word': x} for x in
             parse_buffer_pattern(
                 getlines(self.vim),
                 r'(?<=' + re.escape(self._prefix) + r')\w+'
             )
             if x != context['complete_str']]
Exemplo n.º 4
0
 def gather_candidates(self, context):
     if self.get_var('enable_buffer_pattern'):
         candidates = sorted(parse_buffer_pattern(
             self.vim.vars['denite#_candidates'],
             context['keyword_pattern']), key=str.lower)
     else:
         candidates = self.vim.vars['denite#_candidates']
     return [{'word': x} for x in candidates]
Exemplo n.º 5
0
 def gather_candidates(self, context):
     return [{'word': x} for x in
             parse_buffer_pattern(
                 self.vim.current.buffer[:],
                 r'(?<=' + re.escape(self.__prefix) + r')\w+(?:\(\)?)?',
                 context['complete_str']
             )
             if x != context['complete_str']]
Exemplo n.º 6
0
 def gather_candidates(self, context):
     return [{'word': x} for x in
             parse_buffer_pattern(
                 self.vim.current.buffer,
                 r'(?<=' + re.escape(self.__prefix) + r')\w+(?:\(\)?)?',
                 context['complete_str']
             )
             if x != context['complete_str']]
Exemplo n.º 7
0
    def gather_candidates(self, context: UserContext) -> Candidates:
        line = context['position'][1]
        candidates: Candidates = []

        # lines above
        words = parse_buffer_pattern(
            reversed(
                getlines(self.vim, max([1, line - self.vars['range_above']]),
                         line)),
            context['keyword_pattern'],
        )
        candidates += [{
            'word': x,
            'menu': self.vars['mark_above']
        } for x in words]

        # grab ':changes' command output
        p = re.compile(r'[\s\d]+')
        lines = set()
        for change_line in [
                x[p.search(x).span()[1]:]  # type: ignore
                for x in self.vim.call('execute', 'changes').split('\n')[2:]
                if p.search(x)
        ]:
            if change_line and change_line != '-invalid-':
                lines.add(change_line)

        words = parse_buffer_pattern(lines, context['keyword_pattern'])
        candidates += [{
            'word': x,
            'menu': self.vars['mark_changes']
        } for x in words]

        # lines below
        words = parse_buffer_pattern(
            getlines(self.vim, line, line + self.vars['range_below']),
            context['keyword_pattern'],
        )
        candidates += [{
            'word': x,
            'menu': self.vars['mark_below']
        } for x in words]

        return candidates
Exemplo n.º 8
0
    def gather_candidates(self, context):
        line = context['position'][1]
        candidates = []

        # lines above
        words = parse_buffer_pattern(
            reversed(
                getlines(
                    self.vim, max([1, line - self.vars['range_above']]), line
                )
            ),
            context['keyword_pattern'],
        )
        candidates += [
            {'word': x, 'menu': self.vars['mark_above']} for x in words
        ]

        # grab ':changes' command output
        p = re.compile(r'[\s\d]+')
        lines = set()
        for change_line in [
            x[p.search(x).span()[1]:]
            for x in self.vim.call('execute', 'changes').split('\n')[2:]
            if p.search(x)
        ]:
            if change_line and change_line != '-invalid-':
                lines.add(change_line)

        words = parse_buffer_pattern(lines, context['keyword_pattern'])
        candidates += [
            {'word': x, 'menu': self.vars['mark_changes']} for x in words
        ]

        # lines below
        words = parse_buffer_pattern(
            getlines(self.vim, line, line + self.vars['range_below']),
            context['keyword_pattern'],
        )
        candidates += [
            {'word': x, 'menu': self.vars['mark_below']} for x in words
        ]

        return candidates
Exemplo n.º 9
0
 def _make_cache(self, context: UserContext, bufnr: int) -> None:
     try:
         end = len(self.vim.buffers[bufnr])
         start = max([end - 5000, 1])
         return [{
             'word': x
         } for x in parse_buffer_pattern(
             self.vim.call('getbufline', bufnr, start, end),
             context['keyword_pattern'])]
     except:
         return []
Exemplo n.º 10
0
 def __make_cache(self, context, bufnr):
     try:
         self.__buffers[bufnr] = {
             'bufnr': bufnr,
             'filetype': self.vim.current.buffer.options['filetype'],
             'candidates': parse_buffer_pattern(
                 getlines(self.vim),
                 context['keyword_patterns'],
                 context['complete_str'])
         }
     except UnicodeDecodeError:
         return []
Exemplo n.º 11
0
 def __make_cache(self, context, buffer):
     bufnr = buffer.number
     try:
         if (bufnr in self.__buffers and context['event'] != 'BufWritePost'
                 and len(buffer) > self.__max_lines):
             line = context['position'][1]
             self.__buffers[bufnr]['candidates'] += parse_buffer_pattern(
                 buffer[max([0, line - 500]):line + 500],
                 context['keyword_patterns'], context['complete_str'])
             self.__buffers[bufnr]['candidates'] = list(
                 set(self.__buffers[bufnr]['candidates']))
         else:
             self.__buffers[bufnr] = {
                 'filetype':
                 context['filetype'],
                 'candidates':
                 parse_buffer_pattern(buffer, context['keyword_patterns'],
                                      context['complete_str'])
             }
     except UnicodeDecodeError:
         return []
Exemplo n.º 12
0
 def __make_cache(self, context, bufnr):
     try:
         self.__buffers[bufnr] = {
             'bufnr': bufnr,
             'filetype': context['filetype'],
             'candidates': parse_buffer_pattern(
                 getlines(self.vim),
                 context['keyword_patterns'],
                 context['complete_str'])
         }
     except UnicodeDecodeError:
         return []
Exemplo n.º 13
0
 def __make_cache(self, context):
     try:
         if (context['bufnr'] in self.__buffers and
                 context['event'] != 'BufWritePost' and
                 len(self.vim.current.buffer) > self.__max_lines):
             line = context['position'][1]
             buffer = self.__buffers[context['bufnr']]
             buffer['candidates'] += parse_buffer_pattern(
                     self.vim.current.buffer[max([0, line-500]):line+500],
                     context['keyword_patterns'],
                     context['complete_str'])
             buffer['candidates'] = list(set(buffer['candidates']))
         else:
             self.__buffers[context['bufnr']] = {
                 'filetype': context['filetype'],
                 'candidates': parse_buffer_pattern(
                     self.vim.current.buffer,
                     context['keyword_patterns'],
                     context['complete_str'])
             }
     except UnicodeDecodeError:
         return []
Exemplo n.º 14
0
 def __make_cache(self, context):
     try:
         if (context['bufnr'] in self.__buffers
                 and context['event'] != 'BufWritePost'
                 and len(self.vim.current.buffer) > self.__max_lines):
             line = context['position'][1]
             buffer = self.__buffers[context['bufnr']]
             buffer['candidates'] += parse_buffer_pattern(
                 getlines(self.vim, max([1, line - 500]), line + 500),
                 context['keyword_patterns'], context['complete_str'])
             buffer['candidates'] = list(set(buffer['candidates']))
         else:
             self.__buffers[context['bufnr']] = {
                 'filetype':
                 context['filetype'],
                 'candidates':
                 parse_buffer_pattern(getlines(self.vim),
                                      context['keyword_patterns'],
                                      context['complete_str'])
             }
     except UnicodeDecodeError:
         return []
Exemplo n.º 15
0
 def __make_cache(self, context, bufnr):
     try:
         self.__buffers[bufnr] = {
             'bufnr': bufnr,
             'filetype': self.vim.current.buffer.options['filetype'],
             'candidates': [
                 {'word': x} for x in
                 sorted(parse_buffer_pattern(getlines(self.vim),
                                             context['keyword_patterns']),
                        key=str.lower)
             ]
         }
     except UnicodeDecodeError:
         return []
Exemplo n.º 16
0
 def __make_cache(self, context, buffer):
     bufnr = buffer.number
     try:
         if (bufnr in self.__buffers and
                 context['event'] != 'BufWritePost' and
                 len(buffer) > self.__max_lines):
             line = context['position'][1]
             self.__buffers[bufnr][
                 'candidates'] += parse_buffer_pattern(
                     buffer[max([0, line-500]):line+500],
                     context['keyword_patterns'],
                     context['complete_str'])
             self.__buffers[bufnr]['candidates'] = list(
                 set(self.__buffers[bufnr]['candidates']))
         else:
             self.__buffers[bufnr] = {
                 'filetype': context['filetype'],
                 'candidates': parse_buffer_pattern(
                     buffer,
                     context['keyword_patterns'],
                     context['complete_str'])
             }
     except UnicodeDecodeError:
         return []
Exemplo n.º 17
0
 def gather_candidates(self, context):
     candidates = []
     pattern = re.compile('([A-Z][a-z]+)')
     keyword_pattern = self.vim.call(
             'deoplete#util#get_keyword_pattern',
             context['filetype'], self.keyword_patterns)
     keywords = parse_buffer_pattern(
         self.vim.current.buffer,
         keyword_pattern)
     for keyword in keywords:
         matches = re.findall(pattern, keyword)
         if len(matches) > 0:
             candidates.append(
                 {'word' : matches[0].lower() + ''.join(matches[1:])})
     return candidates
Exemplo n.º 18
0
 def _make_cache(self, context, bufnr):
     try:
         self._buffers[bufnr] = {
             'bufnr':
             bufnr,
             'filetype':
             self.vim.eval('&l:filetype'),
             'candidates': [{
                 'word': x
             } for x in sorted(parse_buffer_pattern(
                 getlines(self.vim), context['keyword_patterns']),
                               key=str.lower)]
         }
     except UnicodeDecodeError:
         return []
Exemplo n.º 19
0
    def _make_cache(self, context: UserContext) -> None:
        # Bufsize check
        size = self.vim.call('line2byte',
                             self.vim.call('line', '$') + 1) - 1
        if size > self._limit:
            return

        try:
            self._buffers[context['bufnr']] = {
                'bufnr': context['bufnr'],
                'filetype': self.get_buf_option('filetype'),
                'candidates': [
                    {'word': x} for x in
                    sorted(parse_buffer_pattern(getlines(self.vim),
                                                context['keyword_pattern']),
                           key=str.lower)
                ]
            }
        except UnicodeDecodeError:
            return
Exemplo n.º 20
0
    def _make_cache(self, context):
        # Bufsize check
        size = self.vim.call('line2byte',
                             self.vim.call('line', '$') + 1) - 1
        if size > self._limit:
            return

        try:
            self._buffers[context['bufnr']] = {
                'bufnr': context['bufnr'],
                'filetype': self.get_buf_option('filetype'),
                'candidates': [
                    {'word': x} for x in
                    sorted(parse_buffer_pattern(getlines(self.vim),
                                                context['keyword_pattern']),
                           key=str.lower)
                ]
            }
        except UnicodeDecodeError:
            return []
Exemplo n.º 21
0
    def _make_cache(self, context):
        # gather databases
        file_exists = os.path.isfile(CACHE_PICKLE)
        file_created_ago = 0
        if file_exists:
            file_created_ago = (
                datetime.datetime.now()
                - datetime.datetime.fromtimestamp(os.stat(CACHE_PICKLE).st_ctime)
            ).days

        if file_exists and file_created_ago < 1:
            self.vim.command("echo 'file already exists'")
            with open(CACHE_PICKLE, "rb") as f:
                self._cache = pickle.load(f)
        else:
            self._cache_db()
            #  th = threading.Thread(target=self._cache_db)
            #  th.start()
            #  if not file_exists:
            #      self.vim.command("echo 'waiting to write the file'")
            #      th.join()
        #
        # gather aliases
        alias_hits = parse_buffer_pattern(
            getlines(self.vim), r"(FROM|JOIN|from|join)\s+(\w+)[.](\w+)([.](\w*))?\s+(\w*)"
        )

        # clear existing aliases
        for table in self._cache["tables"]:
            self._cache["tables"][table]["aliases"] = []

        for alias_hit in alias_hits:
            table = alias_hit[4].upper() or alias_hit[2].upper()
            alias = alias_hit[5].upper()
            if table not in self._cache["tables"]:
                continue

            if alias not in self._cache["tables"][table]["aliases"]:
                self._cache["tables"][table]["aliases"].append(alias)
Exemplo n.º 22
0
    def _make_cache(self, context):
        # Bufsize check
        size = self.vim.call('line2byte',
                             self.vim.call('line', '$') + 1) - 1
        if size > self._limit:
            return

        keyword_pattern = self.vim.call(
            'deoplete#util#get_keyword_pattern',
            context['filetype'], self.keyword_patterns)
        try:
            self._buffers[context['bufnr']] = {
                'bufnr': context['bufnr'],
                'filetype': self.vim.eval('&l:filetype'),
                'candidates': [
                    {'word': x} for x in
                    sorted(parse_buffer_pattern(getlines(self.vim),
                                                keyword_pattern),
                           key=str.lower)
                ]
            }
        except UnicodeDecodeError:
            return []
Exemplo n.º 23
0
    def _make_cache(self, context):
        # Bufsize check
        size = self.vim.call('line2byte', self.vim.call('line', '$') + 1) - 1
        if size > self._limit:
            return

        keyword_pattern = self.vim.call('deoplete#util#get_keyword_pattern',
                                        context['filetype'],
                                        self.keyword_patterns)
        try:
            self._buffers[context['bufnr']] = {
                'bufnr':
                context['bufnr'],
                'filetype':
                self.vim.eval('&l:filetype'),
                'candidates': [{
                    'word': x
                }
                               for x in sorted(parse_buffer_pattern(
                                   getlines(self.vim), keyword_pattern),
                                               key=str.lower)]
            }
        except UnicodeDecodeError:
            return []
Exemplo n.º 24
0
    def _make_cache(self, context):
        # gather variables
        self._cache['variables'] = {}
        variable_hits = parse_buffer_pattern(getlines(self.vim, 1),
                                             r'(@)(\w+)(\s+)(\w+)')
        for variable_hit in variable_hits:
            variable = variable_hit[1]
            type = variable_hit[3]
            if variable not in self._cache['variables']:
                self._cache['variables'][variable] = {'type': type.upper()}

        # populate tables and columns
        if not self._cache['tables']:
            try:
                command_results = (subprocess.check_output(
                    self.command, universal_newlines=True).split('\n'))
            except CalledProcessError:
                return None

            for row in command_results:
                if ',' not in row:
                    continue

                match = re.match(r'(.*),(.*),(.*),(.*),(.*),(.*)', row.strip())
                table_or_view = match.group(1).strip()
                type_name = match.group(2).strip()
                column = match.group(3).strip()
                column_type = match.group(4).strip()
                column_nullable = (True
                                   if match.group(5).strip() == '1' else False)
                column_length = match.group(6).strip()
                column_def = {
                    'column_name': column,
                    'type': column_type,
                    'nullabe': column_nullable,
                    'length':
                    (column_length if column_length != 'NULL' else None),
                }
                if table_or_view not in self._cache['tables']:
                    self._cache['tables'][table_or_view] = {
                        'type': type_name,
                        'columns': [column_def],
                        'aliases': [],
                    }
                elif column not in self._cache['tables'][table_or_view]:
                    self._cache['tables'][table_or_view]['columns'].append(
                        column_def)

        # gather aliases
        alias_hits = parse_buffer_pattern(
            getlines(self.vim),
            r'(FROM|from|JOIN|join)\s+(\w+)\s+(\w+)',
        )

        # clear existing aliases
        for table in self._cache['tables']:
            self._cache['tables'][table]['aliases'] = []

        for alias_hit in alias_hits:
            table = alias_hit[1].upper()
            alias = alias_hit[2].upper()
            if table not in self._cache['tables']:
                continue

            if alias not in self._cache['tables'][table]['aliases']:
                self._cache['tables'][table]['aliases'].append(alias)