mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 19:05:08 +00:00
HackStudio: Fuzzy-match Locator suggestions
This also sorts them to put better results first. Currently the fuzzy-match algorithm gets a little confused, but as that improves, so will this.
This commit is contained in:
parent
85101c6626
commit
4b1c7533f5
2 changed files with 18 additions and 11 deletions
|
@ -8,9 +8,17 @@
|
||||||
|
|
||||||
#include "DeclarationsModel.h"
|
#include "DeclarationsModel.h"
|
||||||
#include "ProjectDeclarations.h"
|
#include "ProjectDeclarations.h"
|
||||||
|
#include <AK/FuzzyMatch.h>
|
||||||
|
|
||||||
namespace HackStudio {
|
namespace HackStudio {
|
||||||
|
|
||||||
|
static String qualified_symbol_name(CodeComprehension::Declaration symbol)
|
||||||
|
{
|
||||||
|
if (!symbol.scope.is_empty())
|
||||||
|
return MUST(String::from_byte_string(symbol.name));
|
||||||
|
return MUST(String::formatted("{}::{}", symbol.scope, symbol.name));
|
||||||
|
}
|
||||||
|
|
||||||
Declaration Declaration::create_filename(ByteString const& filename)
|
Declaration Declaration::create_filename(ByteString const& filename)
|
||||||
{
|
{
|
||||||
Declaration s;
|
Declaration s;
|
||||||
|
@ -39,11 +47,8 @@ GUI::Variant DeclarationsModel::data(GUI::ModelIndex const& index, GUI::ModelRol
|
||||||
return GUI::FileIconProvider::icon_for_path(suggestion.as_filename.value());
|
return GUI::FileIconProvider::icon_for_path(suggestion.as_filename.value());
|
||||||
}
|
}
|
||||||
if (suggestion.is_symbol_declaration()) {
|
if (suggestion.is_symbol_declaration()) {
|
||||||
if (index.column() == Column::Name) {
|
if (index.column() == Column::Name)
|
||||||
if (!suggestion.as_symbol_declaration.value().scope.is_empty())
|
return qualified_symbol_name(suggestion.as_symbol_declaration.value());
|
||||||
return suggestion.as_symbol_declaration.value().name;
|
|
||||||
return ByteString::formatted("{}::{}", suggestion.as_symbol_declaration.value().scope, suggestion.as_symbol_declaration.value().name);
|
|
||||||
}
|
|
||||||
if (index.column() == Column::Filename)
|
if (index.column() == Column::Filename)
|
||||||
return suggestion.as_symbol_declaration.value().position.file;
|
return suggestion.as_symbol_declaration.value().position.file;
|
||||||
if (index.column() == Column::Icon) {
|
if (index.column() == Column::Icon) {
|
||||||
|
@ -68,14 +73,15 @@ GUI::Model::MatchResult DeclarationsModel::data_matches(GUI::ModelIndex const& i
|
||||||
|
|
||||||
auto& declaration = m_declarations[index.row()];
|
auto& declaration = m_declarations[index.row()];
|
||||||
if (declaration.is_filename()) {
|
if (declaration.is_filename()) {
|
||||||
if (declaration.as_filename->contains(needle, CaseSensitivity::CaseInsensitive))
|
if (auto match_result = fuzzy_match(needle, *declaration.as_filename); match_result.matched)
|
||||||
return { TriState::True };
|
return { TriState::True, match_result.score };
|
||||||
return { TriState::False };
|
return { TriState::False };
|
||||||
}
|
}
|
||||||
if (declaration.is_symbol_declaration()) {
|
if (declaration.is_symbol_declaration()) {
|
||||||
if (declaration.as_symbol_declaration->name.contains(needle, CaseSensitivity::CaseInsensitive)
|
auto& symbol = *declaration.as_symbol_declaration;
|
||||||
|| declaration.as_symbol_declaration->scope.contains(needle, CaseSensitivity::CaseInsensitive))
|
auto haystack = qualified_symbol_name(symbol);
|
||||||
return { TriState::True };
|
if (auto match_result = fuzzy_match(needle, haystack); match_result.matched)
|
||||||
|
return { TriState::True, match_result.score };
|
||||||
return { TriState::False };
|
return { TriState::False };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2022, the SerenityOS developers.
|
* Copyright (c) 2022, the SerenityOS developers.
|
||||||
|
* Copyright (c) 2024, Sam Atkins <atkinssj@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -78,7 +79,7 @@ Locator::Locator(Core::EventReceiver* parent)
|
||||||
open_suggestion(index);
|
open_suggestion(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_model = GUI::FilteringProxyModel::create(ProjectDeclarations::the().declarations_model()).release_value_but_fixme_should_propagate_errors();
|
m_model = GUI::FilteringProxyModel::create(ProjectDeclarations::the().declarations_model(), GUI::FilteringProxyModel::FilteringOptions::SortByScore).release_value_but_fixme_should_propagate_errors();
|
||||||
m_suggestion_view->set_model(m_model);
|
m_suggestion_view->set_model(m_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue