refactor(runtime): handle pack/foo/start/bar/after dirs properly

The order should be:
XDG_CONFIG_HOME/nvim
XDG_DATA_HOME/nvim/site/pack/foo/start/bar/
XDG_CONFIG_HOME/nvim/after
XDG_DATA_HOME/nvim/site/pack/foo/start/bar/after
This commit is contained in:
Björn Linse
2021-09-11 20:11:16 +02:00
parent 396280d303
commit a860f7880f
8 changed files with 58 additions and 12 deletions

View File

@@ -168,28 +168,36 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags,
DoInRuntimepathCB callback, void *cookie)
{
int done = FAIL;
if (!(flags & (DIP_NOAFTER | DIP_AFTER))) {
done = do_in_path_and_pp(path, name, flags | DIP_NOAFTER, callback, cookie);
if (done == OK && !(flags & DIP_ALL)) {
return done;
}
flags |= DIP_AFTER;
}
if ((flags & DIP_NORTP) == 0) {
done = do_in_path(path, (name && !*name) ? NULL : name, flags, callback, cookie);
done |= do_in_path(path, (name && !*name) ? NULL : name, flags, callback, cookie);
}
if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START)) {
char *start_dir = "pack/*/start/*/%s"; // NOLINT
size_t len = STRLEN(start_dir) + STRLEN(name);
char_u *s = xmallocz(len);
char *start_dir = "pack/*/start/*/%s%s"; // NOLINT
size_t len = STRLEN(start_dir) + STRLEN(name) + 6;
char_u *s = xmallocz(len); // TODO(bfredl): get rid of random allocations
char *suffix = (flags & DIP_AFTER) ? "after/" : "";
vim_snprintf((char *)s, len, start_dir, name);
done |= do_in_path(p_pp, s, flags, callback, cookie);
vim_snprintf((char *)s, len, start_dir, suffix, name);
done |= do_in_path(p_pp, s, flags & ~DIP_AFTER, callback, cookie);
xfree(s);
if (done == FAIL || (flags & DIP_ALL)) {
start_dir = "start/*/%s"; // NOLINT
len = STRLEN(start_dir) + STRLEN(name);
start_dir = "start/*/%s%s"; // NOLINT
len = STRLEN(start_dir) + STRLEN(name) + 6;
s = xmallocz(len);
vim_snprintf((char *)s, len, start_dir, name);
done |= do_in_path(p_pp, s, flags, callback, cookie);
vim_snprintf((char *)s, len, start_dir, suffix, name);
done |= do_in_path(p_pp, s, flags & ~DIP_AFTER, callback, cookie);
xfree(s);
}