-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathncm2_pyclang.vim
181 lines (152 loc) · 4.8 KB
/
ncm2_pyclang.vim
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
if get(s:, 'loaded', 0)
finish
endif
let s:loaded = 1
let g:ncm2_pyclang#library_path = get(g:,
\ 'ncm2_pyclang#library_path',
\ '')
let g:ncm2_pyclang#gcc_path = get(g:,
\ 'ncm2_pyclang#gcc_path',
\ 'gcc')
let g:ncm2_pyclang#sys_inc_args_fallback = get(g:, 'ncm2_pyclang#sys_inc_args_fallback', {})
let g:ncm2_pyclang#detect_sys_inc_args = get(g:, 'ncm2_pyclang#detect_sys_inc_args', 1)
if !has_key(g:ncm2_pyclang#sys_inc_args_fallback, 'c')
let g:ncm2_pyclang#sys_inc_args_fallback.c = [
\ '-isystem', '/usr/local/include',
\ '-isystem', '/usr/include']
endif
if !has_key(g:ncm2_pyclang#sys_inc_args_fallback, 'cpp')
let g:ncm2_pyclang#sys_inc_args_fallback.cpp = [
\ '-isystem', '/usr/local/include',
\ '-isystem', '/usr/include']
endif
let g:ncm2_pyclang#database_path = get(g:,
\ 'ncm2_pyclang#database_path',
\ [
\ 'compile_commands.json',
\ 'build/compile_commands.json'
\ ])
let g:ncm2_pyclang#args_file_path = get(g:,
\ 'ncm2_pyclang#args_file_path',
\ ['.clang_complete'])
let g:ncm2_pyclang#bin = get(g:, 'ncm2_pyclang#bin', "bin/ncm2_pyclang")
let g:ncm2_pyclang#source = extend(get(g:, 'ncm2_pyclang#source', {}), {
\ 'name': 'pyclang',
\ 'ready': 0,
\ 'scope': ['cpp', 'c'],
\ 'priority': 9,
\ 'mark': 'cxx',
\ 'subscope_enable': 1,
\ 'on_complete': 'ncm2_pyclang#on_complete',
\ 'on_warmup': 'ncm2_pyclang#on_warmup',
\ 'complete_pattern': [
\ '-\>',
\ '::',
\ '\.',
\ '^\s*#',
\ '^\s*#include.*/']
\ }, 'keep')
let g:ncm2_pyclang#proc = yarp#py3({'module': 'ncm2_pyclang_proc',
\ 'job_detach': 1,
\ 'on_load': function('extend',
\ [g:ncm2_pyclang#source, {'ready': 1}])
\ })
func! ncm2_pyclang#init()
call ncm2#register_source(g:ncm2_pyclang#source)
endfunc
func! ncm2_pyclang#on_warmup(ctx)
if &filetype != 'cpp' && &filetype != 'c'
call g:ncm2_pyclang#proc.jobstart()
return
endif
if a:ctx['filepath'] == ""
call g:ncm2_pyclang#proc.jobstart()
return
endif
call g:ncm2_pyclang#proc.try_notify('cache_add',
\ s:data(a:ctx),
\ getline(1, '$'))
if get(b:, 'b:ncm2_pyclang_cache') == 0
au BufDelete <buffer> call
\ g:ncm2_pyclang#proc.try_notify(
\ 'cache_del',
\ expand('%:p'))
endif
let b:ncm2_pyclang_cache = 1
endfunc
func! ncm2_pyclang#on_complete(ctx)
call g:ncm2_pyclang#proc.try_notify('on_complete',
\ a:ctx,
\ s:data({}),
\ getline(1, '$'))
endfunc
func! ncm2_pyclang#find_declaration()
let pos = g:ncm2_pyclang#proc.call('find_declaration',
\ s:data(ncm2#context(g:ncm2_pyclang#source)),
\ getline(1, '$'))
if empty(pos)
echohl ErrorMsg
echom "Cannot find declaration"
echohl None
endif
return pos
endfunc
func! ncm2_pyclang#goto_declaration()
let pos = ncm2_pyclang#find_declaration()
if empty(pos)
return
endif
let filepath = expand("%:p")
if filepath != pos.file
let fes = fnameescape(pos.file)
exe 'edit' fes
else
normal! m'
endif
call cursor(pos.lnum, pos.bcol)
endfunc
func! ncm2_pyclang#goto_declaration_split()
let pos = ncm2_pyclang#find_declaration()
if empty(pos)
return
endif
let filepath = expand("%:p")
if filepath != pos.file
let fes = fnameescape(pos.file)
exe 'split' fes
else
normal! m'
endif
call cursor(pos.lnum, pos.bcol)
endfunc
func! ncm2_pyclang#goto_declaration_vsplit()
let pos = ncm2_pyclang#find_declaration()
if empty(pos)
return
endif
let filepath = expand("%:p")
if filepath != pos.file
let fes = fnameescape(pos.file)
exe 'vsplit' fes
else
normal! m'
endif
call cursor(pos.lnum, pos.bcol)
endfunc
func! ncm2_pyclang#get_args_dir()
return g:ncm2_pyclang#proc.call('get_args_dir',
\ s:data(ncm2#context(g:ncm2_pyclang#source)))
endfunc
func! ncm2_pyclang#error(msg)
call g:ncm2_pyclang#proc.error(a:msg)
endfunc
func! ncm2_pyclang#warn(msg)
call g:ncm2_pyclang#proc.warn(a:msg)
endfunc
func! s:data(context)
return {'cwd': getcwd(),
\ 'database_path': g:ncm2_pyclang#database_path,
\ 'args_file_path': g:ncm2_pyclang#args_file_path,
\ 'context': a:context,
\ }
endfunc