summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio/AutoCompleteResponse.h
blob: de46cf741bfbc95066328df72aae866f0595338e (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
/*
 * 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 << response.partial_input_length;
    encoder << response.language;
    encoder << response.display_text;
    encoder << response.hide_autocomplete_after_applying;
    return true;
}

template<>
inline ErrorOr<void> decode(IPC::Decoder& decoder, GUI::AutocompleteProvider::Entry& response)
{
    TRY(decoder.decode(response.completion));
    TRY(decoder.decode(response.partial_input_length));
    TRY(decoder.decode(response.language));
    TRY(decoder.decode(response.display_text));
    TRY(decoder.decode(response.hide_autocomplete_after_applying));
    return {};
}

template<>
inline bool encode(Encoder& encoder, const GUI::AutocompleteProvider::ProjectLocation& location)
{
    encoder << location.file;
    encoder << location.line;
    encoder << location.column;
    return true;
}

template<>
inline ErrorOr<void> decode(Decoder& decoder, GUI::AutocompleteProvider::ProjectLocation& location)
{
    TRY(decoder.decode(location.file));
    TRY(decoder.decode(location.line));
    TRY(decoder.decode(location.column));
    return {};
}

template<>
inline bool encode(Encoder& encoder, const GUI::AutocompleteProvider::Declaration& declaration)
{
    encoder << declaration.name;
    if (!encode(encoder, declaration.position))
        return false;
    encoder << declaration.type;
    encoder << declaration.scope;
    return true;
}

template<>
inline ErrorOr<void> decode(Decoder& decoder, GUI::AutocompleteProvider::Declaration& declaration)
{
    TRY(decoder.decode(declaration.name));
    TRY(decoder.decode(declaration.position));
    TRY(decoder.decode(declaration.type));
    TRY(decoder.decode(declaration.scope));
    return {};
}

template<>
inline bool encode(Encoder& encoder, Cpp::Parser::TodoEntry const& entry)
{
    encoder << entry.content;
    encoder << entry.filename;
    encoder << entry.line;
    encoder << entry.column;
    return true;
}

template<>
inline ErrorOr<void> decode(Decoder& decoder, Cpp::Parser::TodoEntry& entry)
{
    TRY(decoder.decode(entry.content));
    TRY(decoder.decode(entry.filename));
    TRY(decoder.decode(entry.line));
    TRY(decoder.decode(entry.column));
    return {};
}

}