Skip to content

Commit ebc349e

Browse files
author
gaalcaras
committed
Switch rchunk completion to ncm2
1 parent 0e19458 commit ebc349e

6 files changed

Lines changed: 57 additions & 302 deletions

File tree

autoload/ncm_rchunk.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
if get(s:, 'loaded', 0)
2+
finish
3+
endif
4+
let s:loaded = 1
5+
6+
let g:ncm_rchunk#proc = yarp#py3({
7+
\ 'module': 'ncm_rchunk'
8+
\ })
9+
10+
let g:ncm_rchunk#source = extend(get(g:, 'ncm_rchunk', {}), {
11+
\ 'name': 'Rchunk',
12+
\ 'priority': 9,
13+
\ 'mark': 'Rchunk',
14+
\ 'scope': ['rchunk'],
15+
\ 'subscope_enable': 1,
16+
\ 'word_pattern': '[\w_\.]+',
17+
\ 'complete_pattern': [',\s', '=\s"'],
18+
\ 'on_complete': 'ncm_rchunk#on_complete',
19+
\ }, 'keep')
20+
21+
function! ncm_rchunk#init()
22+
call ncm2#register_source(g:ncm_rchunk#source)
23+
endfunction
24+
25+
function! ncm_rchunk#on_complete(ctx)
26+
call g:ncm_rchunk#proc.try_notify('on_complete', a:ctx)
27+
endfunction

ncm2-plugin/ncm2_R.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
call ncm_r#init()
2+
call ncm_rchunk#init()

pythonx/cm_sources/rcode.py

Lines changed: 0 additions & 280 deletions
This file was deleted.
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,12 @@
55
by Gabriel Alcaras
66
"""
77

8-
from cm import register_source # pylint: disable=E0401
8+
import vim # pylint: disable=E0401
99

1010
from rsource import Rsource # pylint: disable=E0401
1111
import filtr # pylint: disable=E0401
1212
import rlang # pylint: disable=E0401
1313

14-
register_source(name='RChunk',
15-
priority=9,
16-
abbreviation='RChunk',
17-
word_pattern=r'[\w_\.]+',
18-
scoping=True,
19-
scopes=['rchunk'],
20-
early_cache=1,
21-
cm_refresh_patterns=[
22-
r',\s?', # New option
23-
r'=\s?"', # Option value
24-
])
25-
2614

2715
class Source(Rsource): # pylint: disable=too-few-public-methods
2816
"""Completion Manager Source for R Chunk options"""
@@ -121,13 +109,24 @@ def __init__(self, nvim):
121109
options = sorted(options, key=str.lower)
122110
self._options = self.matches.from_chunk_options(options)
123111

124-
def cm_refresh(self, info, ctx,):
112+
def on_complete(self, ctx):
125113
"""Refresh NCM list of matches"""
126114

127115
matches = self._options
128116
option = rlang.get_option(ctx['typed'])
129117

118+
self._info('hello :: typed: {}, ccol: {},'
119+
' startccol: {}'.format(ctx['typed'],
120+
ctx['ccol'],
121+
ctx['startccol']))
122+
130123
if option:
131124
matches = filtr.arg(matches, option)
132125

133-
self.complete(info, ctx, ctx['startcol'], matches)
126+
self._info(matches)
127+
self.complete(ctx, ctx['scope_len'], matches)
128+
129+
130+
SOURCE = Source(vim)
131+
132+
on_complete = SOURCE.on_complete

pythonx/omnils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,10 @@ def _process_option(self, match):
270270

271271
if quotes:
272272
default = quotes.group(1)
273-
snip = '"' + default + '"'
274273

275274
if re.search(r'|', default):
276275
values = quotes.group(1).split('|')
277-
default = '"' + values[0] + '"'
278-
snip = ''
276+
default = values[0]
279277

280278
for value in values:
281279
struct = 'value'
@@ -285,7 +283,8 @@ def _process_option(self, match):
285283
match['args'].append(self.build(word=value,
286284
struct=struct))
287285

288-
add_snippet(match, lhs + ' = "${1:' + snip + '}"')
286+
add_snippet(match, lhs + ' = "${1:' + default + '}"')
287+
default = '"{}"'.format(default)
289288
else:
290289
default = rhs
291290

0 commit comments

Comments
 (0)