Skip to content

Commit ef4ce06

Browse files
authored
Index hover (#92)
1 parent ac6edc8 commit ef4ce06

File tree

7 files changed

+182
-1651
lines changed

7 files changed

+182
-1651
lines changed

include/Feature/Hover.h

+61-67
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,89 @@
11
#pragma once
22

3-
#include "Basic/Document.h"
43
#include "AST/SymbolKind.h"
4+
#include "Basic/SourceCode.h"
5+
#include "Index/Shared.h"
56

67
namespace clice {
78

89
class ASTInfo;
910

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-
2311
namespace config {
2412

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 {};
4014

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
4416

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+
};
4843

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;
5149

52-
/// Show associated document.
53-
bool documentation : 1 = true;
50+
/// Extra information.
51+
std::vector<HoverItem> items;
5452

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;
5855

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;
6258

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;
6661
};
6762

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+
};
6969

70-
namespace feature::hover {
70+
/// Hover information for all symbols in the file.
71+
std::vector<Hover> hovers;
7172

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;
8175
};
8276

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);
8579

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);
9082

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);
9285

93-
} // namespace feature::hover
86+
} // namespace feature
9487

9588
} // namespace clice
89+

include/Server/LSPConverter.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class LSPConverter {
1717

1818
Result convert(llvm::StringRef path, llvm::ArrayRef<feature::SemanticToken> tokens);
1919

20+
Result convert(const feature::Hover& hover);
21+
2022
private:
2123
proto::PositionEncodingKind kind;
2224
};

0 commit comments

Comments
 (0)