mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-24 16:12:01 +08:00
Remove autosuggest_suggest_special
This commit is contained in:
parent
718d9baead
commit
99e18d9cef
|
@ -1388,7 +1388,7 @@ void completer_t::complete_param_expand(const wcstring &str, bool do_file, bool
|
|||
|
||||
if (handle_as_special_cd && do_file)
|
||||
{
|
||||
flags |= DIRECTORIES_ONLY | EXPAND_SPECIAL_CD;
|
||||
flags |= DIRECTORIES_ONLY | EXPAND_SPECIAL_CD | EXPAND_NO_DESCRIPTIONS;
|
||||
}
|
||||
|
||||
/* Squelch file descriptions per issue 254 */
|
||||
|
|
|
@ -480,97 +480,6 @@ static bool autosuggest_parse_command(const wcstring &buff, wcstring *out_expand
|
|||
return result;
|
||||
}
|
||||
|
||||
/* We have to return an escaped string here */
|
||||
bool autosuggest_suggest_special(const wcstring &str, const env_vars_snapshot_t &vars, 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);
|
||||
if (! autosuggest_parse_command(str, &parsed_command, &last_arg_node))
|
||||
return false;
|
||||
|
||||
bool result = false;
|
||||
if (parsed_command == L"cd" && last_arg_node.type == symbol_argument && last_arg_node.has_source())
|
||||
{
|
||||
|
||||
/* 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;
|
||||
#if 1
|
||||
std::vector<completion_t> comps;
|
||||
complete(str, &comps, COMPLETION_REQUEST_AUTOSUGGESTION, vars);
|
||||
if (! comps.empty())
|
||||
{
|
||||
*out_suggestion = comps.at(0);
|
||||
|
||||
// Hackish to make tests pass
|
||||
if (!(out_suggestion->flags & COMPLETE_REPLACES_TOKEN))
|
||||
{
|
||||
out_suggestion->completion.insert(0, str);
|
||||
out_suggestion->flags |= COMPLETE_REPLACES_TOKEN;
|
||||
|
||||
wcstring escaped_dir = last_arg_node.get_source(str);
|
||||
wchar_t quote = L'\0';
|
||||
parse_util_get_parameter_info(escaped_dir, 0, "e, NULL, NULL);
|
||||
|
||||
out_suggestion->completion = parse_util_escape_string_with_quote(out_suggestion->completion, quote);
|
||||
|
||||
if (quote != L'\0') out_suggestion->completion.push_back(quote);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
#endif
|
||||
|
||||
/* We can possibly handle this specially */
|
||||
const wcstring escaped_dir = last_arg_node.get_source(str);
|
||||
wcstring suggested_path;
|
||||
|
||||
/* 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->completion.clear();
|
||||
|
||||
/* Unescape the parameter */
|
||||
wcstring unescaped_dir;
|
||||
bool unescaped = unescape_string(escaped_dir, &unescaped_dir, UNESCAPE_INCOMPLETE);
|
||||
|
||||
/* Determine the quote type we got from the input directory. */
|
||||
wchar_t quote = L'\0';
|
||||
parse_util_get_parameter_info(escaped_dir, 0, "e, NULL, NULL);
|
||||
|
||||
/* Big hack to avoid expanding a tilde inside quotes */
|
||||
path_flags_t path_flags = (quote == L'\0') ? PATH_EXPAND_TILDE : 0;
|
||||
env_var_t working_directory = vars.get(L"PWD");
|
||||
if (working_directory.missing_or_empty())
|
||||
{
|
||||
working_directory = L".";
|
||||
}
|
||||
|
||||
if (unescaped && is_potential_cd_path(unescaped_dir, working_directory, path_flags, &suggested_path))
|
||||
{
|
||||
/* Note: this looks really wrong for strings that have an "unescapable" character in them, e.g. a \t, because parse_util_escape_string_with_quote will insert that character */
|
||||
wcstring escaped_suggested_path = parse_util_escape_string_with_quote(suggested_path, quote);
|
||||
|
||||
/* Return it */
|
||||
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
|
||||
{
|
||||
/* Either an error or some other command, so we don't handle it specially */
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool autosuggest_validate_from_history(const history_item_t &item, file_detection_context_t &detector, const wcstring &working_directory, const env_vars_snapshot_t &vars)
|
||||
{
|
||||
ASSERT_IS_BACKGROUND_THREAD();
|
||||
|
|
|
@ -113,11 +113,6 @@ rgb_color_t highlight_get_color(highlight_spec_t highlight, bool is_background);
|
|||
*/
|
||||
bool autosuggest_validate_from_history(const history_item_t &item, file_detection_context_t &detector, const wcstring &working_directory, const env_vars_snapshot_t &vars);
|
||||
|
||||
/** 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).
|
||||
*/
|
||||
class completion_t;
|
||||
bool autosuggest_suggest_special(const wcstring &str, const env_vars_snapshot_t &vars, 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!
|
||||
|
||||
This is used only internally to this file, and is exposed only for testing.
|
||||
|
|
|
@ -1475,18 +1475,6 @@ struct autosuggestion_context_t
|
|||
}
|
||||
}
|
||||
|
||||
/* Maybe cancel here */
|
||||
if (reader_thread_job_is_stale())
|
||||
return 0;
|
||||
|
||||
/* Try handling a special command like cd */
|
||||
completion_t special_suggestion(L"");
|
||||
if (autosuggest_suggest_special(search_string, this->vars, &special_suggestion))
|
||||
{
|
||||
this->autosuggestion = special_suggestion.completion;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Maybe cancel here */
|
||||
if (reader_thread_job_is_stale())
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue
Block a user