File tree Expand file tree Collapse file tree 11 files changed +451
-53
lines changed Expand file tree Collapse file tree 11 files changed +451
-53
lines changed Original file line number Diff line number Diff line change @@ -1262,11 +1262,9 @@ void ClangdLSPServer::onHover(const TextDocumentPositionParams &Params,
1262
1262
R.contents .kind = HoverContentFormat;
1263
1263
R.range = (*H)->SymRange ;
1264
1264
switch (HoverContentFormat) {
1265
- case MarkupKind::PlainText:
1266
- R.contents .value = (*H)->present ().asPlainText ();
1267
- return Reply (std::move (R));
1268
1265
case MarkupKind::Markdown:
1269
- R.contents .value = (*H)->present ().asMarkdown ();
1266
+ case MarkupKind::PlainText:
1267
+ R.contents .value = (*H)->present (HoverContentFormat);
1270
1268
return Reply (std::move (R));
1271
1269
};
1272
1270
llvm_unreachable (" unhandled MarkupKind" );
Original file line number Diff line number Diff line change @@ -177,6 +177,19 @@ struct Config {
177
177
// / Controls highlighting modifiers that are disabled.
178
178
std::vector<std::string> DisabledModifiers;
179
179
} SemanticTokens;
180
+
181
+ enum class CommentFormatPolicy {
182
+ // / Treat comments as plain text.
183
+ PlainText,
184
+ // / Treat comments as Markdown.
185
+ Markdown,
186
+ // / Treat comments as doxygen.
187
+ Doxygen,
188
+ };
189
+
190
+ struct {
191
+ CommentFormatPolicy CommentFormat = CommentFormatPolicy::PlainText;
192
+ } Documentation;
180
193
};
181
194
182
195
} // namespace clangd
Original file line number Diff line number Diff line change @@ -198,6 +198,7 @@ struct FragmentCompiler {
198
198
compile (std::move (F.InlayHints ));
199
199
compile (std::move (F.SemanticTokens ));
200
200
compile (std::move (F.Style ));
201
+ compile (std::move (F.Documentation ));
201
202
}
202
203
203
204
void compile (Fragment::IfBlock &&F) {
@@ -760,6 +761,21 @@ struct FragmentCompiler {
760
761
}
761
762
}
762
763
764
+ void compile (Fragment::DocumentationBlock &&F) {
765
+ if (F.CommentFormat ) {
766
+ if (auto Val =
767
+ compileEnum<Config::CommentFormatPolicy>(" CommentFormat" ,
768
+ *F.CommentFormat )
769
+ .map (" Plaintext" , Config::CommentFormatPolicy::PlainText)
770
+ .map (" Markdown" , Config::CommentFormatPolicy::Markdown)
771
+ .map (" Doxygen" , Config::CommentFormatPolicy::Doxygen)
772
+ .value ())
773
+ Out.Apply .push_back ([Val](const Params &, Config &C) {
774
+ C.Documentation .CommentFormat = *Val;
775
+ });
776
+ }
777
+ }
778
+
763
779
constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;
764
780
constexpr static llvm::SourceMgr::DiagKind Warning =
765
781
llvm::SourceMgr::DK_Warning;
Original file line number Diff line number Diff line change @@ -372,6 +372,17 @@ struct Fragment {
372
372
std::vector<Located<std::string>> DisabledModifiers;
373
373
};
374
374
SemanticTokensBlock SemanticTokens;
375
+
376
+ // / Configures documentation style and behaviour.
377
+ struct DocumentationBlock {
378
+ // / Specifies the format of comments in the code.
379
+ // / Valid values are enum Config::CommentFormatPolicy values:
380
+ // / - Plaintext: Treat comments as plain text.
381
+ // / - Markdown: Treat comments as Markdown.
382
+ // / - Doxygen: Treat comments as doxygen.
383
+ std::optional<Located<std::string>> CommentFormat;
384
+ };
385
+ DocumentationBlock Documentation;
375
386
};
376
387
377
388
} // namespace config
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ class Parser {
68
68
Dict.handle (" Hover" , [&](Node &N) { parse (F.Hover , N); });
69
69
Dict.handle (" InlayHints" , [&](Node &N) { parse (F.InlayHints , N); });
70
70
Dict.handle (" SemanticTokens" , [&](Node &N) { parse (F.SemanticTokens , N); });
71
+ Dict.handle (" Documentation" , [&](Node &N) { parse (F.Documentation , N); });
71
72
Dict.parse (N);
72
73
return !(N.failed () || HadError);
73
74
}
@@ -299,6 +300,15 @@ class Parser {
299
300
Dict.parse (N);
300
301
}
301
302
303
+ void parse (Fragment::DocumentationBlock &F, Node &N) {
304
+ DictParser Dict (" Documentation" , this );
305
+ Dict.handle (" CommentFormat" , [&](Node &N) {
306
+ if (auto Value = scalarValue (N, " CommentFormat" ))
307
+ F.CommentFormat = *Value;
308
+ });
309
+ Dict.parse (N);
310
+ }
311
+
302
312
// Helper for parsing mapping nodes (dictionaries).
303
313
// We don't use YamlIO as we want to control over unknown keys.
304
314
class DictParser {
Original file line number Diff line number Diff line change 15
15
#include " Headers.h"
16
16
#include " IncludeCleaner.h"
17
17
#include " ParsedAST.h"
18
+ #include " Protocol.h"
18
19
#include " Selection.h"
19
20
#include " SourceCode.h"
20
21
#include " clang-include-cleaner/Analysis.h"
@@ -1535,6 +1536,26 @@ markup::Document HoverInfo::present() const {
1535
1536
return Output;
1536
1537
}
1537
1538
1539
+ std::string HoverInfo::present (MarkupKind Kind) const {
1540
+ if (Kind == MarkupKind::Markdown) {
1541
+ const Config &Cfg = Config::current ();
1542
+ if ((Cfg.Documentation .CommentFormat ==
1543
+ Config::CommentFormatPolicy::Markdown) ||
1544
+ (Cfg.Documentation .CommentFormat ==
1545
+ Config::CommentFormatPolicy::Doxygen))
1546
+ // If the user prefers Markdown, we use the present() method to generate
1547
+ // the Markdown output.
1548
+ return present ().asMarkdown ();
1549
+ if (Cfg.Documentation .CommentFormat ==
1550
+ Config::CommentFormatPolicy::PlainText)
1551
+ // If the user prefers plain text, we use the present() method to generate
1552
+ // the plain text output.
1553
+ return present ().asEscapedMarkdown ();
1554
+ }
1555
+
1556
+ return present ().asPlainText ();
1557
+ }
1558
+
1538
1559
// If the backtick at `Offset` starts a probable quoted range, return the range
1539
1560
// (including the quotes).
1540
1561
std::optional<llvm::StringRef> getBacktickQuoteRange (llvm::StringRef Line,
Original file line number Diff line number Diff line change @@ -120,6 +120,8 @@ struct HoverInfo {
120
120
121
121
// / Produce a user-readable information.
122
122
markup::Document present () const ;
123
+
124
+ std::string present (MarkupKind Kind) const ;
123
125
};
124
126
125
127
inline bool operator ==(const HoverInfo::PrintedType &LHS,
You can’t perform that action at this time.
0 commit comments