aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-06 14:58:51 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-18 17:00:26 -0800
commit5dbf40ca750a1413c5000c6921bff04e17ccd55a (patch)
tree7c0f2c0546ee3c2c648a7881c98f23f90171dbca
parent2d68b250253eb07f8f796a6fe5f421efc90b70e1 (diff)
Switch autosuggest_suggest_special to returning a completion_t
-rw-r--r--src/fish_tests.cpp8
-rw-r--r--src/highlight.cpp17
-rw-r--r--src/highlight.h3
-rw-r--r--src/reader.cpp4
4 files changed, 17 insertions, 15 deletions
diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp
index fc2b2cab..2f627244 100644
--- a/src/fish_tests.cpp
+++ b/src/fish_tests.cpp
@@ -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);
}
}
diff --git a/src/highlight.cpp b/src/highlight.cpp
index d2427d7c..4e5dc3f3 100644
--- a/src/highlight.cpp
+++ b/src/highlight.cpp
@@ -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
diff --git a/src/highlight.h b/src/highlight.h
index 03e192a2..e2395afc 100644
--- a/src/highlight.h
+++ b/src/highlight.h
@@ -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!
diff --git a/src/reader.cpp b/src/reader.cpp
index a1027c39..d6eea53a 100644
--- a/src/reader.cpp
+++ b/src/reader.cpp
@@ -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;
}