|
1 | 1 | #pragma once
|
2 | 2 |
|
3 |
| -#include "Basic/Document.h" |
4 | 3 | #include "AST/SymbolKind.h"
|
| 4 | +#include "Basic/SourceCode.h" |
| 5 | +#include "Index/Shared.h" |
5 | 6 |
|
6 | 7 | namespace clice {
|
7 | 8 |
|
8 | 9 | class ASTInfo;
|
9 | 10 |
|
10 |
| -namespace proto { |
11 |
| - |
12 |
| -// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#hoverParams |
13 |
| -struct HoverParams { |
14 |
| - // The text document. |
15 |
| - URI textDocument; |
16 |
| - |
17 |
| - // The position inside the text document. |
18 |
| - Position position; |
19 |
| -}; |
20 |
| - |
21 |
| -} // namespace proto |
22 |
| - |
23 | 11 | namespace config {
|
24 | 12 |
|
25 |
| -/// For a full memory layout infomation, the render kind decides how to display the value. By |
26 |
| -/// default, show both decimal and hexadecimal. e.g: |
27 |
| -/// size = 4 (0x4), align = 4 (0x4), offset: 0 (0x0) |
28 |
| -/// while show decimal only: |
29 |
| -/// size = 4, align = 4, offset: 0 |
30 |
| -/// while show hexadecimal only: |
31 |
| -/// size = 0x4, align = 0x4, offset: 0x0 |
32 |
| -/// |
33 |
| -/// And bit field is always displayed in decimal. |
34 |
| -/// size = 1 bit (+5 bits padding), align = 1 byte, offset: 4 byte + 2 bit |
35 |
| -enum class MemoryLayoutRenderKind : uint8_t { |
36 |
| - Both = 0, |
37 |
| - Decimal, |
38 |
| - Hexadecimal, |
39 |
| -}; |
| 13 | +struct HoverOptions {}; |
40 | 14 |
|
41 |
| -struct HoverOption { |
42 |
| - /// The maximum number of fields to show in the hover of a class/struct/enum. 0 means show all. |
43 |
| - uint16_t maxFieldsCount = 0; |
| 15 | +} // namespace config |
44 | 16 |
|
45 |
| - /// TODO: |
46 |
| - /// The maximum number of derived classes to show in the hover of a pure virtual class. |
47 |
| - // uint16_t maxDerivedClassNum; |
| 17 | +namespace feature { |
| 18 | + |
| 19 | +struct HoverItem { |
| 20 | + enum class HoverKind : uint8_t { |
| 21 | + /// The typename of a variable or a type alias. |
| 22 | + Type, |
| 23 | + /// Size of type or variable. |
| 24 | + Size, |
| 25 | + /// Align of type or variable. |
| 26 | + Align, |
| 27 | + /// Offset of field in a class/struct. |
| 28 | + Offset, |
| 29 | + /// Bit width of a bit field. |
| 30 | + BitWidth, |
| 31 | + /// The index of a field in a class/struct. |
| 32 | + FieldIndex, |
| 33 | + /// The value of an enum item. |
| 34 | + EnumValue, |
| 35 | + }; |
| 36 | + |
| 37 | + using enum HoverKind; |
| 38 | + |
| 39 | + HoverKind kind; |
| 40 | + |
| 41 | + std::string value; |
| 42 | +}; |
48 | 43 |
|
49 |
| - /// Decide how to render the memory layout. |
50 |
| - MemoryLayoutRenderKind memoryLayoutRenderKind = MemoryLayoutRenderKind::Both; |
| 44 | +/// Hover information for a symbol. |
| 45 | +struct Hover { |
| 46 | + /// Title |
| 47 | + SymbolKind kind; |
| 48 | + std::string name; |
51 | 49 |
|
52 |
| - /// Show associated document. |
53 |
| - bool documentation : 1 = true; |
| 50 | + /// Extra information. |
| 51 | + std::vector<HoverItem> items; |
54 | 52 |
|
55 |
| - /// TODO: |
56 |
| - /// Show overloaded virtual method for class/struct. |
57 |
| - bool overloadVirtualMethod : 1 = true; |
| 53 | + /// Raw document in the source code. |
| 54 | + std::string document; |
58 | 55 |
|
59 |
| - /// Show documentation link for key words, this will link to corresponding page of |
60 |
| - /// `https://en.cppreference.com/w/cpp/keyword/`. |
61 |
| - bool keywords : 1 = true; |
| 56 | + /// The full qualified name of the declaration. |
| 57 | + std::string qualifier; |
62 | 58 |
|
63 |
| - /// TODO: |
64 |
| - /// Show links instead of codeblock in hover information for mentioned symbols. |
65 |
| - bool useLink : 1 = true; |
| 59 | + /// The source code of the declaration. |
| 60 | + std::string source; |
66 | 61 | };
|
67 | 62 |
|
68 |
| -} // namespace config |
| 63 | +/// Hover information for all symbols in the file. |
| 64 | +struct Hovers { |
| 65 | + struct Occurrence { |
| 66 | + LocalSourceRange range; |
| 67 | + uint32_t index; |
| 68 | + }; |
69 | 69 |
|
70 |
| -namespace feature::hover { |
| 70 | + /// Hover information for all symbols in the file. |
| 71 | + std::vector<Hover> hovers; |
71 | 72 |
|
72 |
| -/// TODO: |
73 |
| -/// Implement the action for hovering over elements. |
74 |
| -// struct HoverAction { |
75 |
| -// // Goto type |
76 |
| -// // Find reference |
77 |
| -// }; |
78 |
| - |
79 |
| -struct Result { |
80 |
| - std::string markdown; |
| 73 | + /// A map between the file offset and the index of the hover. |
| 74 | + std::vector<Occurrence> occurrences; |
81 | 75 | };
|
82 | 76 |
|
83 |
| -/// Get the hover information of a declaration with given option. |
84 |
| -Result hover(const clang::Decl* decl, const config::HoverOption& option); |
| 77 | +/// Generate the hover information for the given declaration(for test). |
| 78 | +Hover hover(ASTInfo& AST, const clang::NamedDecl* decl); |
85 | 79 |
|
86 |
| -/// Compute inlay hints for MainfileID in given param and config. |
87 |
| -std::optional<Result> hover(const proto::HoverParams& param, |
88 |
| - ASTInfo& AST, |
89 |
| - const config::HoverOption& option); |
| 80 | +/// Generate the hover information for the symbol at the given offset. |
| 81 | +Hover hover(ASTInfo& AST, uint32_t offset); |
90 | 82 |
|
91 |
| -proto::MarkupContent toLspType(Result hover); |
| 83 | +/// Generate the hover information for all files in the given AST. |
| 84 | +index::Shared<Hovers> indexHover(ASTInfo& AST); |
92 | 85 |
|
93 |
| -} // namespace feature::hover |
| 86 | +} // namespace feature |
94 | 87 |
|
95 | 88 | } // namespace clice
|
| 89 | + |
0 commit comments