|
1 |
| -#include "Basic/Document.h" |
| 1 | +#pragma once |
| 2 | + |
2 | 3 | #include "Basic/SourceCode.h"
|
3 | 4 | #include "Index/Shared.h"
|
4 |
| -#include "Support/JSON.h" |
| 5 | +#include "Support/Enum.h" |
5 | 6 |
|
6 | 7 | namespace clice {
|
7 | 8 |
|
8 |
| -namespace proto { |
9 |
| - |
10 |
| -/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#foldingRangeClientCapabilities |
11 |
| -struct FoldingRangeClientCapabilities {}; |
| 9 | +class ASTInfo; |
12 | 10 |
|
13 |
| -/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#foldingRangeParams |
14 |
| -struct FoldingRangeParams { |
15 |
| - /// The text document. |
16 |
| - TextDocumentIdentifier textDocument; |
17 |
| -}; |
| 11 | +namespace feature { |
18 | 12 |
|
19 | 13 | struct FoldingRangeKind : refl::Enum<FoldingRangeKind> {
|
20 | 14 | enum Kind : uint8_t {
|
21 | 15 | Invalid = 0,
|
22 | 16 | Comment,
|
23 | 17 | Imports,
|
24 | 18 | Region,
|
| 19 | + Namespace, |
| 20 | + Class, |
| 21 | + Enum, |
| 22 | + Struct, |
| 23 | + Union, |
| 24 | + LambdaCapture, |
| 25 | + FunctionParams, |
| 26 | + FunctionBody, |
| 27 | + FunctionCall, |
| 28 | + CompoundStmt, |
| 29 | + AccessSpecifier, |
| 30 | + ConditionDirective, |
| 31 | + Initializer, |
25 | 32 | };
|
26 | 33 |
|
27 | 34 | using Enum::Enum;
|
28 | 35 |
|
29 | 36 | constexpr static auto InvalidEnum = Invalid;
|
30 | 37 | };
|
31 | 38 |
|
32 |
| -/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#foldingRange |
| 39 | +/// We don't record the coalesced text for a range, because it's rarely useful. |
33 | 40 | struct FoldingRange {
|
34 |
| - /// The zero-based start line of the range to fold. The folded area starts after the line's last |
35 |
| - /// character. |
36 |
| - uinteger startLine; |
37 |
| - |
38 |
| - /// The zero-based end line of the range to fold. The folded area ends with the line's last |
39 |
| - /// character. |
40 |
| - uinteger endLine; |
41 |
| - |
42 |
| - /// The zero-based character offset from where the folded range starts. |
43 |
| - uinteger startCharacter; |
44 |
| - |
45 |
| - /// The zero-based character offset before the folded range ends. |
46 |
| - uinteger endCharacter; |
| 41 | + /// The range to fold. |
| 42 | + LocalSourceRange range; |
47 | 43 |
|
48 | 44 | /// Describes the kind of the folding range.
|
49 | 45 | FoldingRangeKind kind;
|
50 | 46 |
|
51 |
| - // The text that the client should show when the specified range is collapsed. |
52 |
| - string collapsedText; |
| 47 | + /// The text to display when the folding range is collapsed. |
| 48 | + std::string text; |
53 | 49 | };
|
54 | 50 |
|
55 |
| -using FoldingRangeResult = std::vector<FoldingRange>; |
56 |
| - |
57 |
| -} // namespace proto |
58 |
| - |
59 |
| -class ASTInfo; |
60 |
| -class SourceConverter; |
61 |
| - |
62 |
| -namespace feature::foldingrange { |
63 |
| - |
64 |
| -json::Value capability(json::Value clientCapabilities); |
65 |
| - |
66 |
| -/// We don't record the coalesced text for a range, because it's rarely useful. |
67 |
| -struct FoldingRange { |
68 |
| - LocalSourceRange range; |
69 |
| - proto::FoldingRangeKind kind; |
70 |
| -}; |
71 |
| - |
72 |
| -using Result = std::vector<FoldingRange>; |
| 51 | +/// Generate folding range for interested file only. |
| 52 | +std::vector<FoldingRange> foldingRange(ASTInfo& AST); |
73 | 53 |
|
74 | 54 | /// Generate folding range for all files.
|
75 |
| -index::Shared<Result> foldingRange(ASTInfo& AST); |
76 |
| - |
77 |
| -/// Return folding range in main file. |
78 |
| -Result foldingRange(proto::FoldingRangeParams param, ASTInfo& AST); |
79 |
| - |
80 |
| -proto::FoldingRange toLspType(const FoldingRange& folding, |
81 |
| - const SourceConverter& SC, |
82 |
| - llvm::StringRef content); |
83 |
| - |
84 |
| -proto::FoldingRangeResult toLspResult(llvm::ArrayRef<FoldingRange> foldings, |
85 |
| - const SourceConverter& SC, |
86 |
| - llvm::StringRef content); |
| 55 | +index::Shared<std::vector<FoldingRange>> indexFoldingRange(ASTInfo& AST); |
87 | 56 |
|
88 |
| -} // namespace feature::foldingrange |
| 57 | +} // namespace feature |
89 | 58 |
|
90 | 59 | } // namespace clice
|
0 commit comments