Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Commit 8d13702

Browse files
authored
Merge pull request #251 from kristijanhusak/feature/smart-case
Add option to enable smart case matching.
2 parents 1cfb859 + 8c03b8d commit 8d13702

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ work as you expect on some language server.
207207
```vim
208208
g:completion_matching_ignore_case = 1
209209
```
210+
- Or smart case matching by
211+
```vim
212+
g:completion_matching_smart_case = 1
213+
```
210214

211215
### Trigger Characters
212216

doc/completion-nvim.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ g:completion_enable_auto_popup *g:completion_enable_auto_popup*
6363
this value to 0 if you don't want automatically popup window.
6464

6565
If you disable auto popup menu, you can manually trigger completion by
66-
mapping keys. For example:
66+
mapping keys. For example:
6767
>
68-
" map <c-p> to manually trigger completion
68+
" map <c-p> to manually trigger completion
6969
imap <silent> <c-p> <Plug>(completion_trigger)
7070
<
7171
Or you want to use <tab> to trigger completion without modifying the
@@ -157,7 +157,7 @@ g:completion_trigger_character *g:completion_trigger_character*
157157
default value: ['.']
158158

159159
g:completion_trigger_keyword_length *g:completion_trigger_keyword_length*
160-
160+
161161
You can specify keyword length for triggering completion, if the
162162
current word is less than keyword length, completion won't be
163163
triggered.
@@ -277,7 +277,7 @@ g:completion_chain_complete_list *g:completion_chain_complete_list*
277277
<
278278
You can take a step further to specify different 'scope' of different
279279
filetypes. 'scope' is literally syntax in your file. Say that you want
280-
different completion lists in comments and function calls, strings,
280+
different completion lists in comments and function calls, strings,
281281
etc, you can do that easily. Here is an example
282282
>
283283
let g:completion_chain_complete_list = {
@@ -346,15 +346,23 @@ g:completion_matching_strategy_list *g:completion_matching_strategy_list*
346346
default value: ['exact']
347347

348348
g:completion_matching_ignore_case *g:completion_matching_ignore_case*
349-
349+
350350
Enable ignore case matching in all matching strategy. For example
351351
>
352352
let g:completion_matching_ignore_case = 1
353353
<
354354
default value: 0
355355

356+
g:completion_matching_smart_case *g:completion_matching_smart_case*
357+
358+
Enable smart case matching in all matching strategy. For example
359+
>
360+
let g:completion_matching_smart_case = 1
361+
<
362+
default value: &smartcase
363+
356364
g:completion_sorting *g:completion_sorting*
357-
365+
358366
You can determine how you want to sort the completion items in popup
359367
menu. Possible values are 'alphabet', 'length', 'none'
360368

lua/completion/matching.lua

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@ local util = require 'completion.util'
33
local opt = require 'completion.option'
44
local M = {}
55

6-
local function fuzzy_match(prefix, word)
7-
if opt.get_option('matching_ignore_case') == 1 then
8-
prefix = string.lower(prefix)
9-
word = string.lower(word)
6+
local function setup_case(prefix, word)
7+
local ignore_case = opt.get_option('matching_ignore_case') == 1
8+
9+
if not ignore_case and opt.get_option('matching_smart_case') == 1 and not prefix:match('[A-Z]') then
10+
ignore_case = true
1011
end
12+
13+
if ignore_case then
14+
return string.lower(prefix), string.lower(word)
15+
end
16+
17+
return prefix, word
18+
end
19+
20+
local function fuzzy_match(prefix, word)
21+
prefix, word = setup_case(prefix, word)
1122
local score = util.fuzzy_score(prefix, word)
1223
if score < 1 then
1324
return true, score
@@ -18,10 +29,7 @@ end
1829

1930

2031
local function substring_match(prefix, word)
21-
if opt.get_option('matching_ignore_case') == 1 then
22-
prefix = string.lower(prefix)
23-
word = string.lower(word)
24-
end
32+
prefix, word = setup_case(prefix, word)
2533
if string.find(word, prefix) then
2634
return true
2735
else
@@ -30,10 +38,7 @@ local function substring_match(prefix, word)
3038
end
3139

3240
local function exact_match(prefix, word)
33-
if opt.get_option('matching_ignore_case') == 1 then
34-
prefix = string.lower(prefix)
35-
word = string.lower(word)
36-
end
41+
prefix, word = setup_case(prefix, word)
3742
if vim.startswith(word, prefix) then
3843
return true
3944
else

plugin/completion.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ if ! exists('g:completion_matching_ignore_case')
8585
let g:completion_matching_ignore_case = 0
8686
endif
8787

88+
if ! exists('g:completion_matching_smart_case')
89+
let g:completion_matching_smart_case = &smartcase
90+
endif
91+
8892
if ! exists('g:completion_matching_strategy_list')
8993
let g:completion_matching_strategy_list = ['exact']
9094
endif

0 commit comments

Comments
 (0)