blob: f394fa8ff110a48c1e5b4260161155193d1ed855 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <AK/Types.h>
#include <LibCpp/Parser.h>
#include <LibGUI/AutocompleteProvider.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
namespace IPC {
template<>
inline bool encode(IPC::Encoder& encoder, const GUI::AutocompleteProvider::Entry& response)
{
encoder << response.completion;
encoder << (u64)response.partial_input_length;
encoder << (u32)response.language;
encoder << response.display_text;
return true;
}
template<>
inline bool decode(IPC::Decoder& decoder, GUI::AutocompleteProvider::Entry& response)
{
u32 language = 0;
u64 partial_input_length = 0;
bool ok = decoder.decode(response.completion)
&& decoder.decode(partial_input_length)
&& decoder.decode(language)
&& decoder.decode(response.display_text);
if (ok) {
response.language = static_cast<GUI::AutocompleteProvider::Language>(language);
response.partial_input_length = partial_input_length;
}
return ok;
}
template<>
inline bool encode(Encoder& encoder, const GUI::AutocompleteProvider::ProjectLocation& location)
{
encoder << location.file;
encoder << (u64)location.line;
encoder << (u64)location.column;
return true;
}
template<>
inline bool decode(Decoder& decoder, GUI::AutocompleteProvider::ProjectLocation& location)
{
u64 line = 0;
u64 column = 0;
if (!decoder.decode(location.file))
return false;
if (!decoder.decode(line))
return false;
if (!decoder.decode(column))
return false;
location.line = line;
location.column = column;
return true;
}
template<>
inline bool encode(Encoder& encoder, const GUI::AutocompleteProvider::Declaration& declaration)
{
encoder << declaration.name;
if (!encode(encoder, declaration.position))
return false;
encoder << (u32)declaration.type;
encoder << declaration.scope;
return true;
}
template<>
inline bool decode(Decoder& decoder, GUI::AutocompleteProvider::Declaration& declaration)
{
if (!decoder.decode(declaration.name))
return false;
if (!decode(decoder, declaration.position))
return false;
u32 type;
if (!decoder.decode(type))
return false;
if (!decoder.decode(declaration.scope))
return false;
declaration.type = static_cast<GUI::AutocompleteProvider::DeclarationType>(type);
return true;
}
template<>
inline bool encode(Encoder& encoder, Cpp::Parser::TodoEntry const& entry)
{
encoder << entry.content;
encoder << entry.filename;
encoder << (u64)entry.line;
encoder << (u64)entry.column;
return true;
}
template<>
inline bool decode(Decoder& decoder, Cpp::Parser::TodoEntry& entry)
{
u64 line = 0;
u64 column = 0;
if (!decoder.decode(entry.content))
return false;
if (!decoder.decode(entry.filename))
return false;
if (!decoder.decode(line))
return false;
if (!decoder.decode(column))
return false;
entry.line = line;
entry.column = column;
return true;
}
}
|