2020-10-03 17:25:51 +03:30
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-10-03 17:25:51 +03:30
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-05-14 17:09:24 +03:00
|
|
|
#include <LibCodeComprehension/CodeComprehensionEngine.h>
|
2020-10-03 17:25:51 +03:30
|
|
|
#include <Shell/Shell.h>
|
|
|
|
|
|
2022-05-14 17:09:24 +03:00
|
|
|
namespace CodeComprehension::Shell {
|
2020-10-03 17:25:51 +03:30
|
|
|
|
2021-05-16 17:25:24 +03:00
|
|
|
class ShellComprehensionEngine : public CodeComprehensionEngine {
|
2020-10-03 17:25:51 +03:30
|
|
|
public:
|
2022-04-01 20:58:27 +03:00
|
|
|
ShellComprehensionEngine(FileDB const& filedb);
|
2022-12-04 18:02:33 +00:00
|
|
|
virtual Vector<CodeComprehension::AutocompleteResultEntry> get_suggestions(DeprecatedString const& file, const GUI::TextPosition& position) override;
|
|
|
|
|
virtual void on_edit(DeprecatedString const& file) override;
|
|
|
|
|
virtual void file_opened([[maybe_unused]] DeprecatedString const& file) override;
|
|
|
|
|
virtual Optional<CodeComprehension::ProjectLocation> find_declaration_of(DeprecatedString const& filename, const GUI::TextPosition& identifier_position) override;
|
2021-03-02 09:40:10 +03:30
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct DocumentData {
|
2022-12-04 18:02:33 +00:00
|
|
|
DocumentData(DeprecatedString&& text, DeprecatedString filename);
|
|
|
|
|
DeprecatedString filename;
|
|
|
|
|
DeprecatedString text;
|
2021-03-02 09:40:10 +03:30
|
|
|
NonnullRefPtr<::Shell::AST::Node> node;
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
Vector<DeprecatedString> const& sourced_paths() const;
|
2021-03-02 09:40:10 +03:30
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<::Shell::AST::Node> parse() const;
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
mutable Optional<Vector<DeprecatedString>> all_sourced_paths {};
|
2021-03-02 09:40:10 +03:30
|
|
|
};
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DocumentData const& get_document_data(DeprecatedString const& file) const;
|
|
|
|
|
DocumentData const& get_or_create_document_data(DeprecatedString const& file);
|
|
|
|
|
void set_document_data(DeprecatedString const& file, OwnPtr<DocumentData>&& data);
|
2021-03-02 09:40:10 +03:30
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
OwnPtr<DocumentData> create_document_data_for(DeprecatedString const& file);
|
2022-04-01 20:58:27 +03:00
|
|
|
void update_declared_symbols(DocumentData const&);
|
2021-03-02 09:40:10 +03:30
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
static size_t resolve(ShellComprehensionEngine::DocumentData const& document, const GUI::TextPosition& position);
|
2021-03-02 09:40:10 +03:30
|
|
|
|
|
|
|
|
::Shell::Shell& shell()
|
2020-10-03 17:25:51 +03:30
|
|
|
{
|
2021-03-02 09:40:10 +03:30
|
|
|
if (s_shell)
|
|
|
|
|
return *s_shell;
|
|
|
|
|
s_shell = ::Shell::Shell::construct();
|
|
|
|
|
return *s_shell;
|
2020-10-03 17:25:51 +03:30
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
HashMap<DeprecatedString, OwnPtr<DocumentData>> m_documents;
|
2021-03-02 09:40:10 +03:30
|
|
|
static RefPtr<::Shell::Shell> s_shell;
|
2020-10-03 17:25:51 +03:30
|
|
|
};
|
|
|
|
|
}
|