annotate clang-tools-extra/clangd/Hover.h @ 180:680fa57a2f20

fix compile errors.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 30 May 2020 17:44:06 +0900
parents 0572611fdcc8
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===--- Hover.h - Information about code at the cursor location -*- C++-*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_HOVER_H
anatofuz
parents:
diff changeset
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_HOVER_H
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 #include "ParsedAST.h"
anatofuz
parents:
diff changeset
13 #include "Protocol.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
14 #include "support/Markup.h"
150
anatofuz
parents:
diff changeset
15 #include "clang/Index/IndexSymbol.h"
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 namespace clang {
anatofuz
parents:
diff changeset
18 namespace clangd {
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 /// Contains detailed information about a Symbol. Especially useful when
anatofuz
parents:
diff changeset
21 /// generating hover responses. It can be rendered as a hover panel, or
anatofuz
parents:
diff changeset
22 /// embedding clients can use the structured information to provide their own
anatofuz
parents:
diff changeset
23 /// UI.
anatofuz
parents:
diff changeset
24 struct HoverInfo {
anatofuz
parents:
diff changeset
25 /// Represents parameters of a function, a template or a macro.
anatofuz
parents:
diff changeset
26 /// For example:
anatofuz
parents:
diff changeset
27 /// - void foo(ParamType Name = DefaultValue)
anatofuz
parents:
diff changeset
28 /// - #define FOO(Name)
anatofuz
parents:
diff changeset
29 /// - template <ParamType Name = DefaultType> class Foo {};
anatofuz
parents:
diff changeset
30 struct Param {
anatofuz
parents:
diff changeset
31 /// The pretty-printed parameter type, e.g. "int", or "typename" (in
anatofuz
parents:
diff changeset
32 /// TemplateParameters), might be None for macro parameters.
anatofuz
parents:
diff changeset
33 llvm::Optional<std::string> Type;
anatofuz
parents:
diff changeset
34 /// None for unnamed parameters.
anatofuz
parents:
diff changeset
35 llvm::Optional<std::string> Name;
anatofuz
parents:
diff changeset
36 /// None if no default is provided.
anatofuz
parents:
diff changeset
37 llvm::Optional<std::string> Default;
anatofuz
parents:
diff changeset
38 };
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 /// For a variable named Bar, declared in clang::clangd::Foo::getFoo the
anatofuz
parents:
diff changeset
41 /// following fields will hold:
anatofuz
parents:
diff changeset
42 /// - NamespaceScope: clang::clangd::
anatofuz
parents:
diff changeset
43 /// - LocalScope: Foo::getFoo::
anatofuz
parents:
diff changeset
44 /// - Name: Bar
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 /// Scopes might be None in cases where they don't make sense, e.g. macros and
anatofuz
parents:
diff changeset
47 /// auto/decltype.
anatofuz
parents:
diff changeset
48 /// Contains all of the enclosing namespaces, empty string means global
anatofuz
parents:
diff changeset
49 /// namespace.
anatofuz
parents:
diff changeset
50 llvm::Optional<std::string> NamespaceScope;
anatofuz
parents:
diff changeset
51 /// Remaining named contexts in symbol's qualified name, empty string means
anatofuz
parents:
diff changeset
52 /// symbol is not local.
anatofuz
parents:
diff changeset
53 std::string LocalScope;
anatofuz
parents:
diff changeset
54 /// Name of the symbol, does not contain any "::".
anatofuz
parents:
diff changeset
55 std::string Name;
anatofuz
parents:
diff changeset
56 llvm::Optional<Range> SymRange;
anatofuz
parents:
diff changeset
57 index::SymbolKind Kind = index::SymbolKind::Unknown;
anatofuz
parents:
diff changeset
58 std::string Documentation;
anatofuz
parents:
diff changeset
59 /// Source code containing the definition of the symbol.
anatofuz
parents:
diff changeset
60 std::string Definition;
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 /// Pretty-printed variable type.
anatofuz
parents:
diff changeset
63 /// Set only for variables.
anatofuz
parents:
diff changeset
64 llvm::Optional<std::string> Type;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
65 /// Set for functions and lambdas.
150
anatofuz
parents:
diff changeset
66 llvm::Optional<std::string> ReturnType;
anatofuz
parents:
diff changeset
67 /// Set for functions, lambdas and macros with parameters.
anatofuz
parents:
diff changeset
68 llvm::Optional<std::vector<Param>> Parameters;
anatofuz
parents:
diff changeset
69 /// Set for all templates(function, class, variable).
anatofuz
parents:
diff changeset
70 llvm::Optional<std::vector<Param>> TemplateParameters;
anatofuz
parents:
diff changeset
71 /// Contains the evaluated value of the symbol if available.
anatofuz
parents:
diff changeset
72 llvm::Optional<std::string> Value;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
73 /// Contains the byte-size of fields and types where it's interesting.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
74 llvm::Optional<uint64_t> Size;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
75 /// Contains the offset of fields within the enclosing class.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
76 llvm::Optional<uint64_t> Offset;
150
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 /// Produce a user-readable information.
anatofuz
parents:
diff changeset
79 markup::Document present() const;
anatofuz
parents:
diff changeset
80 };
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
81
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
82 // Try to infer structure of a documentation comment (e.g. line breaks).
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
83 // FIXME: move to another file so CodeComplete doesn't depend on Hover.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
84 void parseDocumentation(llvm::StringRef Input, markup::Document &Output);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
85
150
anatofuz
parents:
diff changeset
86 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const HoverInfo::Param &);
anatofuz
parents:
diff changeset
87 inline bool operator==(const HoverInfo::Param &LHS,
anatofuz
parents:
diff changeset
88 const HoverInfo::Param &RHS) {
anatofuz
parents:
diff changeset
89 return std::tie(LHS.Type, LHS.Name, LHS.Default) ==
anatofuz
parents:
diff changeset
90 std::tie(RHS.Type, RHS.Name, RHS.Default);
anatofuz
parents:
diff changeset
91 }
anatofuz
parents:
diff changeset
92
anatofuz
parents:
diff changeset
93 /// Get the hover information when hovering at \p Pos.
anatofuz
parents:
diff changeset
94 llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
anatofuz
parents:
diff changeset
95 format::FormatStyle Style,
anatofuz
parents:
diff changeset
96 const SymbolIndex *Index);
anatofuz
parents:
diff changeset
97
anatofuz
parents:
diff changeset
98 } // namespace clangd
anatofuz
parents:
diff changeset
99 } // namespace clang
anatofuz
parents:
diff changeset
100
anatofuz
parents:
diff changeset
101 #endif