Skip to content

Commit 06ca470

Browse files
committed
Code style
1 parent f56745f commit 06ca470

File tree

2 files changed

+61
-58
lines changed

2 files changed

+61
-58
lines changed

include/Feature/Hover.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct Hover {
5353

5454
std::string name;
5555

56-
const char *lang = "cpp";
56+
const char* lang = "cpp";
5757

5858
/// Extra information.
5959
std::vector<HoverItem> items;

src/Feature/Hover.cpp

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace clice::feature {
1717

1818
namespace {
1919

20-
static auto to_proto_range(clang::SourceManager& sm, clang::SourceRange range) -> proto::Range {
20+
auto to_proto_range(clang::SourceManager& sm, clang::SourceRange range) -> proto::Range {
2121
auto range_b = range.getBegin();
2222
auto range_e = range.getEnd();
2323
auto begin = proto::Position{sm.getSpellingLineNumber(range_b) - 1,
@@ -37,10 +37,10 @@ clang::PrintingPolicy proxy_print_policy(clang::PrintingPolicy Base) {
3737
}
3838

3939
// Print type and optionally desuguared type
40-
static std::string print_type(clang::ASTContext& ctx,
41-
clang::QualType qt,
42-
const clang::PrintingPolicy pp,
43-
const config::HoverOptions& opt) {
40+
std::string print_type(clang::ASTContext& ctx,
41+
clang::QualType qt,
42+
const clang::PrintingPolicy pp,
43+
const config::HoverOptions& opt) {
4444
std::string ret;
4545
llvm::raw_string_ostream os(ret);
4646
while(!qt.isNull() && qt->isDecltypeType()) {
@@ -63,27 +63,27 @@ static std::string print_type(clang::ASTContext& ctx,
6363
return ret;
6464
}
6565

66-
static std::string print_type(const clang::TemplateTypeParmDecl* TTP) {
66+
std::string print_type(const clang::TemplateTypeParmDecl* TTP) {
6767
std::string ret = TTP->wasDeclaredWithTypename() ? "typename" : "class";
6868
if(TTP->isParameterPack()) {
6969
ret += " ...";
7070
}
7171
return ret;
7272
}
7373

74-
static std::string print_type(const clang::NonTypeTemplateParmDecl* NTTP,
75-
const clang::PrintingPolicy PP,
76-
const config::HoverOptions& opt) {
74+
std::string print_type(const clang::NonTypeTemplateParmDecl* NTTP,
75+
const clang::PrintingPolicy PP,
76+
const config::HoverOptions& opt) {
7777
std::string ret = print_type(NTTP->getASTContext(), NTTP->getType(), PP, opt);
7878
if(NTTP->isParameterPack()) {
7979
ret += " ...";
8080
}
8181
return ret;
8282
}
8383

84-
static std::string print_type(const clang::TemplateTemplateParmDecl* TTP,
85-
const clang::PrintingPolicy PP,
86-
const config::HoverOptions& opt) {
84+
std::string print_type(const clang::TemplateTemplateParmDecl* TTP,
85+
const clang::PrintingPolicy PP,
86+
const config::HoverOptions& opt) {
8787
using namespace clang;
8888
std::string ret;
8989
llvm::raw_string_ostream OS(ret);
@@ -105,9 +105,9 @@ static std::string print_type(const clang::TemplateTemplateParmDecl* TTP,
105105
return ret;
106106
}
107107

108-
static std::vector<HoverItem> get_hover_items(CompilationUnitRef unit,
109-
const clang::NamedDecl* decl,
110-
const config::HoverOptions& opt) {
108+
std::vector<HoverItem> get_hover_items(CompilationUnitRef unit,
109+
const clang::NamedDecl* decl,
110+
const config::HoverOptions& opt) {
111111
clang::ASTContext& ctx = unit.context();
112112
const auto pp = proxy_print_policy(ctx.getPrintingPolicy());
113113
std::vector<HoverItem> items;
@@ -161,38 +161,38 @@ static std::vector<HoverItem> get_hover_items(CompilationUnitRef unit,
161161
return items;
162162
}
163163

164-
static std::vector<HoverItem> get_hover_items(CompilationUnitRef unit,
165-
const clang::TypeLoc* typeloc,
166-
const config::HoverOptions& opt) {
164+
std::vector<HoverItem> get_hover_items(CompilationUnitRef unit,
165+
const clang::TypeLoc* typeloc,
166+
const config::HoverOptions& opt) {
167167
// TODO: Add items for typeloc
168168
return {};
169169
}
170170

171-
static std::string get_document(CompilationUnitRef unit,
172-
const clang::NamedDecl* decl,
173-
config::HoverOptions opt) {
171+
std::string get_document(CompilationUnitRef unit,
172+
const clang::NamedDecl* decl,
173+
config::HoverOptions opt) {
174174
// TODO: Get comment and strip `/**/` and `//`
175175
clang::ASTContext& Ctx = unit.context();
176176
const clang::RawComment* comment = Ctx.getRawCommentForAnyRedecl(decl);
177177
if(!comment) {
178178
return "";
179179
}
180180
auto raw_string = comment->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
181-
// LOG_WARN("Got comment:\n```\n{}\n```\n", raw_string);
181+
// LOG_DEBUG("Got comment:\n```\n{}\n```\n", raw_string);
182182
return raw_string;
183183
}
184184

185-
static std::string get_qualifier(CompilationUnitRef unit,
186-
const clang::NamedDecl* decl,
187-
config::HoverOptions opt) {
185+
std::string get_qualifier(CompilationUnitRef unit,
186+
const clang::NamedDecl* decl,
187+
config::HoverOptions opt) {
188188
std::string result;
189189
llvm::raw_string_ostream os(result);
190190
decl->printNestedNameSpecifier(os);
191191
return result;
192192
}
193193

194194
// Get all source code
195-
static std::string get_source_code(CompilationUnitRef unit, clang::SourceRange range) {
195+
std::string get_source_code(CompilationUnitRef unit, clang::SourceRange range) {
196196
clang::LangOptions lo;
197197
auto& sm = unit.context().getSourceManager();
198198
auto start_loc = sm.getSpellingLoc(range.getBegin());
@@ -204,7 +204,7 @@ static std::string get_source_code(CompilationUnitRef unit, clang::SourceRange r
204204
lo)};
205205
}
206206

207-
static clang::TemplateTypeParmTypeLoc getContainedAutoParamType(clang::TypeLoc TL) {
207+
clang::TemplateTypeParmTypeLoc getContainedAutoParamType(clang::TypeLoc TL) {
208208
if(auto QTL = TL.getAs<clang::QualifiedTypeLoc>())
209209
return getContainedAutoParamType(QTL.getUnqualifiedLoc());
210210
if(llvm::isa<clang::PointerType, clang::ReferenceType, clang::ParenType>(TL.getTypePtr()))
@@ -219,7 +219,7 @@ static clang::TemplateTypeParmTypeLoc getContainedAutoParamType(clang::TypeLoc T
219219
}
220220

221221
template <typename TemplateDeclTy>
222-
static clang::NamedDecl* getOnlyInstantiationImpl(TemplateDeclTy* TD) {
222+
clang::NamedDecl* getOnlyInstantiationImpl(TemplateDeclTy* TD) {
223223
clang::NamedDecl* Only = nullptr;
224224
for(auto* Spec: TD->specializations()) {
225225
if(Spec->getTemplateSpecializationKind() == clang::TSK_ExplicitSpecialization)
@@ -231,7 +231,7 @@ static clang::NamedDecl* getOnlyInstantiationImpl(TemplateDeclTy* TD) {
231231
return Only;
232232
}
233233

234-
static clang::NamedDecl* getOnlyInstantiation(clang::NamedDecl* TemplatedDecl) {
234+
clang::NamedDecl* getOnlyInstantiation(clang::NamedDecl* TemplatedDecl) {
235235
if(clang::TemplateDecl* TD = TemplatedDecl->getDescribedTemplate()) {
236236
if(auto* CTD = llvm::dyn_cast<clang::ClassTemplateDecl>(TD))
237237
return getOnlyInstantiationImpl(CTD);
@@ -392,9 +392,9 @@ class DeducedTypeVisitor : public clang::RecursiveASTVisitor<DeducedTypeVisitor>
392392
};
393393

394394
// FIXME: Do as clangd a more simple way?
395-
static std::optional<clang::QualType> getDeducedType(clang::ASTContext& ASTCtx,
396-
const clang::HeuristicResolver* Resolver,
397-
clang::SourceLocation Loc) {
395+
std::optional<clang::QualType> getDeducedType(clang::ASTContext& ASTCtx,
396+
const clang::HeuristicResolver* Resolver,
397+
clang::SourceLocation Loc) {
398398
if(!Loc.isValid()) {
399399
return {};
400400
}
@@ -406,9 +406,9 @@ static std::optional<clang::QualType> getDeducedType(clang::ASTContext& ASTCtx,
406406
return V.DeducedType;
407407
}
408408

409-
static std::string get_source_code(const clang::Decl* decl,
410-
clang::PrintingPolicy pp,
411-
const clang::syntax::TokenBuffer& tb) {
409+
std::string get_source_code(const clang::Decl* decl,
410+
clang::PrintingPolicy pp,
411+
const clang::syntax::TokenBuffer& tb) {
412412
if(auto* vd = llvm::dyn_cast<clang::VarDecl>(decl)) {
413413
if(auto* ie = vd->getInit()) {
414414
// Initializers might be huge and result in lots of memory allocations in
@@ -425,9 +425,9 @@ static std::string get_source_code(const clang::Decl* decl,
425425
return def;
426426
}
427427

428-
static std::optional<Hover> hover(CompilationUnitRef unit,
429-
const clang::NamedDecl* decl,
430-
const config::HoverOptions& opt) {
428+
std::optional<Hover> hover(CompilationUnitRef unit,
429+
const clang::NamedDecl* decl,
430+
const config::HoverOptions& opt) {
431431
auto pp = proxy_print_policy(unit.context().getPrintingPolicy());
432432
return Hover{
433433
.kind = SymbolKind::from(decl),
@@ -439,19 +439,19 @@ static std::optional<Hover> hover(CompilationUnitRef unit,
439439
};
440440
}
441441

442-
static std::optional<Hover> hover(CompilationUnitRef unit,
443-
const clang::QualType& ty,
444-
const config::HoverOptions& opt) {
442+
std::optional<Hover> hover(CompilationUnitRef unit,
443+
const clang::QualType& ty,
444+
const config::HoverOptions& opt) {
445445
// TODO: Hover for type
446446
// TODO: Add source code
447447
auto& ctx = unit.context();
448448
auto pp = proxy_print_policy(ctx.getPrintingPolicy());
449449
return Hover{.kind = SymbolKind::Type, .name = print_type(ctx, ty, pp, opt)};
450450
}
451451

452-
static std::optional<Hover> hover(CompilationUnitRef unit,
453-
const SelectionTree::Node* node,
454-
const config::HoverOptions& opt) {
452+
std::optional<Hover> hover(CompilationUnitRef unit,
453+
const SelectionTree::Node* node,
454+
const config::HoverOptions& opt) {
455455
using namespace clang;
456456

457457
#define kind_flag_def(Ty) static constexpr auto Flag##Ty = ASTNodeKind::getFromNodeKind<Ty>()
@@ -477,7 +477,6 @@ static std::optional<Hover> hover(CompilationUnitRef unit,
477477

478478
#define is_in_range(LHS, RHS) (!((Kind < Flag##LHS) && is(LHS)) && (Kind < Flag##RHS))
479479

480-
auto wanted_node = node;
481480
auto Kind = node->data.getNodeKind();
482481

483482
// auto and decltype is specially processed
@@ -486,13 +485,13 @@ static std::optional<Hover> hover(CompilationUnitRef unit,
486485
if(auto ty = getDeducedType(unit.context(), &resolver, node->source_range().getBegin())) {
487486
return hover(unit, *ty, opt);
488487
} else {
489-
LOG_WARN("Cannot get deduced type");
488+
LOG_DEBUG("Cannot get deduced type");
490489
}
491490
}
492491

493492
if(is(NestedNameSpecifierLoc)) {
494493
if(auto ns_specifier_loc = node->get<NestedNameSpecifierLoc>()) {
495-
LOG_WARN("Hit a `NestedNameSpecifierLoc`");
494+
LOG_DEBUG("Hit a `NestedNameSpecifierLoc`");
496495
if(auto ns_specifier = ns_specifier_loc->getNestedNameSpecifier()) {
497496
auto ns = ns_specifier->getAsNamespace();
498497
assert(ns);
@@ -504,36 +503,36 @@ static std::optional<Hover> hover(CompilationUnitRef unit,
504503
}
505504
return Hover{.kind = SymbolKind::Namespace, .name = name};
506505
} else {
507-
LOG_WARN("Cannot get namespace");
506+
LOG_DEBUG("Cannot get namespace");
508507
}
509508
}
510509
} else if(is_in_range(QualType, TypeLoc)) {
511510
// Typeloc
512-
LOG_WARN("Hit a `TypeLoc`");
511+
LOG_DEBUG("Hit a `TypeLoc`");
513512
if(auto typeloc = node->get<TypeLoc>()) {
514513
return hover(unit, typeloc->getType(), opt);
515514
}
516515
} else if(is_in_range(Decl, Stmt)) {
517516
// Decl
518-
LOG_WARN("Hit a `Decl`");
517+
LOG_DEBUG("Hit a `Decl`");
519518
if(auto decl = node->get<clang::NamedDecl>()) {
520519
return hover(unit, decl, opt);
521520
} else {
522-
LOG_WARN("Not intersted");
521+
LOG_DEBUG("Not intersted");
523522
}
524523
} else if(is(DeclRefExpr)) {
525-
LOG_WARN("Hit an `DeclRef`, Unhandled");
524+
LOG_DEBUG("Hit an `DeclRef`, Unhandled");
526525
if(auto dr = node->get<DeclRefExpr>()) {
527526
auto vd = dr->getDecl();
528527
assert(vd);
529528
return hover(unit, llvm::dyn_cast<NamedDecl>(vd), opt);
530529
}
531530
} else if(is_in_range(Attr, ObjCProtocolLoc)) {
532-
LOG_WARN("Hit an `Attr`, Unhandled");
531+
LOG_DEBUG("Hit an `Attr`, Unhandled");
533532
// TODO: Attr?
534533
} else {
535534
// Not interested
536-
LOG_WARN("Not interested");
535+
LOG_DEBUG("Not interested");
537536
}
538537

539538
#undef is
@@ -571,6 +570,10 @@ const char* get_guessed_lang_name(CompilationUnitRef unit) {
571570
return "c";
572571
}
573572

573+
std::optional<std::string> get_provider() {
574+
return std::nullopt;
575+
}
576+
574577
} // namespace
575578

576579
std::optional<Hover> hover(CompilationUnitRef unit,
@@ -622,7 +625,7 @@ std::optional<Hover> hover(CompilationUnitRef unit,
622625

623626
auto tokens_under_cursor = unit.spelled_tokens_touch(*loc);
624627
if(tokens_under_cursor.empty()) {
625-
LOG_WARN("Cannot detect tokens");
628+
LOG_DEBUG("Cannot detect tokens");
626629
return std::nullopt;
627630
}
628631
auto hl_range = tokens_under_cursor.back().range(sm).toCharRange(sm).getAsRange();
@@ -666,15 +669,15 @@ std::optional<Hover> hover(CompilationUnitRef unit,
666669

667670
auto tree = SelectionTree::create_right(unit, {offset, offset});
668671
if(auto node = tree.common_ancestor()) {
669-
LOG_WARN("Got node: {}", node->kind());
672+
LOG_DEBUG("Got node: {}", node->kind());
670673
if(auto info = hover(unit, node, opt)) {
671674
info->lang = lang_name;
672675
info->hl_range = to_proto_range(sm, hl_range);
673676
return info;
674677
}
675678
return std::nullopt;
676679
} else {
677-
LOG_WARN("Not an ast node");
680+
LOG_DEBUG("Not an ast node");
678681
}
679682

680683
return std::nullopt;

0 commit comments

Comments
 (0)