-
-
Notifications
You must be signed in to change notification settings - Fork 959
/
workspace.py
54 lines (46 loc) · 2.18 KB
/
workspace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# ============================================================================
# FILE: workspace.py
# AUTHOR: Qiming Zhao <chemzqm@gmail.com>
# License: MIT license
# ============================================================================
# pylint: disable=E0401,C0411
import re
from denite.kind.file import Kind as FileKind
from denite.source.base import Base
from os.path import relpath
class Source(Base):
def __init__(self, vim):
super().__init__(vim)
self.name = 'coc-workspace'
self.matchers = ['matcher_fuzzy']
self.sorters = ['sorter/sublime']
self.kind = FileKind(vim)
def define_syntax(self):
self.vim.command('syntax case ignore')
self.vim.command(r'syntax match deniteSource_WorkspaceHeader /\v^.*$/ containedin=' + self.syntax_name)
self.vim.command(r'syntax match deniteSource_WorkspaceName /\v^\s*\S+/ contained '
r'containedin=deniteSource_WorkspaceHeader')
self.vim.command(r'syntax match deniteSource_WorkspaceKind /\[\w\+\]/ contained '
r'containedin=deniteSource_WorkspaceHeader')
self.vim.command(r'syntax match deniteSource_WorkspaceFile /\f\+$/ contained '
r'containedin=deniteSource_WorkspaceHeader')
def highlight(self):
self.vim.command('highlight default link deniteSource_WorkspaceName Normal')
self.vim.command('highlight default link deniteSource_WorkspaceKind Typedef')
self.vim.command('highlight default link deniteSource_WorkspaceFile Comment')
def gather_candidates(self, context):
cwd = self.vim.call('getcwd')
items = self.vim.call('CocAction', 'workspaceSymbols')
if items is None or items is 0:
return []
candidates = []
for item in items:
filepath = relpath(item['filepath'], start=cwd)
candidates.append({
'word': item['text'],
'abbr': '%s [%s] %s' % (item['text'], item['kind'], filepath),
'action__path': item['filepath'],
'action__col': item['col'],
'action__line': item['lnum'],
})
return candidates