mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibCodeComprehension: Re-organize code comprehension related code
This moves all code comprehension-related code to a new library, LibCodeComprehension. This also moves some types related to code comprehension tasks (such as autocomplete, find declaration) out of LibGUI and into LibCodeComprehension.
This commit is contained in:
parent
a2c34554cd
commit
b35293d945
65 changed files with 685 additions and 491 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibCodeComprehension/Types.h>
|
||||
#include <LibGUI/Forward.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/TableView.h>
|
||||
|
@ -22,98 +23,7 @@ class AutocompleteProvider {
|
|||
public:
|
||||
virtual ~AutocompleteProvider() = default;
|
||||
|
||||
enum class Language {
|
||||
Unspecified,
|
||||
Cpp,
|
||||
};
|
||||
|
||||
struct Entry {
|
||||
String completion;
|
||||
size_t partial_input_length { 0 };
|
||||
Language language { Language::Unspecified };
|
||||
String display_text {};
|
||||
|
||||
enum class HideAutocompleteAfterApplying {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
HideAutocompleteAfterApplying hide_autocomplete_after_applying { HideAutocompleteAfterApplying::Yes };
|
||||
};
|
||||
|
||||
struct ProjectLocation {
|
||||
String file;
|
||||
size_t line { 0 };
|
||||
size_t column { 0 };
|
||||
|
||||
bool operator==(ProjectLocation const&) const;
|
||||
};
|
||||
|
||||
enum class DeclarationType {
|
||||
Function,
|
||||
Struct,
|
||||
Class,
|
||||
Variable,
|
||||
PreprocessorDefinition,
|
||||
Namespace,
|
||||
Member,
|
||||
};
|
||||
|
||||
struct Declaration {
|
||||
String name;
|
||||
ProjectLocation position;
|
||||
DeclarationType type;
|
||||
String scope;
|
||||
|
||||
bool operator==(Declaration const&) const;
|
||||
};
|
||||
|
||||
virtual void provide_completions(Function<void(Vector<Entry>)>) = 0;
|
||||
|
||||
#define FOR_EACH_SEMANTIC_TYPE \
|
||||
__SEMANTIC(Unknown) \
|
||||
__SEMANTIC(Regular) \
|
||||
__SEMANTIC(Keyword) \
|
||||
__SEMANTIC(Type) \
|
||||
__SEMANTIC(Identifier) \
|
||||
__SEMANTIC(String) \
|
||||
__SEMANTIC(Number) \
|
||||
__SEMANTIC(IncludePath) \
|
||||
__SEMANTIC(PreprocessorStatement) \
|
||||
__SEMANTIC(Comment) \
|
||||
__SEMANTIC(Whitespace) \
|
||||
__SEMANTIC(Function) \
|
||||
__SEMANTIC(Variable) \
|
||||
__SEMANTIC(CustomType) \
|
||||
__SEMANTIC(Namespace) \
|
||||
__SEMANTIC(Member) \
|
||||
__SEMANTIC(Parameter) \
|
||||
__SEMANTIC(PreprocessorMacro)
|
||||
|
||||
struct TokenInfo {
|
||||
|
||||
enum class SemanticType : u32 {
|
||||
#define __SEMANTIC(x) x,
|
||||
FOR_EACH_SEMANTIC_TYPE
|
||||
#undef __SEMANTIC
|
||||
|
||||
} type { SemanticType::Unknown };
|
||||
size_t start_line { 0 };
|
||||
size_t start_column { 0 };
|
||||
size_t end_line { 0 };
|
||||
size_t end_column { 0 };
|
||||
|
||||
static constexpr char const* type_to_string(SemanticType t)
|
||||
{
|
||||
switch (t) {
|
||||
#define __SEMANTIC(x) \
|
||||
case SemanticType::x: \
|
||||
return #x;
|
||||
FOR_EACH_SEMANTIC_TYPE
|
||||
#undef __SEMANTIC
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
};
|
||||
};
|
||||
virtual void provide_completions(Function<void(Vector<CodeComprehension::AutocompleteResultEntry>)>) = 0;
|
||||
|
||||
void attach(TextEditor& editor)
|
||||
{
|
||||
|
@ -133,7 +43,7 @@ public:
|
|||
explicit AutocompleteBox(TextEditor&);
|
||||
~AutocompleteBox() = default;
|
||||
|
||||
void update_suggestions(Vector<AutocompleteProvider::Entry>&& suggestions);
|
||||
void update_suggestions(Vector<CodeComprehension::AutocompleteResultEntry>&& suggestions);
|
||||
bool is_visible() const;
|
||||
void show(Gfx::IntPoint suggestion_box_location);
|
||||
void close();
|
||||
|
@ -141,7 +51,7 @@ public:
|
|||
bool has_suggestions() { return m_suggestion_view->model()->row_count() > 0; }
|
||||
void next_suggestion();
|
||||
void previous_suggestion();
|
||||
AutocompleteProvider::Entry::HideAutocompleteAfterApplying apply_suggestion();
|
||||
CodeComprehension::AutocompleteResultEntry::HideAutocompleteAfterApplying apply_suggestion();
|
||||
|
||||
private:
|
||||
WeakPtr<TextEditor> m_editor;
|
||||
|
@ -149,5 +59,4 @@ private:
|
|||
RefPtr<GUI::TableView> m_suggestion_view;
|
||||
RefPtr<GUI::Label> m_no_suggestions_view;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue