1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

Everywhere: Run clang-format

This commit is contained in:
Idan Horowitz 2022-04-01 20:58:27 +03:00 committed by Linus Groh
parent 0376c127f6
commit 086969277e
1665 changed files with 8479 additions and 8479 deletions

View file

@ -9,13 +9,13 @@
namespace LanguageServers {
CodeComprehensionEngine::CodeComprehensionEngine(const FileDB& filedb, bool should_store_all_declarations)
CodeComprehensionEngine::CodeComprehensionEngine(FileDB const& filedb, bool should_store_all_declarations)
: m_filedb(filedb)
, m_store_all_declarations(should_store_all_declarations)
{
}
void CodeComprehensionEngine::set_declarations_of_document(const String& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations)
void CodeComprehensionEngine::set_declarations_of_document(String const& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations)
{
// Callback may not be configured if we're running tests
if (!set_declarations_of_document_callback)

View file

@ -18,38 +18,38 @@ class ConnectionFromClient;
class CodeComprehensionEngine {
public:
CodeComprehensionEngine(const FileDB& filedb, bool store_all_declarations = false);
CodeComprehensionEngine(FileDB const& filedb, bool store_all_declarations = false);
virtual ~CodeComprehensionEngine() = default;
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position) = 0;
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(String const& file, const GUI::TextPosition& autocomplete_position) = 0;
// TODO: In the future we can pass the range that was edited and only re-parse what we have to.
virtual void on_edit([[maybe_unused]] const String& file) {};
virtual void file_opened([[maybe_unused]] const String& file) {};
virtual void on_edit([[maybe_unused]] String const& file) {};
virtual void file_opened([[maybe_unused]] String const& file) {};
virtual Optional<GUI::AutocompleteProvider::ProjectLocation> find_declaration_of(const String&, const GUI::TextPosition&) { return {}; }
virtual Optional<GUI::AutocompleteProvider::ProjectLocation> find_declaration_of(String const&, const GUI::TextPosition&) { return {}; }
struct FunctionParamsHint {
Vector<String> params;
size_t current_index { 0 };
};
virtual Optional<FunctionParamsHint> get_function_params_hint(const String&, const GUI::TextPosition&) { return {}; }
virtual Optional<FunctionParamsHint> get_function_params_hint(String const&, const GUI::TextPosition&) { return {}; }
virtual Vector<GUI::AutocompleteProvider::TokenInfo> get_tokens_info(const String&) { return {}; }
virtual Vector<GUI::AutocompleteProvider::TokenInfo> get_tokens_info(String const&) { return {}; }
public:
Function<void(const String&, Vector<GUI::AutocompleteProvider::Declaration>&&)> set_declarations_of_document_callback;
Function<void(String const&, Vector<GUI::AutocompleteProvider::Declaration>&&)> set_declarations_of_document_callback;
Function<void(String const&, Vector<Cpp::Parser::TodoEntry>&&)> set_todo_entries_of_document_callback;
protected:
const FileDB& filedb() const { return m_filedb; }
void set_declarations_of_document(const String&, Vector<GUI::AutocompleteProvider::Declaration>&&);
FileDB const& filedb() const { return m_filedb; }
void set_declarations_of_document(String const&, Vector<GUI::AutocompleteProvider::Declaration>&&);
void set_todo_entries_of_document(String const&, Vector<Cpp::Parser::TodoEntry>&&);
const HashMap<String, Vector<GUI::AutocompleteProvider::Declaration>>& all_declarations() const { return m_all_declarations; }
HashMap<String, Vector<GUI::AutocompleteProvider::Declaration>> const& all_declarations() const { return m_all_declarations; }
private:
HashMap<String, Vector<GUI::AutocompleteProvider::Declaration>> m_all_declarations;
const FileDB& m_filedb;
FileDB const& m_filedb;
bool m_store_all_declarations { false };
};
}

View file

@ -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) {

View file

@ -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;

View file

@ -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()));

View file

@ -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());

View file

