Skip to content
This repository was archived by the owner on Aug 24, 2020. It is now read-only.

Commit d9e471e

Browse files
authored
Remove typed_pattern (prabirshrestha#704)
* Remove typed_pattern * Rename asyncomplete_refresh_pattern to vim_lsp_refresh_pattern * Fix textEdit to clear inserted text * Fix when startcol can not be found * Find first item for refresh_pattenr * Fix * Update doc * Trim empty spaces right * Use space
1 parent 3e207c0 commit d9e471e

File tree

3 files changed

+32
-40
lines changed

3 files changed

+32
-40
lines changed

autoload/lsp/omni.vim

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ function! lsp#omni#complete(findstart, base) abort
5858
let s:completion['status'] = s:completion_status_pending
5959
endif
6060

61+
" Find first item which has refresh_pattern
62+
let l:refresh_pattern = '\(\k\+$\)'
63+
for l:server_name in l:info['server_names']
64+
let l:server_info = lsp#get_server_info(l:server_name)
65+
if has_key (l:server_info, 'config') && has_key(l:server_info['config'], 'refresh_pattern')
66+
let l:refresh_pattern = l:server_info['config']['refresh_pattern']
67+
break
68+
endif
69+
endfor
70+
let l:curpos = getcurpos()
71+
let l:left = strpart(getline(l:curpos[1]), 0, l:curpos[2]-1)
72+
let s:completion['startcol'] = matchstrpos(l:left, l:refresh_pattern)[1]
73+
if s:completion['startcol'] == -1
74+
let s:completion['startcol'] = strlen(l:left)
75+
endif
76+
6177
call s:send_completion_request(l:info)
6278

6379
if g:lsp_async_completion
@@ -76,24 +92,9 @@ function! lsp#omni#complete(findstart, base) abort
7692
endif
7793
endfunction
7894

79-
function! s:get_insertion_point(item, current_line, typed_pattern) abort
80-
let l:insert_start = -1
81-
82-
let l:user_data = lsp#omni#get_managed_user_data_from_completed_item(a:item)
83-
if has_key(l:user_data, 'completion_item') && has_key(l:user_data['completion_item'], 'textEdit')
84-
let l:insert_start = l:user_data['completion_item']['textEdit']['range']['start']['character']
85-
endif
86-
87-
if l:insert_start >= 0
88-
return l:insert_start
89-
else
90-
return match(a:current_line, a:typed_pattern)
91-
endif
92-
endfunction
93-
9495
function! s:get_filter_label(item) abort
9596
let l:user_data = lsp#omni#get_managed_user_data_from_completed_item(a:item)
96-
if has_key(l:user_data, 'completion_item') && has_key(l:user_data['completion_item'], 'filterText')
97+
if has_key(l:user_data, 'completion_item') && has_key(l:user_data['completion_item'], 'filterText') && !empty(l:user_data['completion_item']['filterText'])
9798
return trim(l:user_data['completion_item']['filterText'])
9899
endif
99100
return trim(a:item['word'])
@@ -124,13 +125,9 @@ function! s:display_completions(timer, info) abort
124125
let l:server_name = a:info['server_names'][0]
125126
let l:server_info = lsp#get_server_info(l:server_name)
126127

127-
let l:typed_pattern = has_key(l:server_info, 'config') && has_key(l:server_info['config'], 'typed_pattern') ? l:server_info['config']['typed_pattern'] : '\k*$'
128128
let l:current_line = strpart(getline('.'), 0, col('.') - 1)
129-
130-
let s:start_pos = min(map(copy(s:completion['matches']), {_, item -> s:get_insertion_point(item, l:current_line, l:typed_pattern) }))
131-
132129
let l:filter = has_key(l:server_info, 'config') && has_key(l:server_info['config'], 'filter') ? l:server_info['config']['filter'] : { 'name': 'prefix' }
133-
let l:last_typed_word = strpart(l:current_line, s:start_pos)
130+
let l:last_typed_word = strpart(l:current_line, s:completion['startcol'])
134131

135132
if l:filter['name'] ==? 'prefix'
136133
let s:completion['matches'] = filter(s:completion['matches'], {_, item -> s:prefix_filter(item, l:last_typed_word)})
@@ -141,7 +138,7 @@ function! s:display_completions(timer, info) abort
141138
let s:completion['status'] = ''
142139

143140
if mode() is# 'i'
144-
call complete(s:start_pos + 1, s:completion['matches'])
141+
call complete(s:completion['startcol'] + 1, s:completion['matches'])
145142
endif
146143
endfunction
147144

autoload/lsp/ui/vim/completion.vim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,7 @@ function! s:clear_inserted_text(line, position, completed_item, completion_item)
192192

193193
" Expand remove range to textEdit.
194194
if has_key(a:completion_item, 'textEdit')
195-
let l:range['start']['character'] = min([
196-
\ l:range['start']['character'],
197-
\ a:completion_item['textEdit']['range']['start']['character']
198-
\ ])
195+
let l:range['start']['character'] = a:completion_item['textEdit']['range']['start']['character']
199196
let l:range['end']['character'] = max([
200197
\ l:range['end']['character'],
201198
\ a:completion_item['textEdit']['range']['end']['character']

doc/vim-lsp.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ The vim |dict| containing information about the server.
794794
<
795795
Using the `config` key, you can also specify a custom 'typed word
796796
pattern', or a custom filter for completion items, see
797-
|vim-lsp-typed_pattern| and |vim-lsp-completion-filter|.
797+
|vim-lsp-completion-filter|.
798798

799799
The following per-server configuration options are supported by vim-lsp.
800800

@@ -830,28 +830,28 @@ The vim |dict| containing information about the server.
830830
Example: >
831831
'config': { 'completion_item_kinds': {'26': 'type' } }
832832
<
833-
typed_pattern *vim-lsp-typed_pattern*
833+
refresh_pattern *vim-lsp-refresh_pattern*
834834
Type: |String| (|pattern|)
835835
Default: `'\k*$'`
836836

837-
Vim-lsp will automatically detect the text you have typed so far when invoking
838-
completion. It does this by checking the textEdit's range of each completion
839-
item.
837+
Vim-lsp will automatically detect start column of completion so far when
838+
invoking completion. It does this by checking the textEdit's range of each
839+
completion item.
840840

841-
If the language server doesn't use textEdits, you can use a |regexp| to
842-
determine what you have typed so far. The pattern is matched against the
843-
current line, from column 0 up until the cursor's position. Thus, |/$| means
844-
"current cursor position" in this context.
841+
You can use a |regexp| to determine what you want to start completion with
842+
matched text so far. The pattern is matched against the current line, from
843+
column 0 up until the cursor's position. Thus, |/$| means "current cursor
844+
position" in this context.
845845

846846
For example: >
847-
'config': { 'typed_pattern': '\k*$' }
847+
'config': { 'refresh_pattern': '\k*$' }
848848
<
849849
This uses all characters in `'iskeyword'` in front of the cursor as typed
850850
word.
851851

852852
This key is also used to align the completion menu: the completion menu is
853853
placed so its left border is at the column that matches the start of the
854-
`typed_pattern`.
854+
`refresh_pattern`.
855855

856856
filter *vim-lsp-completion-filter*
857857

@@ -860,9 +860,7 @@ completion filter using the `filter` key in the server info's `config` |dict|.
860860
The value of the `filter` key is itself a |dict| containing at least a key
861861
`name`, which specifies which filter to use.
862862

863-
For the meaning of "already typed text" in the remainder of this section, see
864-
|vim-lsp-typed_pattern|. The case (in)sensitivity of the matching is
865-
determined by |g:lsp_ignorecase|.
863+
The case (in)sensitivity of the matching is determined by |g:lsp_ignorecase|.
866864

867865
Example: >
868866
'config': { 'filter': { 'name': 'none' } }

0 commit comments

Comments
 (0)