spacevim/bundle/deoplete.nvim/rplugin/python3/deoplete/source/omni.py
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

103 lines
3.6 KiB
Python

# ============================================================================
# FILE: omni.py
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
# License: MIT license
# ============================================================================
from pynvim import Nvim
import re
import typing
from deoplete.base.source import Base
from deoplete.util import (
convert2list, set_pattern, convert2candidates)
from deoplete.util import UserContext, Candidates
class Source(Base):
def __init__(self, vim: Nvim) -> None:
super().__init__(vim)
self.name = 'omni'
self.mark = '[O]'
self.rank = 500
self.is_bytepos = True
self.min_pattern_length = 0
input_patterns: typing.Dict[str, str] = {}
set_pattern(input_patterns, 'css,less,scss,sass',
[r'\w{2}', r'\w+:?\s*\w*', r'[@!]'])
self.vars = {
'input_patterns': input_patterns,
'functions': {},
}
def get_complete_position(self, context: UserContext) -> int:
current_ft = self.get_buf_option('filetype')
for filetype in list(set([context['filetype']] +
context['filetype'].split('.'))):
pos = self._get_complete_position(context, current_ft, filetype)
if pos >= 0:
return pos
return -1
def _get_complete_position(self, context: UserContext,
current_ft: str, filetype: str) -> int:
complete_pos = -1
for omnifunc in convert2list(
self.get_filetype_var(filetype, 'functions')):
if omnifunc == '' and (filetype == current_ft or
filetype in ['css', 'javascript']):
omnifunc = self.get_buf_option('omnifunc')
if omnifunc == '':
continue
self._omnifunc = omnifunc
for input_pattern in convert2list(
self.get_filetype_var(filetype, 'input_patterns')):
m = re.search('(' + input_pattern + ')$', context['input'])
# self.debug(filetype)
# self.debug(input_pattern)
if input_pattern == '' or (context['event'] !=
'Manual' and m is None):
continue
if self._omnifunc in [
'ccomplete#Complete',
'htmlcomplete#CompleteTags',
'LanguageClient#complete',
'rubycomplete#Complete',
'phpcomplete#CompletePHP']:
# In the blacklist
continue
try:
complete_pos = int(self.vim.call(self._omnifunc, 1, ''))
except Exception:
self.print_error('Error occurred calling omnifunction: ' +
self._omnifunc)
return -1
if complete_pos >= 0:
break
return complete_pos
def gather_candidates(self, context: UserContext) -> Candidates:
try:
candidates = self.vim.call(self._omnifunc, 0, '')
if isinstance(candidates, dict):
candidates = candidates['words']
elif not isinstance(candidates, list):
candidates = []
except Exception:
candidates = []
candidates = convert2candidates(candidates)
for candidate in candidates:
candidate['dup'] = 1
candidate['equal'] = 1
return list(candidates)