@ -12,7 +12,7 @@
namespace LanguageServers {
RefPtr<const GUI::TextDocument> FileDB::get(const String& filename) const
RefPtr<const GUI::TextDocument> FileDB::get(String const& filename) const
{
auto absolute_path = to_absolute_path(filename);
auto document_optional = m_open_files.get(absolute_path);
@ -22,15 +22,15 @@ RefPtr<const GUI::TextDocument> FileDB::get(const String& filename) const
return *document_optional.value();
}
RefPtr<GUI::TextDocument> FileDB::get(const String& filename)
RefPtr<GUI::TextDocument> FileDB::get(String const& filename)
{
auto document = reinterpret_cast<const FileDB*>(this)->get(filename);
auto document = reinterpret_cast<FileDB const*>(this)->get(filename);
if (document.is_null())
return nullptr;
return adopt_ref(*const_cast<GUI::TextDocument*>(document.leak_ref()));
}
RefPtr<const GUI::TextDocument> FileDB::get_or_create_from_filesystem(const String& filename) const
RefPtr<const GUI::TextDocument> FileDB::get_or_create_from_filesystem(String const& filename) const
{
auto absolute_path = to_absolute_path(filename);
auto document = get(absolute_path);
@ -39,20 +39,20 @@ RefPtr<const GUI::TextDocument> FileDB::get_or_create_from_filesystem(const Stri
return create_from_filesystem(absolute_path);
}
RefPtr<GUI::TextDocument> FileDB::get_or_create_from_filesystem(const String& filename)
RefPtr<GUI::TextDocument> FileDB::get_or_create_from_filesystem(String const& filename)
{
auto document = reinterpret_cast<const FileDB*>(this)->get_or_create_from_filesystem(filename);
auto document = reinterpret_cast<FileDB const*>(this)->get_or_create_from_filesystem(filename);
if (document.is_null())
return nullptr;
return adopt_ref(*const_cast<GUI::TextDocument*>(document.leak_ref()));
}
bool FileDB::is_open(const String& filename) const
bool FileDB::is_open(String const& filename) const
{
return m_open_files.contains(to_absolute_path(filename));
}
bool FileDB::add(const String& filename, int fd)
bool FileDB::add(String const& filename, int fd)
{
auto document = create_from_fd(fd);
if (!document)
@ -62,7 +62,7 @@ bool FileDB::add(const String& filename, int fd)
return true;
}
String FileDB::to_absolute_path(const String& filename) const
String FileDB::to_absolute_path(String const& filename) const
{
if (LexicalPath { filename }.is_absolute()) {
return filename;
@ -72,7 +72,7 @@ String FileDB::to_absolute_path(const String& filename) const
return LexicalPath { String::formatted("{}/{}", m_project_root, filename) }.string();
}
RefPtr<GUI::TextDocument> FileDB::create_from_filesystem(const String& filename) const
RefPtr<GUI::TextDocument> FileDB::create_from_filesystem(String const& filename) const
{
auto file = Core::File::open(to_absolute_path(filename), Core::OpenMode::ReadOnly);
if (file.is_error()) {
@ -120,7 +120,7 @@ RefPtr<GUI::TextDocument> FileDB::create_from_file(Core::File& file) const
return document;
}
void FileDB::on_file_edit_insert_text(const String& filename, const String& inserted_text, size_t start_line, size_t start_column)
void FileDB::on_file_edit_insert_text(String const& filename, String const& inserted_text, size_t start_line, size_t start_column)
{
VERIFY(is_open(filename));
auto document = get(filename);
@ -131,7 +131,7 @@ void FileDB::on_file_edit_insert_text(const String& filename, const String& inse
dbgln_if(FILE_CONTENT_DEBUG, "{}", document->text());
}
void FileDB::on_file_edit_remove_text(const String& filename, size_t start_line, size_t start_column, size_t end_line, size_t end_column)
void FileDB::on_file_edit_remove_text(String const& filename, size_t start_line, size_t start_column, size_t end_line, size_t end_column)
{
// TODO: If file is not open - need to get its contents
// Otherwise- somehow verify that respawned language server is synced with all file contents
@ -148,7 +148,7 @@ void FileDB::on_file_edit_remove_text(const String& filename, size_t start_line,
dbgln_if(FILE_CONTENT_DEBUG, "{}", document->text());
}
RefPtr<GUI::TextDocument> FileDB::create_with_content(const String& content)
RefPtr<GUI::TextDocument> FileDB::create_with_content(String const& content)
{
StringView content_view(content);
auto document = GUI::TextDocument::create(&s_default_document_client);
@ -156,7 +156,7 @@ RefPtr<GUI::TextDocument> FileDB::create_with_content(const String& content)
return document;
}
bool FileDB::add(const String& filename, const String& content)
bool FileDB::add(String const& filename, String const& content)
{
auto document = create_with_content(content);
if (!document) {

View file

@ -15,26 +15,26 @@ namespace LanguageServers {
class FileDB final {
public:
RefPtr<const GUI::TextDocument> get(const String& filename) const;
RefPtr<GUI::TextDocument> get(const String& filename);
RefPtr<const GUI::TextDocument> get_or_create_from_filesystem(const String& filename) const;
RefPtr<GUI::TextDocument> get_or_create_from_filesystem(const String& filename);
bool add(const String& filename, int fd);
bool add(const String& filename, const String& content);
RefPtr<const GUI::TextDocument> get(String const& filename) const;
RefPtr<GUI::TextDocument> get(String const& filename);
RefPtr<const GUI::TextDocument> get_or_create_from_filesystem(String const& filename) const;
RefPtr<GUI::TextDocument> get_or_create_from_filesystem(String const& filename);
bool add(String const& filename, int fd);
bool add(String const& filename, String const& content);
void set_project_root(const String& root_path) { m_project_root = root_path; }
const String& project_root() const { return m_project_root; }
void set_project_root(String const& root_path) { m_project_root = root_path; }
String const& project_root() const { return m_project_root; }
void on_file_edit_insert_text(const String& filename, const String& inserted_text, size_t start_line, size_t start_column);
void on_file_edit_remove_text(const String& filename, size_t start_line, size_t start_column, size_t end_line, size_t end_column);
String to_absolute_path(const String& filename) const;
bool is_open(const String& filename) const;
void on_file_edit_insert_text(String const& filename, String const& inserted_text, size_t start_line, size_t start_column);
void on_file_edit_remove_text(String const& filename, size_t start_line, size_t start_column, size_t end_line, size_t end_column);
String to_absolute_path(String const& filename) const;
bool is_open(String const& filename) const;
private:
RefPtr<GUI::TextDocument> create_from_filesystem(const String& filename) const;
RefPtr<GUI::TextDocument> create_from_filesystem(String const& filename) const;
RefPtr<GUI::TextDocument> create_from_fd(int fd) const;
RefPtr<GUI::TextDocument> create_from_file(Core::File&) const;
static RefPtr<GUI::TextDocument> create_with_content(const String&);
static RefPtr<GUI::TextDocument> create_with_content(String const&);
private:
HashMap<String, NonnullRefPtr<GUI::TextDocument>> m_open_files;

View file

@ -20,7 +20,7 @@ private:
: LanguageServers::ConnectionFromClient(move(socket))
{
m_autocomplete_engine = make<ShellComprehensionEngine>(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) {

View file

@ -14,12 +14,12 @@ namespace LanguageServers::Shell {
RefPtr<::Shell::Shell> ShellComprehensionEngine::s_shell {};
ShellComprehensionEngine::ShellComprehensionEngine(const FileDB& filedb)
ShellComprehensionEngine::ShellComprehensionEngine(FileDB const& filedb)
: CodeComprehensionEngine(filedb, true)
{
}
const ShellComprehensionEngine::DocumentData& ShellComprehensionEngine::get_or_create_document_data(const String& file)
ShellComprehensionEngine::DocumentData const& ShellComprehensionEngine::get_or_create_document_data(String const& file)
{
auto absolute_path = filedb().to_absolute_path(file);
if (!m_documents.contains(absolute_path)) {
@ -28,7 +28,7 @@ const ShellComprehensionEngine::DocumentData& ShellComprehensionEngine::get_or_c
return get_document_data(absolute_path);
}
const ShellComprehensionEngine::DocumentData& ShellComprehensionEngine::get_document_data(const String& file) const
ShellComprehensionEngine::DocumentData const& ShellComprehensionEngine::get_document_data(String const& file) const
{
auto absolute_path = filedb().to_absolute_path(file);
auto document_data = m_documents.get(absolute_path);
@ -36,7 +36,7 @@ const ShellComprehensionEngine::DocumentData& ShellComprehensionEngine::get_docu
return *document_data.value();
}
OwnPtr<ShellComprehensionEngine::DocumentData> ShellComprehensionEngine::create_document_data_for(const String& file)
OwnPtr<ShellComprehensionEngine::DocumentData> ShellComprehensionEngine::create_document_data_for(String const& file)
{
auto document = filedb().get(file);
if (!document)
@ -50,7 +50,7 @@ OwnPtr<ShellComprehensionEngine::DocumentData> ShellComprehensionEngine::create_
return document_data;
}
void ShellComprehensionEngine::set_document_data(const String& file, OwnPtr<DocumentData>&& data)
void ShellComprehensionEngine::set_document_data(String const& file, OwnPtr<DocumentData>&& data)
{
m_documents.set(filedb().to_absolute_path(file), move(data));
}
@ -62,7 +62,7 @@ ShellComprehensionEngine::DocumentData::DocumentData(String&& _text, String _fil
{
}
const Vector<String>& ShellComprehensionEngine::DocumentData::sourced_paths() const
Vector<String> const& ShellComprehensionEngine::DocumentData::sourced_paths() const
{
if (all_sourced_paths.has_value())
return all_sourced_paths.value();
@ -110,7 +110,7 @@ NonnullRefPtr<::Shell::AST::Node> ShellComprehensionEngine::DocumentData::parse(
return ::Shell::AST::make_ref_counted<::Shell::AST::SyntaxError>(::Shell::AST::Position {}, "Unable to parse file");
}
size_t ShellComprehensionEngine::resolve(const ShellComprehensionEngine::DocumentData& document, const GUI::TextPosition& position)
size_t ShellComprehensionEngine::resolve(ShellComprehensionEngine::DocumentData const& document, const GUI::TextPosition& position)
{
size_t offset = 0;
@ -133,11 +133,11 @@ size_t ShellComprehensionEngine::resolve(const ShellComprehensionEngine::Documen
return offset;
}
Vector<GUI::AutocompleteProvider::Entry> ShellComprehensionEngine::get_suggestions(const String& file, const GUI::TextPosition& position)
Vector<GUI::AutocompleteProvider::Entry> ShellComprehensionEngine::get_suggestions(String const& file, const GUI::TextPosition& position)
{
dbgln_if(SH_LANGUAGE_SERVER_DEBUG, "ShellComprehensionEngine position {}:{}", position.line(), position.column());
const auto& document = get_or_create_document_data(file);
auto const& document = get_or_create_document_data(file);
size_t offset_in_file = resolve(document, position);
::Shell::AST::HitTestResult hit_test = document.node->hit_test_position(offset_in_file);
@ -154,20 +154,20 @@ Vector<GUI::AutocompleteProvider::Entry> ShellComprehensionEngine::get_suggestio
return entries;
}
void ShellComprehensionEngine::on_edit(const String& file)
void ShellComprehensionEngine::on_edit(String const& file)
{
set_document_data(file, create_document_data_for(file));
}
void ShellComprehensionEngine::file_opened([[maybe_unused]] const String& file)
void ShellComprehensionEngine::file_opened([[maybe_unused]] String const& file)
{
set_document_data(file, create_document_data_for(file));
}
Optional<GUI::AutocompleteProvider::ProjectLocation> ShellComprehensionEngine::find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position)
Optional<GUI::AutocompleteProvider::ProjectLocation> ShellComprehensionEngine::find_declaration_of(String const& filename, const GUI::TextPosition& identifier_position)
{
dbgln_if(SH_LANGUAGE_SERVER_DEBUG, "find_declaration_of({}, {}:{})", filename, identifier_position.line(), identifier_position.column());
const auto& document = get_or_create_document_data(filename);
auto const& document = get_or_create_document_data(filename);
auto position = resolve(document, identifier_position);
auto result = document.node->hit_test_position(position);
if (!result.matching_node) {
@ -192,10 +192,10 @@ Optional<GUI::AutocompleteProvider::ProjectLocation> ShellComprehensionEngine::f
return {};
}
void ShellComprehensionEngine::update_declared_symbols(const DocumentData& document)
void ShellComprehensionEngine::update_declared_symbols(DocumentData const& document)
{
struct Visitor : public ::Shell::AST::NodeVisitor {
explicit Visitor(const String& filename)
explicit Visitor(String const& filename)
: filename(filename)
{
}
@ -225,7 +225,7 @@ void ShellComprehensionEngine::update_declared_symbols(const DocumentData& docum
declarations.append({ node->name().name, { filename, node->position().start_line.line_number, node->position().start_line.line_column }, GUI::AutocompleteProvider::DeclarationType::Function, {} });
}
const String& filename;
String const& filename;
Vector<GUI::AutocompleteProvider::Declaration> declarations;
} visitor { document.filename };

View file

@ -13,11 +13,11 @@ namespace LanguageServers::Shell {
class ShellComprehensionEngine : public CodeComprehensionEngine {
public:
ShellComprehensionEngine(const FileDB& filedb);
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& 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;
ShellComprehensionEngine(FileDB const& filedb);
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(String const& file, const GUI::TextPosition& 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;
private:
struct DocumentData {
@ -26,7 +26,7 @@ private:
String text;
NonnullRefPtr<::Shell::AST::Node> node;
const Vector<String>& sourced_paths() const;
Vector<String> const& sourced_paths() const;
private:
NonnullRefPtr<::Shell::AST::Node> parse() const;
@ -34,15 +34,15 @@ private:
mutable Optional<Vector<String>> all_sourced_paths {};
};
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(const DocumentData&);
void update_declared_symbols(DocumentData const&);
static size_t resolve(const ShellComprehensionEngine::DocumentData& document, const GUI::TextPosition& position);
static size_t resolve(ShellComprehensionEngine::DocumentData const& document, const GUI::TextPosition& position);
::Shell::Shell& shell()
{