Skip to content

Commit b56195e

Browse files
committed
patch 7.4.2112
Problem: getcompletion(.., 'dir') returns a match with trailing "*" when there are no matches. (Chdiza) Solution: Return an empty list when there are no matches. Add a trailing slash to directories. (Yegappan Lakshmanan) Add tests for no matches. (closes #947)
1 parent 471a897 commit b56195e

3 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/evalfunc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,8 +4164,8 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
41644164
{
41654165
char_u *pat;
41664166
expand_T xpc;
4167-
int options = WILD_KEEP_ALL | WILD_SILENT | WILD_USE_NL
4168-
| WILD_LIST_NOTFOUND | WILD_NO_BEEP;
4167+
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
4168+
| WILD_NO_BEEP;
41694169

41704170
if (p_wic)
41714171
options |= WILD_ICASE;
@@ -4194,7 +4194,7 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
41944194
pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
41954195
if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL))
41964196
{
4197-
int i;
4197+
int i;
41984198

41994199
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
42004200

src/testdir/test_cmdline.vim

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,53 +47,83 @@ func Test_getcompletion()
4747

4848
let l = getcompletion('v:n', 'var')
4949
call assert_true(index(l, 'v:null') >= 0)
50+
let l = getcompletion('v:notexists', 'var')
51+
call assert_equal([], l)
5052

5153
let l = getcompletion('', 'augroup')
5254
call assert_true(index(l, 'END') >= 0)
55+
let l = getcompletion('blahblah', 'augroup')
56+
call assert_equal([], l)
5357

5458
let l = getcompletion('', 'behave')
5559
call assert_true(index(l, 'mswin') >= 0)
60+
let l = getcompletion('not', 'behave')
61+
call assert_equal([], l)
5662

5763
let l = getcompletion('', 'color')
5864
call assert_true(index(l, 'default') >= 0)
65+
let l = getcompletion('dirty', 'color')
66+
call assert_equal([], l)
5967

6068
let l = getcompletion('', 'command')
6169
call assert_true(index(l, 'sleep') >= 0)
70+
let l = getcompletion('awake', 'command')
71+
call assert_equal([], l)
6272

6373
let l = getcompletion('', 'dir')
64-
call assert_true(index(l, 'samples') >= 0)
74+
call assert_true(index(l, 'samples/') >= 0)
75+
let l = getcompletion('NoMatch', 'dir')
76+
call assert_equal([], l)
6577

6678
let l = getcompletion('exe', 'expression')
6779
call assert_true(index(l, 'executable(') >= 0)
80+
let l = getcompletion('kill', 'expression')
81+
call assert_equal([], l)
6882

6983
let l = getcompletion('tag', 'function')
7084
call assert_true(index(l, 'taglist(') >= 0)
85+
let l = getcompletion('paint', 'function')
86+
call assert_equal([], l)
7187

7288
let Flambda = {-> 'hello'}
7389
let l = getcompletion('', 'function')
7490
let l = filter(l, {i, v -> v =~ 'lambda'})
75-
call assert_equal(0, len(l))
91+
call assert_equal([], l)
7692

7793
let l = getcompletion('run', 'file')
7894
call assert_true(index(l, 'runtest.vim') >= 0)
95+
let l = getcompletion('walk', 'file')
96+
call assert_equal([], l)
7997

8098
let l = getcompletion('ha', 'filetype')
8199
call assert_true(index(l, 'hamster') >= 0)
100+
let l = getcompletion('horse', 'filetype')
101+
call assert_equal([], l)
82102

83103
let l = getcompletion('z', 'syntax')
84104
call assert_true(index(l, 'zimbu') >= 0)
105+
let l = getcompletion('emacs', 'syntax')
106+
call assert_equal([], l)
85107

86108
let l = getcompletion('jikes', 'compiler')
87109
call assert_true(index(l, 'jikes') >= 0)
110+
let l = getcompletion('break', 'compiler')
111+
call assert_equal([], l)
88112

89113
let l = getcompletion('last', 'help')
90114
call assert_true(index(l, ':tablast') >= 0)
115+
let l = getcompletion('giveup', 'help')
116+
call assert_equal([], l)
91117

92118
let l = getcompletion('time', 'option')
93119
call assert_true(index(l, 'timeoutlen') >= 0)
120+
let l = getcompletion('space', 'option')
121+
call assert_equal([], l)
94122

95123
let l = getcompletion('er', 'highlight')
96124
call assert_true(index(l, 'ErrorMsg') >= 0)
125+
let l = getcompletion('dark', 'highlight')
126+
call assert_equal([], l)
97127

98128
" For others test if the name is recognized.
99129
let names = ['buffer', 'environment', 'file_in_path',

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ static char *(features[]) =
758758

759759
static int included_patches[] =
760760
{ /* Add new patch number below this line */
761+
/**/
762+
2112,
761763
/**/
762764
2111,
763765
/**/

0 commit comments

Comments
 (0)