clang-tools  10.0.0git
Hover.h
Go to the documentation of this file.
1 //===--- Hover.h - Information about code at the cursor location -*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_HOVER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_HOVER_H
11 
12 #include "FormattedString.h"
13 #include "ParsedAST.h"
14 #include "Protocol.h"
15 #include "clang/Index/IndexSymbol.h"
16 
17 namespace clang {
18 namespace clangd {
19 
20 /// Contains detailed information about a Symbol. Especially useful when
21 /// generating hover responses. It can be rendered as a hover panel, or
22 /// embedding clients can use the structured information to provide their own
23 /// UI.
24 struct HoverInfo {
25  /// Represents parameters of a function, a template or a macro.
26  /// For example:
27  /// - void foo(ParamType Name = DefaultValue)
28  /// - #define FOO(Name)
29  /// - template <ParamType Name = DefaultType> class Foo {};
30  struct Param {
31  /// The pretty-printed parameter type, e.g. "int", or "typename" (in
32  /// TemplateParameters), might be None for macro parameters.
33  llvm::Optional<std::string> Type;
34  /// None for unnamed parameters.
35  llvm::Optional<std::string> Name;
36  /// None if no default is provided.
37  llvm::Optional<std::string> Default;
38  };
39 
40  /// For a variable named Bar, declared in clang::clangd::Foo::getFoo the
41  /// following fields will hold:
42  /// - NamespaceScope: clang::clangd::
43  /// - LocalScope: Foo::getFoo::
44  /// - Name: Bar
45 
46  /// Scopes might be None in cases where they don't make sense, e.g. macros and
47  /// auto/decltype.
48  /// Contains all of the enclosing namespaces, empty string means global
49  /// namespace.
50  llvm::Optional<std::string> NamespaceScope;
51  /// Remaining named contexts in symbol's qualified name, empty string means
52  /// symbol is not local.
53  std::string LocalScope;
54  /// Name of the symbol, does not contain any "::".
55  std::string Name;
56  llvm::Optional<Range> SymRange;
58  std::string Documentation;
59  /// Source code containing the definition of the symbol.
60  std::string Definition;
61 
62  /// Pretty-printed variable type.
63  /// Set only for variables.
64  llvm::Optional<std::string> Type;
65  /// Set for functions and lambadas.
66  llvm::Optional<std::string> ReturnType;
67  /// Set for functions, lambdas and macros with parameters.
68  llvm::Optional<std::vector<Param>> Parameters;
69  /// Set for all templates(function, class, variable).
70  llvm::Optional<std::vector<Param>> TemplateParameters;
71  /// Contains the evaluated value of the symbol if available.
72  llvm::Optional<std::string> Value;
73 
74  /// Produce a user-readable information.
75  markup::Document present() const;
76 };
77 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const HoverInfo::Param &);
78 inline bool operator==(const HoverInfo::Param &LHS,
79  const HoverInfo::Param &RHS) {
80  return std::tie(LHS.Type, LHS.Name, LHS.Default) ==
81  std::tie(RHS.Type, RHS.Name, RHS.Default);
82 }
83 
84 /// Get the hover information when hovering at \p Pos.
85 llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
86  format::FormatStyle Style,
87  const SymbolIndex *Index);
88 
89 } // namespace clangd
90 } // namespace clang
91 
92 #endif
Contains detailed information about a Symbol.
Definition: Hover.h:24
index::SymbolKind Kind
Definition: Hover.h:57
bool operator==(const HoverInfo::Param &LHS, const HoverInfo::Param &RHS)
Definition: Hover.h:78
clang::find_all_symbols::SymbolInfo::SymbolKind SymbolKind
Definition: SymbolInfo.cpp:21
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:85
llvm::Optional< std::string > Name
None for unnamed parameters.
Definition: Hover.h:35
llvm::Optional< std::string > Type
Pretty-printed variable type.
Definition: Hover.h:64
llvm::Optional< std::vector< Param > > Parameters
Set for functions, lambdas and macros with parameters.
Definition: Hover.h:68
Represents parameters of a function, a template or a macro.
Definition: Hover.h:30
std::string Definition
Source code containing the definition of the symbol.
Definition: Hover.h:60
llvm::Optional< std::string > Type
The pretty-printed parameter type, e.g.
Definition: Hover.h:33
std::string Name
Name of the symbol, does not contain any "::".
Definition: Hover.h:55
llvm::Optional< HoverInfo > getHover(ParsedAST &AST, Position Pos, format::FormatStyle Style, const SymbolIndex *Index)
Get the hover information when hovering at Pos.
Definition: Hover.cpp:477
llvm::Optional< Range > SymRange
Definition: Hover.h:56
llvm::Optional< std::string > Default
None if no default is provided.
Definition: Hover.h:37
Position Pos
Definition: SourceCode.cpp:772
A format-agnostic representation for structured text.
std::string LocalScope
Remaining named contexts in symbol&#39;s qualified name, empty string means symbol is not local...
Definition: Hover.h:53
llvm::Optional< std::string > NamespaceScope
For a variable named Bar, declared in clang::clangd::Foo::getFoo the following fields will hold: ...
Definition: Hover.h:50
Stores and provides access to parsed AST.
Definition: ParsedAST.h:46
llvm::Optional< std::vector< Param > > TemplateParameters
Set for all templates(function, class, variable).
Definition: Hover.h:70
llvm::Optional< std::string > ReturnType
Set for functions and lambadas.
Definition: Hover.h:66
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< std::string > Value
Contains the evaluated value of the symbol if available.
Definition: Hover.h:72
markup::Document present() const
Produce a user-readable information.
Definition: Hover.cpp:526
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
std::string Documentation
Definition: Hover.h:58
const SymbolIndex * Index
Definition: Dexp.cpp:84
static cl::opt< std::string > FormatStyle("format-style", cl::desc(R"( Style for formatting code around applied fixes: - 'none' (default) turns off formatting - 'file' (literally 'file', not a placeholder) uses .clang-format file in the closest parent directory - '{ <json> }' specifies options inline, e.g. -format-style='{BasedOnStyle: llvm, IndentWidth: 8}' - 'llvm', 'google', 'webkit', 'mozilla' See clang-format documentation for the up-to-date information about formatting styles and options. This option overrides the 'FormatStyle` option in .clang-tidy file, if any. )"), cl::init("none"), cl::cat(ClangTidyCategory))