mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
LibGUI+HackStudio: Add TokenInfo struct for language-server IPC
The TokenInfo struct contains the token's position and a "semantic type". The semantic type is a more fine-grained token type than what's in Cpp::Token::Type. For example, the semantic token type differentiates between a reference to a variable and to a function parameter. In the normal Token::Type, both would be Token::Type::Identifier.
This commit is contained in:
parent
605becb28b
commit
a54d0cc805
2 changed files with 53 additions and 0 deletions
|
@ -96,4 +96,31 @@ inline ErrorOr<void> decode(Decoder& decoder, Cpp::Parser::TodoEntry& entry)
|
|||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool encode(Encoder& encoder, const GUI::AutocompleteProvider::TokenInfo& location)
|
||||
{
|
||||
encoder << (u32)location.type;
|
||||
static_assert(sizeof(location.type) == sizeof(u32));
|
||||
encoder << location.start_line;
|
||||
encoder << location.start_column;
|
||||
encoder << location.end_line;
|
||||
encoder << location.end_column;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline ErrorOr<void> decode(Decoder& decoder, GUI::AutocompleteProvider::TokenInfo& entry)
|
||||
{
|
||||
u32 semantic_type { 0 };
|
||||
static_assert(sizeof(semantic_type) == sizeof(entry.type));
|
||||
|
||||
TRY(decoder.decode(semantic_type));
|
||||
entry.type = static_cast<GUI::AutocompleteProvider::TokenInfo::SemanticType>(semantic_type);
|
||||
TRY(decoder.decode(entry.start_line));
|
||||
TRY(decoder.decode(entry.start_column));
|
||||
TRY(decoder.decode(entry.end_line));
|
||||
TRY(decoder.decode(entry.end_column));
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,6 +69,32 @@ public:
|
|||
|
||||
virtual void provide_completions(Function<void(Vector<Entry>)>) = 0;
|
||||
|
||||
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 };
|
||||
};
|
||||
|
||||
void attach(TextEditor& editor)
|
||||
{
|
||||
VERIFY(!m_editor);
|
||||
|
|
Loading…
Add table
Reference in a new issue