mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
Everywhere: Run clang-format
This commit is contained in:
parent
0376c127f6
commit
086969277e
1665 changed files with 8479 additions and 8479 deletions
|
@ -19,7 +19,7 @@ private:
|
|||
: LanguageServers::ConnectionFromClient(move(socket))
|
||||
{
|
||||
m_autocomplete_engine = make<CppComprehensionEngine>(m_filedb);
|
||||
m_autocomplete_engine->set_declarations_of_document_callback = [this](const String& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations) {
|
||||
m_autocomplete_engine->set_declarations_of_document_callback = [this](String const& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations) {
|
||||
async_declarations_in_document(filename, move(declarations));
|
||||
};
|
||||
m_autocomplete_engine->set_todo_entries_of_document_callback = [this](String const& filename, Vector<Cpp::Parser::TodoEntry>&& todo_entries) {
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
|
||||
namespace LanguageServers::Cpp {
|
||||
|
||||
CppComprehensionEngine::CppComprehensionEngine(const FileDB& filedb)
|
||||
CppComprehensionEngine::CppComprehensionEngine(FileDB const& filedb)
|
||||
: CodeComprehensionEngine(filedb, true)
|
||||
{
|
||||
}
|
||||
|
||||
const CppComprehensionEngine::DocumentData* CppComprehensionEngine::get_or_create_document_data(const String& file)
|
||||
CppComprehensionEngine::DocumentData const* CppComprehensionEngine::get_or_create_document_data(String const& file)
|
||||
{
|
||||
auto absolute_path = filedb().to_absolute_path(file);
|
||||
if (!m_documents.contains(absolute_path)) {
|
||||
|
@ -34,7 +34,7 @@ const CppComprehensionEngine::DocumentData* CppComprehensionEngine::get_or_creat
|
|||
return get_document_data(absolute_path);
|
||||
}
|
||||
|
||||
const CppComprehensionEngine::DocumentData* CppComprehensionEngine::get_document_data(const String& file) const
|
||||
CppComprehensionEngine::DocumentData const* CppComprehensionEngine::get_document_data(String const& file) const
|
||||
{
|
||||
auto absolute_path = filedb().to_absolute_path(file);
|
||||
auto document_data = m_documents.get(absolute_path);
|
||||
|
@ -43,7 +43,7 @@ const CppComprehensionEngine::DocumentData* CppComprehensionEngine::get_document
|
|||
return document_data.value();
|
||||
}
|
||||
|
||||
OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data_for(const String& file)
|
||||
OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data_for(String const& file)
|
||||
{
|
||||
if (m_unfinished_documents.contains(file)) {
|
||||
return {};
|
||||
|
@ -56,22 +56,22 @@ OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_docu
|
|||
return create_document_data(document->text(), file);
|
||||
}
|
||||
|
||||
void CppComprehensionEngine::set_document_data(const String& file, OwnPtr<DocumentData>&& data)
|
||||
void CppComprehensionEngine::set_document_data(String const& file, OwnPtr<DocumentData>&& data)
|
||||
{
|
||||
m_documents.set(filedb().to_absolute_path(file), move(data));
|
||||
}
|
||||
|
||||
Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position)
|
||||
Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::get_suggestions(String const& file, const GUI::TextPosition& autocomplete_position)
|
||||
{
|
||||
Cpp::Position position { autocomplete_position.line(), autocomplete_position.column() > 0 ? autocomplete_position.column() - 1 : 0 };
|
||||
|
||||
dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "CppComprehensionEngine position {}:{}", position.line, position.column);
|
||||
|
||||
const auto* document_ptr = get_or_create_document_data(file);
|
||||
auto const* document_ptr = get_or_create_document_data(file);
|
||||
if (!document_ptr)
|
||||
return {};
|
||||
|
||||
const auto& document = *document_ptr;
|
||||
auto const& document = *document_ptr;
|
||||
auto containing_token = document.parser().token_at(position);
|
||||
|
||||
if (containing_token.has_value() && containing_token->type() == Token::Type::IncludePath) {
|
||||
|
@ -102,7 +102,7 @@ Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::get_suggestions
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_autocomplete_name(const DocumentData& document, const ASTNode& node, Optional<Token> containing_token) const
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_autocomplete_name(DocumentData const& document, ASTNode const& node, Optional<Token> containing_token) const
|
||||
{
|
||||
auto partial_text = String::empty();
|
||||
if (containing_token.has_value() && containing_token.value().type() != Token::Type::ColonColon) {
|
||||
|
@ -111,7 +111,7 @@ Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_a
|
|||
return autocomplete_name(document, node, partial_text);
|
||||
}
|
||||
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_autocomplete_property(const DocumentData& document, const ASTNode& node, Optional<Token> containing_token) const
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_autocomplete_property(DocumentData const& document, ASTNode const& node, Optional<Token> containing_token) const
|
||||
{
|
||||
if (!containing_token.has_value())
|
||||
return {};
|
||||
|
@ -119,7 +119,7 @@ Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_a
|
|||
if (!node.parent()->is_member_expression())
|
||||
return {};
|
||||
|
||||
const auto& parent = static_cast<const MemberExpression&>(*node.parent());
|
||||
auto const& parent = static_cast<MemberExpression const&>(*node.parent());
|
||||
|
||||
auto partial_text = String::empty();
|
||||
if (containing_token.value().type() != Token::Type::Dot) {
|
||||
|
@ -131,12 +131,12 @@ Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_a
|
|||
return autocomplete_property(document, parent, partial_text);
|
||||
}
|
||||
|
||||
Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_name(const DocumentData& document, const ASTNode& node, const String& partial_text) const
|
||||
Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_name(DocumentData const& document, ASTNode const& node, String const& partial_text) const
|
||||
{
|
||||
auto reference_scope = scope_of_reference_to_symbol(node);
|
||||
auto current_scope = scope_of_node(node);
|
||||
|
||||
auto symbol_matches = [&](const Symbol& symbol) {
|
||||
auto symbol_matches = [&](Symbol const& symbol) {
|
||||
if (!is_symbol_available(symbol, current_scope, reference_scope)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_na
|
|||
|
||||
Vector<Symbol> matches;
|
||||
|
||||
for_each_available_symbol(document, [&](const Symbol& symbol) {
|
||||
for_each_available_symbol(document, [&](Symbol const& symbol) {
|
||||
if (symbol_matches(symbol)) {
|
||||
matches.append(symbol);
|
||||
}
|
||||
|
@ -179,17 +179,17 @@ Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_na
|
|||
return suggestions;
|
||||
}
|
||||
|
||||
Vector<StringView> CppComprehensionEngine::scope_of_reference_to_symbol(const ASTNode& node) const
|
||||
Vector<StringView> CppComprehensionEngine::scope_of_reference_to_symbol(ASTNode const& node) const
|
||||
{
|
||||
const Name* name = nullptr;
|
||||
Name const* name = nullptr;
|
||||
if (node.is_name()) {
|
||||
// FIXME It looks like this code path is never taken
|
||||
name = reinterpret_cast<const Name*>(&node);
|
||||
name = reinterpret_cast<Name const*>(&node);
|
||||
} else if (node.is_identifier()) {
|
||||
auto* parent = node.parent();
|
||||
if (!(parent && parent->is_name()))
|
||||
return {};
|
||||
name = reinterpret_cast<const Name*>(parent);
|
||||
name = reinterpret_cast<Name const*>(parent);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ Vector<StringView> CppComprehensionEngine::scope_of_reference_to_symbol(const AS
|
|||
return scope_parts;
|
||||
}
|
||||
|
||||
Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_property(const DocumentData& document, const MemberExpression& parent, const String partial_text) const
|
||||
Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_property(DocumentData const& document, MemberExpression const& parent, const String partial_text) const
|
||||
{
|
||||
VERIFY(parent.object());
|
||||
auto type = type_of(document, *parent.object());
|
||||
|
@ -224,7 +224,7 @@ Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_pr
|
|||
return suggestions;
|
||||
}
|
||||
|
||||
bool CppComprehensionEngine::is_property(const ASTNode& node) const
|
||||
bool CppComprehensionEngine::is_property(ASTNode const& node) const
|
||||
{
|
||||
if (!node.parent()->is_member_expression())
|
||||
return false;
|
||||
|
@ -233,7 +233,7 @@ bool CppComprehensionEngine::is_property(const ASTNode& node) const
|
|||
return parent.property() == &node;
|
||||
}
|
||||
|
||||
String CppComprehensionEngine::type_of_property(const DocumentData& document, const Identifier& identifier) const
|
||||
String CppComprehensionEngine::type_of_property(DocumentData const& document, Identifier const& identifier) const
|
||||
{
|
||||
auto& parent = verify_cast<MemberExpression>(*identifier.parent());
|
||||
VERIFY(parent.object());
|
||||
|
@ -241,7 +241,7 @@ String CppComprehensionEngine::type_of_property(const DocumentData& document, co
|
|||
for (auto& prop : properties) {
|
||||
if (prop.name.name != identifier.name())
|
||||
continue;
|
||||
const Type* type { nullptr };
|
||||
Type const* type { nullptr };
|
||||
if (prop.declaration->is_variable_declaration()) {
|
||||
type = verify_cast<VariableDeclaration>(*prop.declaration).type();
|
||||
}
|
||||
|
@ -258,9 +258,9 @@ String CppComprehensionEngine::type_of_property(const DocumentData& document, co
|
|||
return {};
|
||||
}
|
||||
|
||||
String CppComprehensionEngine::type_of_variable(const Identifier& identifier) const
|
||||
String CppComprehensionEngine::type_of_variable(Identifier const& identifier) const
|
||||
{
|
||||
const ASTNode* current = &identifier;
|
||||
ASTNode const* current = &identifier;
|
||||
while (current) {
|
||||
for (auto& decl : current->declarations()) {
|
||||
if (decl.is_variable_or_parameter_declaration()) {
|
||||
|
@ -278,21 +278,21 @@ String CppComprehensionEngine::type_of_variable(const Identifier& identifier) co
|
|||
return {};
|
||||
}
|
||||
|
||||
String CppComprehensionEngine::type_of(const DocumentData& document, const Expression& expression) const
|
||||
String CppComprehensionEngine::type_of(DocumentData const& document, Expression const& expression) const
|
||||
{
|
||||
if (expression.is_member_expression()) {
|
||||
auto& member_expression = verify_cast<MemberExpression>(expression);
|
||||
VERIFY(member_expression.property());
|
||||
if (member_expression.property()->is_identifier())
|
||||
return type_of_property(document, static_cast<const Identifier&>(*member_expression.property()));
|
||||
return type_of_property(document, static_cast<Identifier const&>(*member_expression.property()));
|
||||
return {};
|
||||
}
|
||||
|
||||
const Identifier* identifier { nullptr };
|
||||
Identifier const* identifier { nullptr };
|
||||
if (expression.is_name()) {
|
||||
identifier = static_cast<const Name&>(expression).name();
|
||||
identifier = static_cast<Name const&>(expression).name();
|
||||
} else if (expression.is_identifier()) {
|
||||
identifier = &static_cast<const Identifier&>(expression);
|
||||
identifier = &static_cast<Identifier const&>(expression);
|
||||
} else {
|
||||
dbgln("expected identifier or name, got: {}", expression.class_name());
|
||||
VERIFY_NOT_REACHED(); // TODO
|
||||
|
@ -304,7 +304,7 @@ String CppComprehensionEngine::type_of(const DocumentData& document, const Expre
|
|||
return type_of_variable(*identifier);
|
||||
}
|
||||
|
||||
Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::properties_of_type(const DocumentData& document, const String& type) const
|
||||
Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::properties_of_type(DocumentData const& document, String const& type) const
|
||||
{
|
||||
auto type_symbol = SymbolName::create(type);
|
||||
auto decl = find_declaration_of(document, type_symbol);
|
||||
|
@ -331,17 +331,17 @@ Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::properties_of_typ
|
|||
return properties;
|
||||
}
|
||||
|
||||
CppComprehensionEngine::Symbol CppComprehensionEngine::Symbol::create(StringView name, const Vector<StringView>& scope, NonnullRefPtr<Declaration> declaration, IsLocal is_local)
|
||||
CppComprehensionEngine::Symbol CppComprehensionEngine::Symbol::create(StringView name, Vector<StringView> const& scope, NonnullRefPtr<Declaration> declaration, IsLocal is_local)
|
||||
{
|
||||
return { { name, scope }, move(declaration), is_local == IsLocal::Yes };
|
||||
}
|
||||
|
||||
Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::get_child_symbols(const ASTNode& node) const
|
||||
Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::get_child_symbols(ASTNode const& node) const
|
||||
{
|
||||
return get_child_symbols(node, {}, Symbol::IsLocal::No);
|
||||
}
|
||||
|
||||
Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::get_child_symbols(const ASTNode& node, const Vector<StringView>& scope, Symbol::IsLocal is_local) const
|
||||
Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::get_child_symbols(ASTNode const& node, Vector<StringView> const& scope, Symbol::IsLocal is_local) const
|
||||
{
|
||||
Vector<Symbol> symbols;
|
||||
|
||||
|
@ -391,23 +391,23 @@ String CppComprehensionEngine::document_path_from_include_path(StringView includ
|
|||
return result;
|
||||
}
|
||||
|
||||
void CppComprehensionEngine::on_edit(const String& file)
|
||||
void CppComprehensionEngine::on_edit(String const& file)
|
||||
{
|
||||
set_document_data(file, create_document_data_for(file));
|
||||
}
|
||||
|
||||
void CppComprehensionEngine::file_opened([[maybe_unused]] const String& file)
|
||||
void CppComprehensionEngine::file_opened([[maybe_unused]] String const& file)
|
||||
{
|
||||
get_or_create_document_data(file);
|
||||
}
|
||||
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position)
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::find_declaration_of(String const& filename, const GUI::TextPosition& identifier_position)
|
||||
{
|
||||
const auto* document_ptr = get_or_create_document_data(filename);
|
||||
auto const* document_ptr = get_or_create_document_data(filename);
|
||||
if (!document_ptr)
|
||||
return {};
|
||||
|
||||
const auto& document = *document_ptr;
|
||||
auto const& document = *document_ptr;
|
||||
auto decl = find_declaration_of(document, identifier_position);
|
||||
if (decl) {
|
||||
return GUI::AutocompleteProvider::ProjectLocation { decl->filename(), decl->start().line, decl->start().column };
|
||||
|
@ -416,7 +416,7 @@ Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::fin
|
|||
return find_preprocessor_definition(document, identifier_position);
|
||||
}
|
||||
|
||||
RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const DocumentData& document, const GUI::TextPosition& identifier_position)
|
||||
RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(DocumentData const& document, const GUI::TextPosition& identifier_position)
|
||||
{
|
||||
auto node = document.parser().node_at(Cpp::Position { identifier_position.line(), identifier_position.column() });
|
||||
if (!node) {
|
||||
|
@ -426,7 +426,7 @@ RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const DocumentDa
|
|||
return find_declaration_of(document, *node);
|
||||
}
|
||||
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::find_preprocessor_definition(const DocumentData& document, const GUI::TextPosition& text_position)
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::find_preprocessor_definition(DocumentData const& document, const GUI::TextPosition& text_position)
|
||||
{
|
||||
Position cpp_position { text_position.line(), text_position.column() };
|
||||
auto substitution = find_preprocessor_substitution(document, cpp_position);
|
||||
|
@ -459,11 +459,11 @@ struct TargetDeclaration {
|
|||
String name;
|
||||
};
|
||||
|
||||
static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node, String name);
|
||||
static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node)
|
||||
static Optional<TargetDeclaration> get_target_declaration(ASTNode const& node, String name);
|
||||
static Optional<TargetDeclaration> get_target_declaration(ASTNode const& node)
|
||||
{
|
||||
if (node.is_identifier()) {
|
||||
return get_target_declaration(node, static_cast<const Identifier&>(node).name());
|
||||
return get_target_declaration(node, static_cast<Identifier const&>(node).name());
|
||||
}
|
||||
|
||||
if (node.is_declaration()) {
|
||||
|
@ -478,7 +478,7 @@ static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node)
|
|||
return {};
|
||||
}
|
||||
|
||||
static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node, String name)
|
||||
static Optional<TargetDeclaration> get_target_declaration(ASTNode const& node, String name)
|
||||
{
|
||||
if (node.parent() && node.parent()->is_name()) {
|
||||
auto& name_node = *verify_cast<Name>(node.parent());
|
||||
|
@ -509,7 +509,7 @@ static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node, S
|
|||
|
||||
return TargetDeclaration { TargetDeclaration::Type::Variable, name };
|
||||
}
|
||||
RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const DocumentData& document_data, const ASTNode& node) const
|
||||
RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(DocumentData const& document_data, ASTNode const& node) const
|
||||
{
|
||||
dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "find_declaration_of: {} ({})", document_data.parser().text_of_node(node), node.class_name());
|
||||
|
||||
|
@ -520,7 +520,7 @@ RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const DocumentDa
|
|||
auto reference_scope = scope_of_reference_to_symbol(node);
|
||||
auto current_scope = scope_of_node(node);
|
||||
|
||||
auto symbol_matches = [&](const Symbol& symbol) {
|
||||
auto symbol_matches = [&](Symbol const& symbol) {
|
||||
bool match_function = target_decl.value().type == TargetDeclaration::Function && symbol.declaration->is_function();
|
||||
bool match_variable = target_decl.value().type == TargetDeclaration::Variable && symbol.declaration->is_variable_declaration();
|
||||
bool match_type = target_decl.value().type == TargetDeclaration::Type && (symbol.declaration->is_struct_or_class() || symbol.declaration->is_enum());
|
||||
|
@ -558,7 +558,7 @@ RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const DocumentDa
|
|||
|
||||
Optional<Symbol> match;
|
||||
|
||||
for_each_available_symbol(document_data, [&](const Symbol& symbol) {
|
||||
for_each_available_symbol(document_data, [&](Symbol const& symbol) {
|
||||
if (symbol_matches(symbol)) {
|
||||
match = symbol;
|
||||
return IterationDecision::Break;
|
||||
|
@ -595,7 +595,7 @@ void CppComprehensionEngine::update_todo_entries(DocumentData& document)
|
|||
set_todo_entries_of_document(document.filename(), document.parser().get_todo_entries());
|
||||
}
|
||||
|
||||
GUI::AutocompleteProvider::DeclarationType CppComprehensionEngine::type_of_declaration(const Declaration& decl)
|
||||
GUI::AutocompleteProvider::DeclarationType CppComprehensionEngine::type_of_declaration(Declaration const& decl)
|
||||
{
|
||||
if (decl.is_struct())
|
||||
return GUI::AutocompleteProvider::DeclarationType::Struct;
|
||||
|
@ -612,7 +612,7 @@ GUI::AutocompleteProvider::DeclarationType CppComprehensionEngine::type_of_decla
|
|||
return GUI::AutocompleteProvider::DeclarationType::Variable;
|
||||
}
|
||||
|
||||
OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data(String&& text, const String& filename)
|
||||
OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data(String&& text, String const& filename)
|
||||
{
|
||||
auto document_data = make<DocumentData>();
|
||||
document_data->m_filename = filename;
|
||||
|
@ -657,7 +657,7 @@ OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_docu
|
|||
return document_data;
|
||||
}
|
||||
|
||||
Vector<StringView> CppComprehensionEngine::scope_of_node(const ASTNode& node) const
|
||||
Vector<StringView> CppComprehensionEngine::scope_of_node(ASTNode const& node) const
|
||||
{
|
||||
|
||||
auto parent = node.parent();
|
||||
|
@ -683,7 +683,7 @@ Vector<StringView> CppComprehensionEngine::scope_of_node(const ASTNode& node) co
|
|||
return parent_scope;
|
||||
}
|
||||
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_autocomplete_include(const DocumentData&, Token include_path_token, Cpp::Position const& cursor_position) const
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_autocomplete_include(DocumentData const&, Token include_path_token, Cpp::Position const& cursor_position) const
|
||||
{
|
||||
VERIFY(include_path_token.type() == Token::Type::IncludePath);
|
||||
auto partial_include = include_path_token.text().trim_whitespace();
|
||||
|
@ -751,10 +751,10 @@ Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::try_a
|
|||
return options;
|
||||
}
|
||||
|
||||
RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const CppComprehensionEngine::DocumentData& document, const CppComprehensionEngine::SymbolName& target_symbol_name) const
|
||||
RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(CppComprehensionEngine::DocumentData const& document, CppComprehensionEngine::SymbolName const& target_symbol_name) const
|
||||
{
|
||||
RefPtr<Declaration> target_declaration;
|
||||
for_each_available_symbol(document, [&](const Symbol& symbol) {
|
||||
for_each_available_symbol(document, [&](Symbol const& symbol) {
|
||||
if (symbol.name == target_symbol_name) {
|
||||
target_declaration = symbol.declaration;
|
||||
return IterationDecision::Break;
|
||||
|
@ -797,7 +797,7 @@ String CppComprehensionEngine::SymbolName::to_string() const
|
|||
return String::formatted("{}::{}", scope_as_string(), name);
|
||||
}
|
||||
|
||||
bool CppComprehensionEngine::is_symbol_available(const Symbol& symbol, const Vector<StringView>& current_scope, const Vector<StringView>& reference_scope)
|
||||
bool CppComprehensionEngine::is_symbol_available(Symbol const& symbol, Vector<StringView> const& current_scope, Vector<StringView> const& reference_scope)
|
||||
{
|
||||
|
||||
if (!reference_scope.is_empty()) {
|
||||
|
@ -818,13 +818,13 @@ bool CppComprehensionEngine::is_symbol_available(const Symbol& symbol, const Vec
|
|||
return true;
|
||||
}
|
||||
|
||||
Optional<CodeComprehensionEngine::FunctionParamsHint> CppComprehensionEngine::get_function_params_hint(const String& filename, const GUI::TextPosition& identifier_position)
|
||||
Optional<CodeComprehensionEngine::FunctionParamsHint> CppComprehensionEngine::get_function_params_hint(String const& filename, const GUI::TextPosition& identifier_position)
|
||||
{
|
||||
const auto* document_ptr = get_or_create_document_data(filename);
|
||||
auto const* document_ptr = get_or_create_document_data(filename);
|
||||
if (!document_ptr)
|
||||
return {};
|
||||
|
||||
const auto& document = *document_ptr;
|
||||
auto const& document = *document_ptr;
|
||||
Cpp::Position cpp_position { identifier_position.line(), identifier_position.column() };
|
||||
auto node = document.parser().node_at(cpp_position);
|
||||
if (!node) {
|
||||
|
@ -883,7 +883,7 @@ Optional<CppComprehensionEngine::FunctionParamsHint> CppComprehensionEngine::get
|
|||
FunctionCall& call_node,
|
||||
size_t argument_index)
|
||||
{
|
||||
const Identifier* callee = nullptr;
|
||||
Identifier const* callee = nullptr;
|
||||
VERIFY(call_node.callee());
|
||||
if (call_node.callee()->is_identifier()) {
|
||||
callee = verify_cast<Identifier>(call_node.callee());
|
||||
|
@ -929,15 +929,15 @@ Optional<CppComprehensionEngine::FunctionParamsHint> CppComprehensionEngine::get
|
|||
return hint;
|
||||
}
|
||||
|
||||
Vector<GUI::AutocompleteProvider::TokenInfo> CppComprehensionEngine::get_tokens_info(const String& filename)
|
||||
Vector<GUI::AutocompleteProvider::TokenInfo> CppComprehensionEngine::get_tokens_info(String const& filename)
|
||||
{
|
||||
dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "CppComprehensionEngine::get_tokens_info: {}", filename);
|
||||
|
||||
const auto* document_ptr = get_or_create_document_data(filename);
|
||||
auto const* document_ptr = get_or_create_document_data(filename);
|
||||
if (!document_ptr)
|
||||
return {};
|
||||
|
||||
const auto& document = *document_ptr;
|
||||
auto const& document = *document_ptr;
|
||||
|
||||
Vector<GUI::AutocompleteProvider::TokenInfo> tokens_info;
|
||||
size_t i = 0;
|
||||
|
|
|
@ -23,14 +23,14 @@ using namespace ::Cpp;
|
|||
|
||||
class CppComprehensionEngine : public CodeComprehensionEngine {
|
||||
public:
|
||||
CppComprehensionEngine(const FileDB& filedb);
|
||||
CppComprehensionEngine(FileDB const& filedb);
|
||||
|
||||
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position) override;
|
||||
virtual void on_edit(const String& file) override;
|
||||
virtual void file_opened([[maybe_unused]] const String& file) override;
|
||||
virtual Optional<GUI::AutocompleteProvider::ProjectLocation> find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position) override;
|
||||
virtual Optional<FunctionParamsHint> get_function_params_hint(const String&, const GUI::TextPosition&) override;
|
||||
virtual Vector<GUI::AutocompleteProvider::TokenInfo> get_tokens_info(const String& filename) override;
|
||||
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(String const& file, const GUI::TextPosition& autocomplete_position) override;
|
||||
virtual void on_edit(String const& file) override;
|
||||
virtual void file_opened([[maybe_unused]] String const& file) override;
|
||||
virtual Optional<GUI::AutocompleteProvider::ProjectLocation> find_declaration_of(String const& filename, const GUI::TextPosition& identifier_position) override;
|
||||
virtual Optional<FunctionParamsHint> get_function_params_hint(String const&, const GUI::TextPosition&) override;
|
||||
virtual Vector<GUI::AutocompleteProvider::TokenInfo> get_tokens_info(String const& filename) override;
|
||||
|
||||
private:
|
||||
struct SymbolName {
|
||||
|
@ -42,7 +42,7 @@ private:
|
|||
String scope_as_string() const;
|
||||
String to_string() const;
|
||||
|
||||
bool operator==(const SymbolName&) const = default;
|
||||
bool operator==(SymbolName const&) const = default;
|
||||
};
|
||||
|
||||
struct Symbol {
|
||||
|
@ -57,15 +57,15 @@ private:
|
|||
No,
|
||||
Yes
|
||||
};
|
||||
static Symbol create(StringView name, const Vector<StringView>& scope, NonnullRefPtr<Declaration>, IsLocal is_local);
|
||||
static Symbol create(StringView name, Vector<StringView> const& scope, NonnullRefPtr<Declaration>, IsLocal is_local);
|
||||
};
|
||||
|
||||
friend Traits<SymbolName>;
|
||||
|
||||
struct DocumentData {
|
||||
const String& filename() const { return m_filename; }
|
||||
const String& text() const { return m_text; }
|
||||
const Preprocessor& preprocessor() const
|
||||
String const& filename() const { return m_filename; }
|
||||
String const& text() const { return m_text; }
|
||||
Preprocessor const& preprocessor() const
|
||||
{
|
||||
VERIFY(m_preprocessor);
|
||||
return *m_preprocessor;
|
||||
|
@ -75,7 +75,7 @@ private:
|
|||
VERIFY(m_preprocessor);
|
||||
return *m_preprocessor;
|
||||
}
|
||||
const Parser& parser() const
|
||||
Parser const& parser() const
|
||||
{
|
||||
VERIFY(m_parser);
|
||||
return *m_parser;
|
||||
|
@ -95,52 +95,52 @@ private:
|
|||
HashTable<String> m_available_headers;
|
||||
};
|
||||
|
||||
Vector<GUI::AutocompleteProvider::Entry> autocomplete_property(const DocumentData&, const MemberExpression&, const String partial_text) const;
|
||||
Vector<GUI::AutocompleteProvider::Entry> autocomplete_name(const DocumentData&, const ASTNode&, const String& partial_text) const;
|
||||
String type_of(const DocumentData&, const Expression&) const;
|
||||
String type_of_property(const DocumentData&, const Identifier&) const;
|
||||
String type_of_variable(const Identifier&) const;
|
||||
bool is_property(const ASTNode&) const;
|
||||
RefPtr<Declaration> find_declaration_of(const DocumentData&, const ASTNode&) const;
|
||||
RefPtr<Declaration> find_declaration_of(const DocumentData&, const SymbolName&) const;
|
||||
RefPtr<Declaration> find_declaration_of(const DocumentData&, const GUI::TextPosition& identifier_position);
|
||||
Vector<GUI::AutocompleteProvider::Entry> autocomplete_property(DocumentData const&, MemberExpression const&, const String partial_text) const;
|
||||
Vector<GUI::AutocompleteProvider::Entry> autocomplete_name(DocumentData const&, ASTNode const&, String const& partial_text) const;
|
||||
String type_of(DocumentData const&, Expression const&) const;
|
||||
String type_of_property(DocumentData const&, Identifier const&) const;
|
||||
String type_of_variable(Identifier const&) const;
|
||||
bool is_property(ASTNode const&) const;
|
||||
RefPtr<Declaration> find_declaration_of(DocumentData const&, ASTNode const&) const;
|
||||
RefPtr<Declaration> find_declaration_of(DocumentData const&, SymbolName const&) const;
|
||||
RefPtr<Declaration> find_declaration_of(DocumentData const&, const GUI::TextPosition& identifier_position);
|
||||
|
||||
enum class RecurseIntoScopes {
|
||||
No,
|
||||
Yes
|
||||
};
|
||||
|
||||
Vector<Symbol> properties_of_type(const DocumentData& document, const String& type) const;
|
||||
Vector<Symbol> get_child_symbols(const ASTNode&) const;
|
||||
Vector<Symbol> get_child_symbols(const ASTNode&, const Vector<StringView>& scope, Symbol::IsLocal) const;
|
||||
Vector<Symbol> properties_of_type(DocumentData const& document, String const& type) const;
|
||||
Vector<Symbol> get_child_symbols(ASTNode const&) const;
|
||||
Vector<Symbol> get_child_symbols(ASTNode const&, Vector<StringView> const& scope, Symbol::IsLocal) const;
|
||||
|
||||
const DocumentData* get_document_data(const String& file) const;
|
||||
const DocumentData* get_or_create_document_data(const String& file);
|
||||
void set_document_data(const String& file, OwnPtr<DocumentData>&& data);
|
||||
DocumentData const* get_document_data(String const& file) const;
|
||||
DocumentData const* get_or_create_document_data(String const& file);
|
||||
void set_document_data(String const& file, OwnPtr<DocumentData>&& data);
|
||||
|
||||
OwnPtr<DocumentData> create_document_data_for(const String& file);
|
||||
OwnPtr<DocumentData> create_document_data_for(String const& file);
|
||||
String document_path_from_include_path(StringView include_path) const;
|
||||
void update_declared_symbols(DocumentData&);
|
||||
void update_todo_entries(DocumentData&);
|
||||
GUI::AutocompleteProvider::DeclarationType type_of_declaration(const Declaration&);
|
||||
Vector<StringView> scope_of_node(const ASTNode&) const;
|
||||
Vector<StringView> scope_of_reference_to_symbol(const ASTNode&) const;
|
||||
GUI::AutocompleteProvider::DeclarationType type_of_declaration(Declaration const&);
|
||||
Vector<StringView> scope_of_node(ASTNode const&) const;
|
||||
Vector<StringView> scope_of_reference_to_symbol(ASTNode const&) const;
|
||||
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> find_preprocessor_definition(const DocumentData&, const GUI::TextPosition&);
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> find_preprocessor_definition(DocumentData const&, const GUI::TextPosition&);
|
||||
Optional<Cpp::Preprocessor::Substitution> find_preprocessor_substitution(DocumentData const&, Cpp::Position const&);
|
||||
|
||||
OwnPtr<DocumentData> create_document_data(String&& text, const String& filename);
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> try_autocomplete_property(const DocumentData&, const ASTNode&, Optional<Token> containing_token) const;
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> try_autocomplete_name(const DocumentData&, const ASTNode&, Optional<Token> containing_token) const;
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> try_autocomplete_include(const DocumentData&, Token include_path_token, Cpp::Position const& cursor_position) const;
|
||||
static bool is_symbol_available(const Symbol&, const Vector<StringView>& current_scope, const Vector<StringView>& reference_scope);
|
||||
OwnPtr<DocumentData> create_document_data(String&& text, String const& filename);
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> try_autocomplete_property(DocumentData const&, ASTNode const&, Optional<Token> containing_token) const;
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> try_autocomplete_name(DocumentData const&, ASTNode const&, Optional<Token> containing_token) const;
|
||||
Optional<Vector<GUI::AutocompleteProvider::Entry>> try_autocomplete_include(DocumentData const&, Token include_path_token, Cpp::Position const& cursor_position) const;
|
||||
static bool is_symbol_available(Symbol const&, Vector<StringView> const& current_scope, Vector<StringView> const& reference_scope);
|
||||
Optional<FunctionParamsHint> get_function_params_hint(DocumentData const&, FunctionCall&, size_t argument_index);
|
||||
|
||||
template<typename Func>
|
||||
void for_each_available_symbol(const DocumentData&, Func) const;
|
||||
void for_each_available_symbol(DocumentData const&, Func) const;
|
||||
|
||||
template<typename Func>
|
||||
void for_each_included_document_recursive(const DocumentData&, Func) const;
|
||||
void for_each_included_document_recursive(DocumentData const&, Func) const;
|
||||
|
||||
GUI::AutocompleteProvider::TokenInfo::SemanticType get_token_semantic_type(DocumentData const&, Token const&);
|
||||
GUI::AutocompleteProvider::TokenInfo::SemanticType get_semantic_type_for_identifier(DocumentData const&, Position);
|
||||
|
@ -154,7 +154,7 @@ private:
|
|||
};
|
||||
|
||||
template<typename Func>
|
||||
void CppComprehensionEngine::for_each_available_symbol(const DocumentData& document, Func func) const
|
||||
void CppComprehensionEngine::for_each_available_symbol(DocumentData const& document, Func func) const
|
||||
{
|
||||
for (auto& item : document.m_symbols) {
|
||||
auto decision = func(item.value);
|
||||
|
@ -162,7 +162,7 @@ void CppComprehensionEngine::for_each_available_symbol(const DocumentData& docum
|
|||
return;
|
||||
}
|
||||
|
||||
for_each_included_document_recursive(document, [&](const DocumentData& document) {
|
||||
for_each_included_document_recursive(document, [&](DocumentData const& document) {
|
||||
for (auto& item : document.m_symbols) {
|
||||
auto decision = func(item.value);
|
||||
if (decision == IterationDecision::Break)
|
||||
|
@ -173,7 +173,7 @@ void CppComprehensionEngine::for_each_available_symbol(const DocumentData& docum
|
|||
}
|
||||
|
||||
template<typename Func>
|
||||
void CppComprehensionEngine::for_each_included_document_recursive(const DocumentData& document, Func func) const
|
||||
void CppComprehensionEngine::for_each_included_document_recursive(DocumentData const& document, Func func) const
|
||||
{
|
||||
for (auto& included_path : document.m_available_headers) {
|
||||
auto* included_document = get_document_data(included_path);
|
||||
|
@ -190,7 +190,7 @@ namespace AK {
|
|||
|
||||
template<>
|
||||
struct Traits<LanguageServers::Cpp::CppComprehensionEngine::SymbolName> : public GenericTraits<LanguageServers::Cpp::CppComprehensionEngine::SymbolName> {
|
||||
static unsigned hash(const LanguageServers::Cpp::CppComprehensionEngine::SymbolName& key)
|
||||
static unsigned hash(LanguageServers::Cpp::CppComprehensionEngine::SymbolName const& key)
|
||||
{
|
||||
unsigned hash = 0;
|
||||
hash = pair_int_hash(hash, string_hash(key.name.characters_without_null_termination(), key.name.length()));
|
||||
|
|
|
@ -55,7 +55,7 @@ int run_tests()
|
|||
return s_some_test_failed ? 1 : 0;
|
||||
}
|
||||
|
||||
static void add_file(FileDB& filedb, const String& name)
|
||||
static void add_file(FileDB& filedb, String const& name)
|
||||
{
|
||||
auto file = Core::File::open(LexicalPath::join(TESTS_ROOT_DIR, name).string(), Core::OpenMode::ReadOnly);
|
||||
VERIFY(!file.is_error());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue