summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCodeComprehension/CodeComprehensionEngine.h
blob: 04d7909a421f9b6c746bd07cfde11d08ef3d0708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
 * Copyright (c) 2022, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include "FileDB.h"
#include "Types.h"
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/Vector.h>
#include <LibGUI/TextPosition.h>

namespace CodeComprehension {

class CodeComprehensionEngine {
    AK_MAKE_NONCOPYABLE(CodeComprehensionEngine);
    AK_MAKE_NONMOVABLE(CodeComprehensionEngine);

public:
    CodeComprehensionEngine(FileDB const& filedb, bool store_all_declarations = false);
    virtual ~CodeComprehensionEngine() = default;

    virtual Vector<AutocompleteResultEntry> get_suggestions(String const& file, GUI::TextPosition const& 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]] String const& file) {};
    virtual void file_opened([[maybe_unused]] String const& file) {};

    virtual Optional<ProjectLocation> find_declaration_of(String const&, GUI::TextPosition const&) { return {}; }

    struct FunctionParamsHint {
        Vector<String> params;
        size_t current_index { 0 };
    };
    virtual Optional<FunctionParamsHint> get_function_params_hint(String const&, GUI::TextPosition const&) { return {}; }

    virtual Vector<TokenInfo> get_tokens_info(String const&) { return {}; }

    Function<void(String const&, Vector<Declaration>&&)> set_declarations_of_document_callback;
    Function<void(String const&, Vector<TodoEntry>&&)> set_todo_entries_of_document_callback;

protected:
    FileDB const& filedb() const { return m_filedb; }
    void set_declarations_of_document(String const&, Vector<Declaration>&&);
    void set_todo_entries_of_document(String const&, Vector<TodoEntry>&&);
    HashMap<String, Vector<Declaration>> const& all_declarations() const { return m_all_declarations; }

private:
    HashMap<String, Vector<Declaration>> m_all_declarations;
    FileDB const& m_filedb;
    bool m_store_all_declarations { false };
};
}