mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
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.
This commit is contained in:
parent
f0862cf2b7
commit
2427f3b38b
2 changed files with 20 additions and 1 deletions
|
@ -32,6 +32,7 @@ namespace Line {
|
||||||
CompletionSuggestion::CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia, Style style)
|
CompletionSuggestion::CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia, Style style)
|
||||||
: style(style)
|
: style(style)
|
||||||
, text_string(completion)
|
, text_string(completion)
|
||||||
|
, is_valid(true)
|
||||||
{
|
{
|
||||||
Utf8View text_u8 { completion };
|
Utf8View text_u8 { completion };
|
||||||
Utf8View trivia_u8 { trailing_trivia };
|
Utf8View trivia_u8 { trailing_trivia };
|
||||||
|
@ -49,6 +50,11 @@ CompletionSuggestion::CompletionSuggestion(const StringView& completion, const S
|
||||||
void SuggestionManager::set_suggestions(Vector<CompletionSuggestion>&& suggestions)
|
void SuggestionManager::set_suggestions(Vector<CompletionSuggestion>&& suggestions)
|
||||||
{
|
{
|
||||||
m_suggestions = move(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 };
|
size_t common_suggestion_prefix { 0 };
|
||||||
if (m_suggestions.size() == 1) {
|
if (m_suggestions.size() == 1) {
|
||||||
m_largest_common_suggestion_prefix_length = m_suggestions[0].text_view.length();
|
m_largest_common_suggestion_prefix_length = m_suggestions[0].text_view.length();
|
||||||
|
|
|
@ -37,12 +37,24 @@ namespace Line {
|
||||||
// FIXME: These objects are pretty heavy since they store two copies of text
|
// FIXME: These objects are pretty heavy since they store two copies of text
|
||||||
// somehow get rid of one
|
// somehow get rid of one
|
||||||
struct CompletionSuggestion {
|
struct CompletionSuggestion {
|
||||||
|
private:
|
||||||
|
struct ForSearchTag {
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
static constexpr ForSearchTag ForSearch {};
|
||||||
|
|
||||||
// intentionally not explicit (allows suggesting bare strings)
|
// intentionally not explicit (allows suggesting bare strings)
|
||||||
CompletionSuggestion(const String& completion)
|
CompletionSuggestion(const String& completion)
|
||||||
: CompletionSuggestion(completion, "", {})
|
: CompletionSuggestion(completion, "", {})
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompletionSuggestion(const String& completion, ForSearchTag)
|
||||||
|
: text_string(completion)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia)
|
CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia)
|
||||||
: CompletionSuggestion(completion, trailing_trivia, {})
|
: CompletionSuggestion(completion, trailing_trivia, {})
|
||||||
{
|
{
|
||||||
|
@ -52,7 +64,7 @@ struct CompletionSuggestion {
|
||||||
|
|
||||||
bool operator==(const CompletionSuggestion& suggestion) const
|
bool operator==(const CompletionSuggestion& suggestion) const
|
||||||
{
|
{
|
||||||
return suggestion.text == text;
|
return suggestion.text_string == text_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<u32> text;
|
Vector<u32> text;
|
||||||
|
@ -63,6 +75,7 @@ struct CompletionSuggestion {
|
||||||
Utf32View text_view;
|
Utf32View text_view;
|
||||||
Utf32View trivia_view;
|
Utf32View trivia_view;
|
||||||
String text_string;
|
String text_string;
|
||||||
|
bool is_valid { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class SuggestionManager {
|
class SuggestionManager {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue