codecompletionchunk.h 3.39 KB
Newer Older
1 2
/****************************************************************************
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5 6 7 8 9 10 11
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 24 25
**
****************************************************************************/

hjk's avatar
hjk committed
26
#pragma once
27

28
#include "clangsupport_global.h"
Marco Bubke's avatar
Marco Bubke committed
29

30 31
#include <utf8string.h>

32
#include <QDataStream>
33 34
#include <QVector>

35
namespace ClangBackEnd {
36

37 38 39
class CodeCompletionChunk;
using CodeCompletionChunks = QVector<CodeCompletionChunk>;

40
class CodeCompletionChunk
41 42
{
public:
43
    enum Kind : quint8 {
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
        Optional,
        TypedText,
        Text,
        Placeholder,
        Informative,
        CurrentParameter,
        LeftParen,
        RightParen,
        LeftBracket,
        RightBracket,
        LeftBrace,
        RightBrace,
        LeftAngle,
        RightAngle,
        Comma,
        ResultType,
        Colon,
        SemiColon,
        Equal,
        HorizontalSpace,
        VerticalSpace,
65 66
        Invalid = 255
    };
67

68
    CodeCompletionChunk() = default;
69 70
    CodeCompletionChunk(Kind kind,
                        const Utf8String &text,
71
                        bool isOptional = false)
Marco Bubke's avatar
Marco Bubke committed
72 73 74
        : m_text(text),
          m_kind(kind),
          m_isOptional(isOptional)
75 76 77 78 79
    {
    }

    Kind kind() const
    {
Marco Bubke's avatar
Marco Bubke committed
80
        return m_kind;
81 82 83 84
    }

    const Utf8String &text() const
    {
Marco Bubke's avatar
Marco Bubke committed
85
        return m_text;
86 87 88 89
    }

    bool isOptional() const
    {
Marco Bubke's avatar
Marco Bubke committed
90
        return m_isOptional;
91 92 93 94
    }

    friend QDataStream &operator<<(QDataStream &out, const CodeCompletionChunk &chunk)
    {
Marco Bubke's avatar
Marco Bubke committed
95 96 97
        out << static_cast<quint8>(chunk.m_kind);
        out << chunk.m_text;
        out << chunk.m_isOptional;
98 99 100 101 102 103 104 105 106

        return out;
    }

    friend QDataStream &operator>>(QDataStream &in, CodeCompletionChunk &chunk)
    {
        quint8 kind;

        in >> kind;
Marco Bubke's avatar
Marco Bubke committed
107 108
        in >> chunk.m_text;
        in >> chunk.m_isOptional;
109

Marco Bubke's avatar
Marco Bubke committed
110
        chunk.m_kind = static_cast<CodeCompletionChunk::Kind>(kind);
111 112 113 114 115 116 117 118 119 120

        return in;
    }

    friend bool operator==(const CodeCompletionChunk &first, const CodeCompletionChunk &second)
    {
        return first.kind() == second.kind()
                && first.text() == second.text()
                && first.isOptional() == second.isOptional();
    }
121 122

private:
Marco Bubke's avatar
Marco Bubke committed
123 124 125
    Utf8String m_text;
    Kind m_kind = Invalid;
    bool m_isOptional = false;
126 127
};

128
CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const CodeCompletionChunk &chunk);
129

Marco Bubke's avatar
Marco Bubke committed
130
std::ostream &operator<<(std::ostream &os, const CodeCompletionChunk::Kind &kind);
131

132
} // namespace ClangBackEnd