patch 8.2.3459: Vim9: need more tests for empty string arguments
Problem: Vim9: need more tests for empty string arguments.
Solution: Add more tests. Also use empty argument with menu_info() to get
the top-level menu names. (Yegappan Lakshmanan, closes #8925)
diff --git a/src/menu.c b/src/menu.c
index b9f7db2..2cd3270 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -2830,9 +2830,27 @@
* Get the information about a menu item in mode 'which'
*/
static int
-menuitem_getinfo(vimmenu_T *menu, int modes, dict_T *dict)
+menuitem_getinfo(char_u *menu_name, vimmenu_T *menu, int modes, dict_T *dict)
{
int status;
+ list_T *l;
+
+ if (*menu_name == NUL)
+ {
+ // Return all the top-level menus
+ vimmenu_T *topmenu;
+
+ l = list_alloc();
+ if (l == NULL)
+ return FAIL;
+
+ dict_add_list(dict, "submenus", l);
+ // get all the children. Skip PopUp[nvoci].
+ for (topmenu = menu; topmenu != NULL; topmenu = topmenu->next)
+ if (!menu_is_hidden(topmenu->dname))
+ list_append_string(l, topmenu->dname, -1);
+ return OK;
+ }
if (menu_is_tearoff(menu->dname)) // skip tearoff menu item
return OK;
@@ -2903,9 +2921,9 @@
// If there are submenus, add all the submenu display names
if (status == OK && menu->children != NULL)
{
- list_T *l = list_alloc();
vimmenu_T *child;
+ l = list_alloc();
if (l == NULL)
return FAIL;
@@ -2992,7 +3010,7 @@
return;
if (menu->modes & modes)
- menuitem_getinfo(menu, modes, retdict);
+ menuitem_getinfo(menu_name, menu, modes, retdict);
}
#endif // FEAT_MENU