summaryrefslogtreecommitdiff
path: root/Libraries/LibLine
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-05-22 22:40:42 +0430
committerAndreas Kling <kling@serenityos.org>2020-05-23 01:31:41 +0200
commit2427f3b38ba65948a63c61e121733bdf060851ea (patch)
tree2f97e9ae7165cec87c43b5333d30c39d7dc23796 /Libraries/LibLine
parentf0862cf2b702e0298c27103aec0e6a3a0d06990d (diff)
downloadserenity-2427f3b38ba65948a63c61e121733bdf060851ea.zip
LibLine: Add a constructor for CompletionSuggestions purely for comparison
`CompletionSuggestion(text, ForSearch)` creates a suggestion whose only purpose is to be compared against. This constructor skips initialising the views.
Diffstat (limited to 'Libraries/LibLine')
-rw-r--r--Libraries/LibLine/SuggestionManager.cpp6
-rw-r--r--Libraries/LibLine/SuggestionManager.h15
2 files changed, 20 insertions, 1 deletions
diff --git a/Libraries/LibLine/SuggestionManager.cpp b/Libraries/LibLine/SuggestionManager.cpp
index 8284b38a20..88a8cdcde4 100644
--- a/Libraries/LibLine/SuggestionManager.cpp
+++ b/Libraries/LibLine/SuggestionManager.cpp
@@ -32,6 +32,7 @@ namespace Line {
CompletionSuggestion::CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia, Style style)
: style(style)
, text_string(completion)
+ , is_valid(true)
{
Utf8View text_u8 { completion };
Utf8View trivia_u8 { trailing_trivia };
@@ -49,6 +50,11 @@ CompletionSuggestion::CompletionSuggestion(const StringView& completion, const S
void SuggestionManager::set_suggestions(Vector<CompletionSuggestion>&& suggestions)
{
m_suggestions = move(suggestions);
+
+ // make sure we were not given invalid suggestions
+ for (auto& suggestion : m_suggestions)
+ ASSERT(suggestion.is_valid);
+
size_t common_suggestion_prefix { 0 };
if (m_suggestions.size() == 1) {
m_largest_common_suggestion_prefix_length = m_suggestions[0].text_view.length();
diff --git a/Libraries/LibLine/SuggestionManager.h b/Libraries/LibLine/SuggestionManager.h
index 6b7918242c..47821b6bb0 100644
--- a/Libraries/LibLine/SuggestionManager.h
+++ b/Libraries/LibLine/SuggestionManager.h
@@ -37,12 +37,24 @@ namespace Line {
// FIXME: These objects are pretty heavy since they store two copies of text
// somehow get rid of one
struct CompletionSuggestion {
+private:
+ struct ForSearchTag {
+ };
+
+public:
+ static constexpr ForSearchTag ForSearch {};
+
// intentionally not explicit (allows suggesting bare strings)
CompletionSuggestion(const String& completion)
: CompletionSuggestion(completion, "", {})
{
}
+ CompletionSuggestion(const String& completion, ForSearchTag)
+ : text_string(completion)
+ {
+ }
+
CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia)
: CompletionSuggestion(completion, trailing_trivia, {})
{
@@ -52,7 +64,7 @@ struct CompletionSuggestion {
bool operator==(const CompletionSuggestion& suggestion) const
{
- return suggestion.text == text;
+ return suggestion.text_string == text_string;
}
Vector<u32> text;
@@ -63,6 +75,7 @@ struct CompletionSuggestion {
Utf32View text_view;
Utf32View trivia_view;
String text_string;
+ bool is_valid { false };
};
class SuggestionManager {