Переглянути джерело

Don't search for completion/help in upper levels when line is empty.

When the purpose is completion or help and user didn't type
any text yet then don't show completion/help for the upper
kpath levels but only for the current one.
Serj Kalichev 7 місяців тому
батько
коміт
e136f07b25
1 змінених файлів з 9 додано та 0 видалено
  1. 9 0
      klish/ksession/ksession_parse.c

+ 9 - 0
klish/ksession/ksession_parse.c

@@ -322,6 +322,7 @@ kpargv_t *ksession_parse_line(ksession_t *session, const faux_argv_t *argv,
 	klevel_t *level = NULL;
 	size_t level_found = 0; // Level where command was found
 	kpath_t *path = NULL;
+	bool_t dont_parse_upper;
 
 	assert(session);
 	if (!session)
@@ -332,6 +333,9 @@ kpargv_t *ksession_parse_line(ksession_t *session, const faux_argv_t *argv,
 
 	argv_iter = faux_argv_iter(argv);
 
+	dont_parse_upper = faux_argv_len(argv) == 0 &&
+		(purpose == KPURPOSE_COMPLETION || purpose == KPURPOSE_HELP);
+
 	// Initialize kpargv_t
 	pargv = kpargv_new();
 	assert(pargv);
@@ -360,6 +364,11 @@ kpargv_t *ksession_parse_line(ksession_t *session, const faux_argv_t *argv,
 		// levels of path.
 		if (kpargv_pargs_len(pargv) > 0)
 			break;
+		// When the purpose is completion or help and user didn't type
+		// any text yet then don't show completion/help for the upper
+		// kpath levels but only for the current one.
+		if (dont_parse_upper)
+			break;
 		level_found--;
 	}
 	// Save last argument