Skip to content

Instantly share code, notes, and snippets.

@mhinz
Created January 17, 2018 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhinz/4e783d421bd31866d4183264420e4669 to your computer and use it in GitHub Desktop.
Save mhinz/4e783d421bd31866d4183264420e4669 to your computer and use it in GitHub Desktop.
diff --git i/src/nvim/eval.c w/src/nvim/eval.c
index 28c590c0b..c60ec7b03 100644
--- i/src/nvim/eval.c
+++ w/src/nvim/eval.c
@@ -22538,3 +22538,50 @@ void ex_checkhealth(exarg_T *eap)
xfree(buf);
}
+
+/// Function given to ExpandGeneric() to obtain expansion specific
+/// to the checkhealth command.
+char_u *get_checkhealth_name(expand_T *xp, int idx)
+{
+ const char *vimruntime_env = os_getenv("VIMRUNTIME");
+ if (vimruntime_env == NULL) {
+ return NULL;
+ }
+
+ char *checkhealth_cmds[10] = { NULL };
+ size_t bufsize = STRLEN(vimruntime_env) + sizeof("/autoload/health");
+ char *dirpath = xmalloc(bufsize);
+ snprintf(dirpath, bufsize, "%s/autoload/health", vimruntime_env);
+
+ Directory dir;
+ if (os_file_is_readable(dirpath) && os_scandir(&dir, dirpath)) {
+ char *entry;
+ int i = 0;
+ while (i < 10 && (entry = (char *)os_scandir_next(&dir))) {
+ // Remove "\.vim" from "file\.vim"
+ if (STRLEN(entry) > 5) {
+ size_t ext_start = STRLEN(entry) - 4;
+ entry[ext_start] = NUL;
+ checkhealth_cmds[i++] = entry;
+ }
+ }
+ }
+
+ os_closedir(&dir);
+ xfree(dirpath);
+
+ return (char_u *)checkhealth_cmds[idx];
+}
+
+/// Handle command line completion for :checkhealth command.
+void set_context_in_checkhealth_cmd(expand_T *xp, const char *arg)
+{
+ xp->xp_context = EXPAND_CHECKHEALTH;
+ xp->xp_pattern = (char_u *)arg;
+
+ if (*skiptowhite((const char_u *)arg) == NUL) {
+ return;
+ }
+
+ xp->xp_context = EXPAND_NOTHING;
+}
diff --git i/src/nvim/ex_docmd.c w/src/nvim/ex_docmd.c
index 2fa8db6b8..d275c6e7c 100644
--- i/src/nvim/ex_docmd.c
+++ w/src/nvim/ex_docmd.c
@@ -3442,6 +3442,9 @@ const char * set_one_cmd_context(
case CMD_profile:
set_context_in_profile_cmd(xp, arg);
break;
+ case CMD_checkhealth:
+ set_context_in_checkhealth_cmd(xp, arg);
+ break;
case CMD_behave:
xp->xp_context = EXPAND_BEHAVE;
xp->xp_pattern = (char_u *)arg;
diff --git i/src/nvim/ex_getln.c w/src/nvim/ex_getln.c
index 82fac8d78..f04686edc 100644
--- i/src/nvim/ex_getln.c
+++ w/src/nvim/ex_getln.c
@@ -4718,6 +4718,7 @@ ExpandFromContext (
{ EXPAND_CSCOPE, get_cscope_name, true, true },
{ EXPAND_SIGN, get_sign_name, true, true },
{ EXPAND_PROFILE, get_profile_name, true, true },
+ { EXPAND_CHECKHEALTH, get_checkhealth_name, true, true },
#ifdef HAVE_WORKING_LIBINTL
{ EXPAND_LANGUAGE, get_lang_arg, true, false },
{ EXPAND_LOCALES, get_locales, true, false },
diff --git i/src/nvim/vim.h w/src/nvim/vim.h
index b535e380d..38cb168c0 100644
--- i/src/nvim/vim.h
+++ w/src/nvim/vim.h
@@ -144,6 +144,7 @@ enum {
EXPAND_CSCOPE,
EXPAND_SIGN,
EXPAND_PROFILE,
+ EXPAND_CHECKHEALTH,
EXPAND_BEHAVE,
EXPAND_FILETYPE,
EXPAND_FILES_IN_PATH,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment