vim-patch:8.0.1398: :packadd does not load packages from the "start" directory (#8762)

Problem:    :packadd does not load packages from the "start" directory.
            (Alejandro Hernandez)
Solution:   Make :packadd look in the "start" directory if those packages were
            not loaded on startup.
9e1d399e63
This commit is contained in:
Jan Edmund Lazo 2018-07-22 20:04:49 -04:00 committed by Justin M. Keyes
parent 13d29cb9ed
commit c9f2faf3bf
2 changed files with 43 additions and 7 deletions

View File

@ -2693,15 +2693,28 @@ void ex_packloadall(exarg_T *eap)
/// ":packadd[!] {name}" /// ":packadd[!] {name}"
void ex_packadd(exarg_T *eap) void ex_packadd(exarg_T *eap)
{ {
static const char *plugpat = "pack/*/opt/%s"; // NOLINT static const char *plugpat = "pack/*/%s/%s"; // NOLINT
int res = OK;
size_t len = STRLEN(plugpat) + STRLEN(eap->arg); // Round 1: use "start", round 2: use "opt".
char *pat = (char *)xmallocz(len); for (int round = 1; round <= 2; round++) {
vim_snprintf(pat, len, plugpat, eap->arg); // Only look under "start" when loading packages wasn't done yet.
do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR + DIP_ERR, add_pack_plugin, if (round == 1 && did_source_packages) {
eap->forceit ? &APP_ADD_DIR : &APP_BOTH); continue;
}
const size_t len = STRLEN(plugpat) + STRLEN(eap->arg) + 5;
char *pat = xmallocz(len);
vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
// The first round don't give a "not found" error, in the second round
// only when nothing was found in the first round.
res = do_in_path(p_pp, (char_u *)pat,
DIP_ALL + DIP_DIR
+ (round == 2 && res == FAIL ? DIP_ERR : 0),
add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
xfree(pat); xfree(pat);
} }
}
/// ":options" /// ":options"
void ex_options(exarg_T *eap) void ex_options(exarg_T *eap)

View File

@ -58,6 +58,24 @@ describe('packadd', function()
call assert_fails("packadd", 'E471:') call assert_fails("packadd", 'E471:')
endfunc endfunc
func Test_packadd_start()
let plugdir = expand(s:topdir . '/pack/mine/start/other')
call mkdir(plugdir . '/plugin', 'p')
set rtp&
let rtp = &rtp
filetype on
exe 'split ' . plugdir . '/plugin/test.vim'
call setline(1, 'let g:plugin_works = 24')
wq
packadd other
call assert_equal(24, g:plugin_works)
call assert_true(len(&rtp) > len(rtp))
call assert_true(&rtp =~ (escape(plugdir, '\') . '\($\|,\)'))
endfunc
func Test_packadd_noload() func Test_packadd_noload()
call mkdir(s:plugdir . '/plugin', 'p') call mkdir(s:plugdir . '/plugin', 'p')
call mkdir(s:plugdir . '/syntax', 'p') call mkdir(s:plugdir . '/syntax', 'p')
@ -286,6 +304,11 @@ describe('packadd', function()
expected_empty() expected_empty()
end) end)
it('loads packages from "start" directory', function()
call('Test_packadd_start')
expected_empty()
end)
describe('command line completion', function() describe('command line completion', function()
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local screen local screen