2020-09-20 20:56:02 +03:00
|
|
|
/*
|
2020-12-30 13:55:06 +03:30
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-09-20 20:56:02 +03:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-20 20:56:02 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2020-12-30 13:55:06 +03:30
|
|
|
#include <LibGUI/Forward.h>
|
2021-10-27 23:13:49 -05:00
|
|
|
#include <LibGUI/Label.h>
|
2021-10-28 00:46:05 -05:00
|
|
|
#include <LibGUI/TableView.h>
|
2020-12-30 13:55:06 +03:30
|
|
|
#include <LibGUI/TextEditor.h>
|
|
|
|
|
#include <LibGUI/Window.h>
|
2021-02-27 09:31:05 +02:00
|
|
|
#include <LibIPC/Decoder.h>
|
2020-09-20 20:56:02 +03:00
|
|
|
|
2020-12-30 13:55:06 +03:30
|
|
|
namespace GUI {
|
2020-09-20 20:56:02 +03:00
|
|
|
|
2020-12-30 13:55:06 +03:30
|
|
|
class AutocompleteProvider {
|
|
|
|
|
AK_MAKE_NONCOPYABLE(AutocompleteProvider);
|
|
|
|
|
AK_MAKE_NONMOVABLE(AutocompleteProvider);
|
2020-10-03 16:30:16 +03:30
|
|
|
|
2020-09-20 20:56:02 +03:00
|
|
|
public:
|
2020-12-30 13:55:06 +03:30
|
|
|
virtual ~AutocompleteProvider() { }
|
2020-09-20 20:56:02 +03:00
|
|
|
|
2020-12-30 13:55:06 +03:30
|
|
|
enum class Language {
|
|
|
|
|
Unspecified,
|
|
|
|
|
Cpp,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Entry {
|
|
|
|
|
String completion;
|
|
|
|
|
size_t partial_input_length { 0 };
|
|
|
|
|
Language language { Language::Unspecified };
|
2021-10-26 00:45:07 -05:00
|
|
|
String display_text {};
|
2021-10-28 20:31:54 -05:00
|
|
|
|
|
|
|
|
enum class HideAutocompleteAfterApplying {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
HideAutocompleteAfterApplying hide_autocomplete_after_applying { HideAutocompleteAfterApplying::Yes };
|
2020-12-30 13:55:06 +03:30
|
|
|
};
|
|
|
|
|
|
2021-02-27 09:31:05 +02:00
|
|
|
struct ProjectLocation {
|
|
|
|
|
String file;
|
|
|
|
|
size_t line { 0 };
|
|
|
|
|
size_t column { 0 };
|
2021-04-10 17:38:11 +03:00
|
|
|
|
|
|
|
|
bool operator==(const ProjectLocation&) const;
|
2021-02-27 09:31:05 +02:00
|
|
|
};
|
|
|
|
|
|
2021-02-27 09:40:34 +02:00
|
|
|
enum class DeclarationType {
|
|
|
|
|
Function,
|
|
|
|
|
Struct,
|
|
|
|
|
Class,
|
2021-03-13 09:50:33 +02:00
|
|
|
Variable,
|
|
|
|
|
PreprocessorDefinition,
|
2021-04-10 17:34:57 +03:00
|
|
|
Namespace,
|
|
|
|
|
Member,
|
2021-02-27 09:40:34 +02:00
|
|
|
};
|
|
|
|
|
|
2021-02-27 09:31:05 +02:00
|
|
|
struct Declaration {
|
|
|
|
|
String name;
|
|
|
|
|
ProjectLocation position;
|
2021-02-27 09:40:34 +02:00
|
|
|
DeclarationType type;
|
2021-03-23 12:32:45 +02:00
|
|
|
String scope;
|
2021-04-10 17:38:11 +03:00
|
|
|
|
|
|
|
|
bool operator==(const Declaration&) const;
|
2021-02-27 09:31:05 +02:00
|
|
|
};
|
|
|
|
|
|
2020-12-30 13:55:06 +03:30
|
|
|
virtual void provide_completions(Function<void(Vector<Entry>)>) = 0;
|
|
|
|
|
|
2022-02-05 20:31:33 +02:00
|
|
|
struct TokenInfo {
|
|
|
|
|
enum class SemanticType : u32 {
|
|
|
|
|
Unknown,
|
|
|
|
|
Regular,
|
|
|
|
|
Keyword,
|
|
|
|
|
Type,
|
|
|
|
|
Identifier,
|
|
|
|
|
String,
|
|
|
|
|
Number,
|
|
|
|
|
IncludePath,
|
|
|
|
|
PreprocessorStatement,
|
|
|
|
|
Comment,
|
|
|
|
|
Whitespace,
|
|
|
|
|
Function,
|
|
|
|
|
Variable,
|
|
|
|
|
CustomType,
|
|
|
|
|
Namespace,
|
|
|
|
|
Member,
|
|
|
|
|
Parameter,
|
|
|
|
|
} type { SemanticType::Unknown };
|
|
|
|
|
size_t start_line { 0 };
|
|
|
|
|
size_t start_column { 0 };
|
|
|
|
|
size_t end_line { 0 };
|
|
|
|
|
size_t end_column { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-30 13:55:06 +03:30
|
|
|
void attach(TextEditor& editor)
|
|
|
|
|
{
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(!m_editor);
|
2020-12-30 13:55:06 +03:30
|
|
|
m_editor = editor;
|
|
|
|
|
}
|
|
|
|
|
void detach() { m_editor.clear(); }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
AutocompleteProvider() { }
|
|
|
|
|
|
|
|
|
|
WeakPtr<TextEditor> m_editor;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class AutocompleteBox final {
|
|
|
|
|
public:
|
|
|
|
|
explicit AutocompleteBox(TextEditor&);
|
|
|
|
|
~AutocompleteBox();
|
|
|
|
|
|
|
|
|
|
void update_suggestions(Vector<AutocompleteProvider::Entry>&& suggestions);
|
|
|
|
|
bool is_visible() const;
|
2021-03-27 18:27:08 +03:00
|
|
|
void show(Gfx::IntPoint suggestion_box_location);
|
2020-09-20 20:56:02 +03:00
|
|
|
void close();
|
|
|
|
|
|
2021-10-28 00:46:45 -05:00
|
|
|
bool has_suggestions() { return m_suggestion_view->model()->row_count() > 0; }
|
2020-09-20 20:56:02 +03:00
|
|
|
void next_suggestion();
|
|
|
|
|
void previous_suggestion();
|
2021-10-28 20:31:54 -05:00
|
|
|
AutocompleteProvider::Entry::HideAutocompleteAfterApplying apply_suggestion();
|
2020-09-20 20:56:02 +03:00
|
|
|
|
|
|
|
|
private:
|
2020-12-30 13:55:06 +03:30
|
|
|
WeakPtr<TextEditor> m_editor;
|
2020-09-20 20:56:02 +03:00
|
|
|
RefPtr<GUI::Window> m_popup_window;
|
|
|
|
|
RefPtr<GUI::TableView> m_suggestion_view;
|
2021-10-27 23:13:49 -05:00
|
|
|
RefPtr<GUI::Label> m_no_suggestions_view;
|
2020-09-20 20:56:02 +03:00
|
|
|
};
|
2020-12-30 13:55:06 +03:30
|
|
|
|
2020-09-20 20:56:02 +03:00
|
|
|
}
|