mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-18 01:23:15 +08:00
Switch autosuggest_suggest_special to returning a completion_t
This commit is contained in:
parent
2d68b25025
commit
5dbf40ca75
|
@ -2301,19 +2301,19 @@ static void test_completion_insertions()
|
|||
|
||||
static void perform_one_autosuggestion_special_test(const wcstring &command, const wcstring &wd, const wcstring &expected, long line)
|
||||
{
|
||||
wcstring suggestion;
|
||||
completion_t suggestion(L"");
|
||||
bool success = autosuggest_suggest_special(command, wd, &suggestion);
|
||||
if (! success)
|
||||
{
|
||||
printf("line %ld: autosuggest_suggest_special() failed for command %ls\n", line, command.c_str());
|
||||
do_test(success);
|
||||
}
|
||||
if (suggestion != expected)
|
||||
if (suggestion.completion != expected)
|
||||
{
|
||||
printf("line %ld: autosuggest_suggest_special() returned the wrong expected string for command %ls\n", line, command.c_str());
|
||||
printf(" actual: %ls\n", suggestion.c_str());
|
||||
printf(" actual: %ls\n", suggestion.completion.c_str());
|
||||
printf("expected: %ls\n", expected.c_str());
|
||||
do_test(suggestion == expected);
|
||||
do_test(suggestion.completion == expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -480,13 +480,13 @@ static bool autosuggest_parse_command(const wcstring &buff, wcstring *out_expand
|
|||
}
|
||||
|
||||
/* We have to return an escaped string here */
|
||||
bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_directory, wcstring *out_suggestion)
|
||||
bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_directory, completion_t *out_suggestion)
|
||||
{
|
||||
if (str.empty())
|
||||
return false;
|
||||
|
||||
ASSERT_IS_BACKGROUND_THREAD();
|
||||
|
||||
|
||||
/* Parse the string */
|
||||
wcstring parsed_command;
|
||||
parse_node_t last_arg_node(token_type_invalid);
|
||||
|
@ -502,7 +502,7 @@ bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_di
|
|||
|
||||
/* We always return true because we recognized the command. This prevents us from falling back to dumber algorithms; for example we won't suggest a non-directory for the cd command. */
|
||||
result = true;
|
||||
out_suggestion->clear();
|
||||
out_suggestion->completion.clear();
|
||||
|
||||
/* Unescape the parameter */
|
||||
wcstring unescaped_dir;
|
||||
|
@ -520,11 +520,12 @@ bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_di
|
|||
wcstring escaped_suggested_path = parse_util_escape_string_with_quote(suggested_path, quote);
|
||||
|
||||
/* Return it */
|
||||
out_suggestion->assign(str);
|
||||
out_suggestion->erase(last_arg_node.source_start);
|
||||
if (quote != L'\0') out_suggestion->push_back(quote);
|
||||
out_suggestion->append(escaped_suggested_path);
|
||||
if (quote != L'\0') out_suggestion->push_back(quote);
|
||||
wcstring suggestion = str;
|
||||
suggestion.erase(last_arg_node.source_start);
|
||||
if (quote != L'\0') suggestion.push_back(quote);
|
||||
suggestion.append(escaped_suggested_path);
|
||||
if (quote != L'\0') suggestion.push_back(quote);
|
||||
*out_suggestion = completion_t(suggestion, L"", fuzzy_match_exact, COMPLETE_REPLACES_TOKEN);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -115,7 +115,8 @@ bool autosuggest_validate_from_history(const history_item_t &item, file_detectio
|
|||
|
||||
/** Given the command line contents 'str', return via reference a suggestion by specially recognizing the command. The suggestion is escaped. Returns true if we recognized the command (even if we couldn't think of a suggestion for it).
|
||||
*/
|
||||
bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_directory, wcstring *out_suggestion);
|
||||
class completion_t;
|
||||
bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_directory, completion_t *out_suggestion);
|
||||
|
||||
/* Tests whether the specified string cpath is the prefix of anything we could cd to. directories is a list of possible parent directories (typically either the working directory, or the cdpath). This does I/O!
|
||||
|
||||
|
|
|
@ -1482,10 +1482,10 @@ struct autosuggestion_context_t
|
|||
return 0;
|
||||
|
||||
/* Try handling a special command like cd */
|
||||
wcstring special_suggestion;
|
||||
completion_t special_suggestion(L"");
|
||||
if (autosuggest_suggest_special(search_string, working_directory, &special_suggestion))
|
||||
{
|
||||
this->autosuggestion = special_suggestion;
|
||||
this->autosuggestion = special_suggestion.completion;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user