Skip to content

Commit 5cfea60

Browse files
committed
Strip comments
1 parent 7c3c815 commit 5cfea60

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

src/Feature/Hover.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ static std::string get_document(CompilationUnit& unit,
168168
if(!comment) {
169169
return "";
170170
}
171-
auto raw_string = comment->getRawText(Ctx.getSourceManager()).str();
171+
auto raw_string = comment->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
172+
LOG_WARN("Got comment:\n```\n{}\n```\n", raw_string);
172173
return "";
173174
}
174175

@@ -426,7 +427,9 @@ static std::optional<Hover> hover(CompilationUnit& unit,
426427
const config::HoverOptions& opt) {
427428
// TODO: Hover for type
428429
// TODO: Add source code
429-
return Hover{.kind = SymbolKind::Type, .name = ty.getAsString()};
430+
auto& ctx = unit.context();
431+
auto pp = ctx.getPrintingPolicy();
432+
return Hover{.kind = SymbolKind::Type, .name = print_type(ctx, ty, pp, opt)};
430433
}
431434

432435
static std::optional<Hover> hover(CompilationUnit& unit,

tests/unit/Feature/HoverTests.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,72 @@ int main() {
245245
}
246246
};
247247

248+
TEST_CASE(Comments) {
249+
constexpr auto code = R"CODE(
250+
/// This is line comment
251+
/// This comment line 2
252+
/// This comment line 3 with indent
253+
/// This comment line 4
254+
static void fu$(pos_0)nc() {
255+
256+
}
257+
258+
// This is line comment
259+
// This comment line 2
260+
// This comment line 3 with indent
261+
// This comment line 4
262+
static void fu$(pos_1)nc1() {
263+
264+
}
265+
266+
/*
267+
* This is block comment
268+
* This comment line 2
269+
* This comment line 3 with indent
270+
* This comment line 4
271+
*/
272+
static void fu$(pos_2)nc2() {
273+
274+
}
275+
276+
/**
277+
* This is block comment
278+
* This comment line 2
279+
* This comment line 3 with indent
280+
* This comment line 4
281+
**/
282+
static void fu$(pos_3)nc3() {
283+
284+
}
285+
286+
/********************************************
287+
* This is block comment
288+
* This comment line 2
289+
* This comment line 3 with indent
290+
* This comment line 4
291+
*******************************************/
292+
static void fu$(pos_4)nc4() {
293+
294+
}
295+
)CODE";
296+
297+
auto annotation = AnnotatedSource::from(code);
298+
tester.add_main("main.cpp", annotation.content);
299+
tester.compile();
300+
ASSERT_TRUE(tester.unit.has_value());
301+
const unsigned count = annotation.offsets.size();
302+
for(unsigned i = 0; i < count; ++i) {
303+
unsigned offset = annotation.offsets[std::format("pos_{}", i)];
304+
auto HI = clice::feature::hover(*tester.unit, offset, {});
305+
// if(HI.has_value()) {
306+
// auto msg = HI->display({});
307+
// std::println("```\n{}```\n", *msg);
308+
// } else {
309+
// std::println("No hover info");
310+
// }
311+
}
312+
}
313+
248314
TEST_CASE(Namespace) {
249315
run(R"cpp(
250316
namespace A {

0 commit comments

Comments
 (0)