-
Notifications
You must be signed in to change notification settings - Fork 59
Feat: Hover #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat: Hover #225
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @aurora0x27, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly refactors and enhances the hover functionality within the codebase. The changes aim to make the hover feature more robust, flexible, and capable of providing more comprehensive information by introducing optional return types, configurable options, and improved handling of various Abstract Syntax Tree (AST) node types, particularly TypeLocs.
Highlights
- Hover Function Signature Update: The primary
hoverfunction ininclude/Feature/Hover.handsrc/Feature/Hover.cpphas been updated to returnstd::optional<Hover>instead ofHover, indicating that hover information might not always be available. It also now accepts aconfig::HoverOptionsparameter for more configurable behavior. - Improved Hover Information Retrieval: Internal helper functions like
getHoverItems,getDocument,getQualifier, andgetSourceCodehave been refactored (e.g.,getHoverItemsrenamed toget_hover_itemsand now acceptsconfig::HoverOptions). New overloads forhoverandget_hover_itemshave been added to specifically handleclang::TypeLocnodes, expanding the types of symbols for which hover information can be generated. - Integration of Hover Options: The
src/Server/Feature.cppfile now initializes and passesconfig::HoverOptionsto thefeature::hovercall, enabling features like Doxygen parsing, Markdown comment parsing, and showing 'aka' information for hover results. - Enhanced AST Traversal and Logging: The
hoverimplementation insrc/Feature/Hover.cppnow includes more robust AST traversal logic, usingsrc_loc_in_main_fileandspelled_tokens_touchfor better token identification. Debugging logs (clice::log::warn,clice::log::info) have been added to aid in development and understanding of the hover logic.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the hover feature, introducing std::optional for the return type and config::HoverOptions for configurability. The changes are a good step forward, but there are a few issues to address. Most critically, there's a potential crash in src/Server/Feature.cpp due to dereferencing an optional without checking if it has a value. I've also pointed out some leftover debugging code and unused parameters that should be cleaned up before merging. Overall, good progress on this feature.
src/Server/Feature.cpp
Outdated
| auto hover = feature::hover(*ast, offset, opt); | ||
| // TODO: Join comment with ast info, build structed text | ||
| proto::Hover result; | ||
| result.contents.kind = "markdown"; | ||
| result.contents.value = std::format("{}: {}", hover.kind.name(), hover.name); | ||
| result.contents.value = std::format("{}: {}", hover->kind.name(), hover->name); | ||
| return json::serialize(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function feature::hover now returns a std::optional<Hover>. However, the returned optional is dereferenced on line 70 (hover->kind.name()) without first checking if it contains a value. If feature::hover returns std::nullopt, this will cause a crash. You should check if hover has a value before accessing it.
auto hover = feature::hover(*ast, offset, opt);
if (!hover) {
return json::Value(nullptr);
}
// TODO: Join comment with ast info, build structed text
proto::Hover result;
result.contents.kind = "markdown";
result.contents.value = std::format("{}: {}", hover->kind.name(), hover->name);
return json::serialize(result);
include/Feature/Hover.h
Outdated
| // /// Generate the hover information for the given declaration(for test). | ||
| // Hover hover(CompilationUnit& unit, const clang::NamedDecl* decl, const config::HoverOptions& opt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Feature/Hover.cpp
Outdated
| std::string getDocument(CompilationUnit& unit, | ||
| const clang::NamedDecl* decl, | ||
| config::HoverOptions opt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opt parameter of type config::HoverOptions has been added to this function but is not being used within the function body. This also applies to getQualifier and getSourceCode. Unused parameters can be misleading. Please either use this parameter to configure the function's behavior or remove it if it's not needed.
src/Feature/Hover.cpp
Outdated
| for(auto& tk: tokens_under_cursor) { | ||
| clice::log::info("Hit token '{}'", tk.str()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Feature/Hover.cpp
Outdated
|
|
||
| clice::log::warn("Not selected"); | ||
|
|
||
| node->data.dump(llvm::errs(), unit.context()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3b966a5 to
635cf85
Compare
|
Any update? |
Handling typeloc and template params. |
78d65fe to
c518757
Compare
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughHover was refactored to be configuration-driven: hover() now accepts Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server as on_hover()
participant HoverSvc as hover(offset, opt)
participant Tree as SelectionTree
participant Decl as NamedDecl/TypeLoc
participant Builder as Hover Builder
participant Display as Hover::display(opt)
Client->>Server: hover request (uri, offset)
Server->>HoverSvc: hover(unit, offset, HoverOptions)
HoverSvc->>Tree: find node at offset
alt directive/macro
HoverSvc->>Builder: build macro/directive hover + hl_range
else decl/type/node
Tree-->>HoverSvc: node
HoverSvc->>Decl: resolve NamedDecl/TypeLoc or deduce type
HoverSvc->>Builder: collect items, document, qualifier, source
end
Builder-->>HoverSvc: Hover (with optional hl_range and document)
HoverSvc-->>Server: std::optional<Hover>
alt Hover present
Server->>Display: hover->display(HoverOptions)
Display-->>Server: formatted markdown
Server->>Client: response (content + range)
else no hover
Server->>Client: fallback "Cannot get hover info"
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
include/Feature/Hover.h (1)
1-6: Header uses STL types without including their headers. Add required includes (and forward-declare CompilationUnit).Public headers must be self-sufficient. Please include the STL headers you use and forward-declare CompilationUnit (or include its header).
Apply this diff near the top:
#pragma once -#include "AST/SymbolKind.h" -#include "AST/SourceCode.h" -#include "Index/Shared.h" +#include "AST/SymbolKind.h" +#include "Index/Shared.h" +#include <cstdint> +#include <optional> +#include <string> +#include <vector> + +namespace clice { +class CompilationUnit; +} // namespace cliceOptional: drop the unused include to reduce dependencies as shown above.
src/Feature/Hover.cpp (1)
15-35: Use wide types and consistent units for hover metrics (bytes vs bits).
- getFieldOffset returns bits; your comment suggests “Offset” (commonly bytes). Convert to bytes.
- Char/align sizes use CharUnits->getQuantity (signed 64). Avoid truncation to uint32_t.
- auto addItem = [&items](HoverItem::HoverKind kind, uint32_t value) { - items.emplace_back(kind, llvm::Twine(value).str()); - }; + auto addItem = [&items](HoverItem::HoverKind kind, uint64_t value) { + items.emplace_back(kind, llvm::Twine(value).str()); + }; @@ - addItem(HoverItem::FieldIndex, FD->getFieldIndex()); - addItem(HoverItem::Offset, Ctx.getFieldOffset(FD)); - addItem(HoverItem::Size, Ctx.getTypeSizeInChars(FD->getType()).getQuantity()); - addItem(HoverItem::Align, Ctx.getTypeAlignInChars(FD->getType()).getQuantity()); + addItem(HoverItem::FieldIndex, static_cast<uint64_t>(FD->getFieldIndex())); + // Convert bits -> bytes for user-facing offset. + addItem(HoverItem::Offset, + static_cast<uint64_t>(Ctx.getFieldOffset(FD)) / + static_cast<uint64_t>(Ctx.getCharWidth())); + addItem(HoverItem::Size, + static_cast<uint64_t>(Ctx.getTypeSizeInChars(FD->getType()).getQuantity())); + addItem(HoverItem::Align, + static_cast<uint64_t>(Ctx.getTypeAlignInChars(FD->getType()).getQuantity()));Also clarify units in HoverItem comments if keeping bits anywhere.
♻️ Duplicate comments (4)
include/Feature/Hover.h (1)
68-70: Remove commented-out API or add TODO with rationale.Dead commented code increases noise; delete it or replace with a clear TODO and target owner.
-// /// Generate the hover information for the given declaration(for test). -// Hover hover(CompilationUnit& unit, const clang::NamedDecl* decl, const config::HoverOptions& -// opt);src/Feature/Hover.cpp (2)
115-118: Reduce noisy token logging to debug or remove in release builds.
This was previously flagged; switch to debug or guard with a compile-time flag.- for(auto& tk: tokens_under_cursor) { - clice::logging::info("Hit token '{}'", tk.str()); - } + for(auto& tk: tokens_under_cursor) { + clice::logging::debug("Hit token '{}'", tk.str()); + }
138-138: Remove raw AST dump to stderr or guard it behind debug.
Keeps logs clean in production.- node->data.dump(llvm::errs(), unit.context()); + // node->data.dump(llvm::errs(), unit.context()); // debug onlysrc/Server/Feature.cpp (1)
65-71: Check optional before use and capture by value to avoid lifetime hazards.
- The optional is dereferenced without a has_value() check. Return null when no hover exists.
- Avoid capturing stack locals by reference in async work; capture by value (both opt and ast pointer are small).
- co_return co_await async::submit([kind = this->kind, offset, &ast, &opt] { - auto hover = feature::hover(*ast, offset, opt); - // TODO: Join comment with ast info, build structed text - proto::Hover result; - result.contents.kind = "markdown"; - result.contents.value = std::format("{}: {}", hover->kind.name(), hover->name); - return json::serialize(result); - }); + co_return co_await async::submit([kind = this->kind, offset, ast = ast, opt = opt] { + auto hover = feature::hover(*ast, offset, opt); + if(!hover) { + return json::Value(nullptr); + } + // TODO: Join comment with AST info; build structured text + proto::Hover result; + result.contents.kind = "markdown"; + result.contents.value = std::format("{}: {}", hover->kind.name(), hover->name); + return json::serialize(result); + });
🧹 Nitpick comments (4)
include/Feature/Hover.h (1)
72-75: Public API looks good; consider documenting nullopt cases and option semantics.Briefly document when nullopt is returned and how HoverOptions affects output for LSP clients.
src/Server/Feature.cpp (1)
60-64: Initialize HoverOptions from configuration once, not per request.The in-function NOTE is correct. Plumb user/server settings and store defaults on Server; read here without reconstructing each call.
src/Feature/Hover.cpp (2)
46-76: Unify HoverOptions passing and silence unused warnings.These helpers accept HoverOptions by value, unlike others by const-ref; also currently unused. Take by const-ref and mark maybe_unused to avoid warnings until options are applied.
-std::string getDocument(CompilationUnit& unit, - const clang::NamedDecl* decl, - config::HoverOptions opt) { +std::string getDocument(CompilationUnit& unit, + const clang::NamedDecl* decl, + [[maybe_unused]] const config::HoverOptions& opt) { @@ -std::string getQualifier(CompilationUnit& unit, - const clang::NamedDecl* decl, - config::HoverOptions opt) { +std::string getQualifier(CompilationUnit& unit, + const clang::NamedDecl* decl, + [[maybe_unused]] const config::HoverOptions& opt) { @@ -std::string getSourceCode(CompilationUnit& unit, - const clang::NamedDecl* decl, - config::HoverOptions opt) { +std::string getSourceCode(CompilationUnit& unit, + const clang::NamedDecl* decl, + [[maybe_unused]] const config::HoverOptions& opt) {Later, wire options into formatting/parsing behaviors.
98-104: TypeLoc path returns nullopt; consider minimal fallback content.Even a simple spelling of the type under cursor would improve UX until full support is added.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
include/Feature/Hover.h(1 hunks)src/Feature/Hover.cpp(3 hunks)src/Server/Feature.cpp(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
include/Feature/Hover.h (2)
src/Feature/Hover.cpp (6)
hover(85-96)hover(85-87)hover(98-104)hover(98-100)hover(106-154)hover(106-108)include/Compiler/CompilationUnit.h (1)
CompilationUnit(15-204)
src/Feature/Hover.cpp (2)
src/AST/Selection.cpp (12)
unit(718-727)unit(718-721)range(407-437)range(407-407)offset(592-606)offset(592-592)offset(1131-1136)offset(1131-1131)create_right(1233-1240)create_right(1233-1233)node(978-990)node(978-978)src/AST/Utility.cpp (2)
name_of(193-253)name_of(193-193)
src/Server/Feature.cpp (1)
src/Feature/Hover.cpp (6)
hover(85-96)hover(85-87)hover(98-104)hover(98-100)hover(106-154)hover(106-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: macos (macos-15, debug)
- GitHub Check: macos (macos-15, release)
- GitHub Check: windows (windows-2025)
- GitHub Check: linux (ubuntu-24.04, debug)
- GitHub Check: linux (ubuntu-24.04, release)
- GitHub Check: build (macos-15)
- GitHub Check: build (windows-2025)
- GitHub Check: build (ubuntu-24.04)
🔇 Additional comments (1)
src/Feature/Hover.cpp (1)
106-114: Return early on invalid loc is good; consider validating offset before building SelectionTree.After adding the bounds check in src_loc_in_main_file, this is largely covered. Optional: also verify offset <= content size here for defense-in-depth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
♻️ Duplicate comments (5)
src/Feature/Hover.cpp (3)
140-196: Consider reducing logging verbosity in node dispatch.This function logs every node kind it encounters (lines 145, 168, 171, 177, 181, 184, 188). While useful during development, this level of logging will be very noisy in production. Consider moving to debug level or removing once the hover dispatching logic is stable.
205-207: Validate offset bounds before constructing SourceLocation.The helper constructs a
SourceLocationfor any offset without checking if the offset is within the file bounds. Out-of-range offsets can produce invalid locations and cause downstream crashes.Apply this diff to add bounds checking:
auto src_loc_in_main_file = [&sm](uint32_t off) -> std::optional<clang::SourceLocation> { + auto fid = sm.getMainFileID(); + auto size = sm.getFileIDSize(fid); + if(off >= size) { + return std::nullopt; + } - return sm.getLocForStartOfFile(sm.getMainFileID()).getLocWithOffset(off); + return sm.getLocForStartOfFile(fid).getLocWithOffset(off); };
130-138: Remove debug AST dump to stderr.Line 135 dumps the TypeLoc AST to stderr on every type hover. This is useful for development but should be removed before merging, as it clutters stderr and exposes internal AST details.
static std::optional<Hover> hover(CompilationUnit& unit, const clang::TypeLoc* typeloc, const config::HoverOptions& opt) { // TODO: Hover for type clice::logging::warn("Hit a typeloc"); - typeloc->dump(llvm::errs(), unit.context()); auto ty = typeloc->getType(); return Hover{.kind = SymbolKind::Type, .name = ty.getAsString()}; }tests/unit/Feature/Hover.cpp (1)
173-187: The test scaffolding is incomplete (same issue as DeducedType_Auto).The
offsetsvector is empty, so the loop doesn't test anything. Populate it with the position markers fromannotation.offsetsbefore merging.include/Feature/Hover.h (1)
77-79: Remove the commented-out code.Commented-out code should be removed to keep the codebase clean. If this declaration is needed in the future, it can be retrieved from version control history.
Apply this diff:
-// /// Generate the hover information for the given declaration(for test). -// Hover hover(CompilationUnit& unit, const clang::NamedDecl* decl, const config::HoverOptions& -// opt); - /// Generate the hover information for the symbol at the given offset.
🧹 Nitpick comments (2)
src/Server/Feature.cpp (1)
60-63: Consider making HoverOptions configurable.The
HoverOptionsare hardcoded here. If hover behavior should be user-configurable (via LSP settings or workspace config), consider sourcing these options from a configuration manager rather than hardcoding them in the handler.src/Feature/Hover.cpp (1)
29-56: Consider reducing debug logging verbosity.Lines 30, 53-55 emit warnings on every field hover. These logs will be very noisy in production when users hover over struct members. Consider using
debuglevel or removing them once the feature stabilizes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
include/Feature/Hover.h(3 hunks)src/Feature/Hover.cpp(1 hunks)src/Server/Feature.cpp(1 hunks)tests/unit/Feature/Hover.cpp(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/Server/Feature.cpp (1)
src/Feature/Hover.cpp (8)
hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
tests/unit/Feature/Hover.cpp (1)
src/Feature/Hover.cpp (8)
hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
include/Feature/Hover.h (1)
src/Feature/Hover.cpp (12)
get_item_content(250-257)get_item_content(250-250)display(259-272)display(259-259)hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
src/Feature/Hover.cpp (1)
src/AST/Selection.cpp (11)
unit(718-727)unit(718-721)kind(1185-1190)kind(1185-1185)os(1154-1154)range(407-437)range(407-407)node(978-990)node(978-978)create_right(1233-1240)create_right(1233-1233)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: macos (macos-15, release)
- GitHub Check: macos (macos-15, debug)
- GitHub Check: linux (ubuntu-24.04, debug)
- GitHub Check: linux (ubuntu-24.04, release)
- GitHub Check: windows (windows-2025)
- GitHub Check: build (macos-15)
- GitHub Check: build (windows-2025)
- GitHub Check: build (ubuntu-24.04)
🔇 Additional comments (2)
src/Server/Feature.cpp (1)
68-78: Hover result handling looks correct.The code properly checks the optional hover result and the optional display result before using them, with appropriate fallback messages. This addresses the previous review concern about null dereference.
src/Feature/Hover.cpp (1)
259-272: The display formatting is basic but functional.The current implementation provides a straightforward text-based representation. This works for a WIP feature. If richer formatting is desired (collapsible sections, syntax highlighting hints, formatted tables), that can be deferred to a follow-up.
| static std::string get_document(CompilationUnit& unit, | ||
| const clang::NamedDecl* decl, | ||
| config::HoverOptions opt) { | ||
| clang::ASTContext& Ctx = unit.context(); | ||
| const clang::RawComment* comment = Ctx.getRawCommentForAnyRedecl(decl); | ||
| if(!comment) { | ||
| return ""; | ||
| } | ||
|
|
||
| return comment->getRawText(Ctx.getSourceManager()).str(); | ||
| auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); | ||
| return ""; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the logic bug in get_document.
Line 79 retrieves the raw comment text into raw_string, but line 80 immediately returns an empty string without using it. This means hover will never show documentation even when comments are present.
If document parsing is not yet implemented, add a TODO and return the raw string for now:
static std::string get_document(CompilationUnit& unit,
const clang::NamedDecl* decl,
config::HoverOptions opt) {
clang::ASTContext& Ctx = unit.context();
const clang::RawComment* comment = Ctx.getRawCommentForAnyRedecl(decl);
if(!comment) {
return "";
}
auto raw_string = comment->getRawText(Ctx.getSourceManager()).str();
- return "";
+ // TODO: Parse comment according to opt.parse_comment_as_markdown
+ return raw_string;
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| static std::string get_document(CompilationUnit& unit, | |
| const clang::NamedDecl* decl, | |
| config::HoverOptions opt) { | |
| clang::ASTContext& Ctx = unit.context(); | |
| const clang::RawComment* comment = Ctx.getRawCommentForAnyRedecl(decl); | |
| if(!comment) { | |
| return ""; | |
| } | |
| return comment->getRawText(Ctx.getSourceManager()).str(); | |
| auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); | |
| return ""; | |
| } | |
| static std::string get_document(CompilationUnit& unit, | |
| const clang::NamedDecl* decl, | |
| config::HoverOptions opt) { | |
| clang::ASTContext& Ctx = unit.context(); | |
| const clang::RawComment* comment = Ctx.getRawCommentForAnyRedecl(decl); | |
| if(!comment) { | |
| return ""; | |
| } | |
| auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); | |
| // TODO: Parse comment according to opt.parse_comment_as_markdown | |
| return raw_string; | |
| } |
🤖 Prompt for AI Agents
In src/Feature/Hover.cpp around lines 71 to 81, get_document currently reads the
raw comment into raw_string but then returns an empty string, so documentation
is never shown; fix this by returning the raw_string (or if full parsing isn't
implemented, return raw_string with a TODO comment indicating future
parsing/formatting), ensuring you keep the existing retrieval logic and only
replace the final return "" with return of the raw_string.
| std::vector<unsigned> offsets; | ||
| tester.compile(); | ||
| expect(tester.unit.has_value()); | ||
| for(auto offset: offsets) { | ||
| auto HI = clice::feature::hover(*tester.unit, offset, {}); | ||
| if(HI.has_value()) { | ||
| auto msg = HI->display({}); | ||
| // std::println("{}", *msg); | ||
| } else { | ||
| // std::println("No hover info"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test scaffolding is incomplete.
The offsets vector is declared but never populated, so the loop at lines 101-109 iterates over an empty collection and doesn't exercise any hover functionality. Ensure you populate offsets from the annotation.offsets map (e.g., by extracting pos_0, pos_1, etc.) before merging this PR.
Apply this pattern to populate the offsets:
auto annotation = AnnotatedSource::from(code);
tester.add_main("main.cpp", annotation.content);
- std::vector<unsigned> offsets;
+ std::vector<unsigned> offsets = {
+ annotation.offsets["pos_0"],
+ annotation.offsets["pos_1"],
+ // ... add remaining positions
+ };
tester.compile();Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In tests/unit/Feature/Hover.cpp around lines 98 to 109, the offsets vector is
declared but never populated so the hover loop never runs; populate offsets from
the test annotation's offsets map before calling tester.compile(), e.g. extract
entries like "pos_0", "pos_1", ... (or iterate all annotation.offsets keys) and
push their integer values into the offsets vector so the for-loop exercises
hover at those positions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (10)
include/Feature/Hover.h (1)
77-79: Remove or document the commented-out function.As noted in a past review, commented-out code should be removed to improve clarity. If this function is intended for future use, replace the comment with a
// TODOexplaining the plan.src/Feature/Hover.cpp (6)
18-63: Theoptparameter is unused in this function.As noted in a past review, the
config::HoverOptions& optparameter is declared but not used withinget_hover_items. Either use it to configure behavior (e.g., controlling which items to include) or remove it if it's not needed yet.
83-90: Theoptparameter is unused.As noted in a past review, the
config::HoverOptions optparameter is not used inget_qualifier. Consider removing it or using it to configure output formatting.
71-81: The function retrieves the comment but returns an empty string.As flagged in a past review, line 79 retrieves
raw_stringbut line 80 returns an empty string, so documentation is never shown in hover results.Return the raw string until parsing is fully implemented:
auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); - return ""; + // TODO: Parse comment according to opt.parse_comment_as_markdown + return raw_string;
130-138: Remove the debug dump to stderr.As flagged in a past review, line 135 dumps the AST node to
stderr. This debug output should be removed or conditionally compiled for production.- clice::logging::warn("Hit a typeloc"); - typeloc->dump(llvm::errs(), unit.context()); auto ty = typeloc->getType();
140-196: Excessive debug logging should be removed or reduced.As noted in a past review, this function contains extensive
clice::logging::warncalls that will clutter production logs. Either remove them, replace with debug-level logging, or conditionally compile them.
205-207: Validate offset bounds to prevent crashes.As flagged in a past review, the lambda at lines 205-207 doesn't validate that
offis within the main file's size, which can lead to invalidSourceLocationobjects and downstream crashes.Add bounds checking:
auto src_loc_in_main_file = [&sm](uint32_t off) -> std::optional<clang::SourceLocation> { - return sm.getLocForStartOfFile(sm.getMainFileID()).getLocWithOffset(off); + auto fid = sm.getMainFileID(); + auto buf = sm.getBufferData(fid); + if(off > buf.size()) { + return std::nullopt; + } + return sm.getLocForStartOfFile(fid).getLocWithOffset(off); };tests/unit/Feature/Hover.cpp (3)
98-109: The offsets vector is never populated.As flagged in the previous review, the
offsetsvector is declared but never populated fromannotation.offsets, so the loop at lines 101-109 never runs and the test doesn't exercise hover functionality.Populate the offsets vector before the loop:
auto annotation = AnnotatedSource::from(code); tester.add_main("main.cpp", annotation.content); - std::vector<unsigned> offsets; + std::vector<unsigned> offsets; + for (const auto& [key, offset] : annotation.offsets) { + offsets.push_back(offset); + } tester.compile();
158-158: Fix the malformed token.Line 158 contains
decltyppos_13)ype(auto)which is syntactically incorrect. This should bedeclty$(pos_13)pe(auto)to match the annotation pattern used elsewhere.Apply this fix:
- decltyppos_13)ype(auto) r2 = get_ca(); // const int + declty$(pos_13)pe(auto) r2 = get_ca(); // const int
173-187: The offsets vector is never populated.Same issue as in "DeducedType_Auto": the
offsetsvector at line 173 is declared but never populated fromannotation.offsets, so the loop at lines 177-187 doesn't exercise any hover functionality.Populate the offsets vector:
auto annotation = AnnotatedSource::from(code); tester.add_main("main.cpp", annotation.content); - std::vector<unsigned> offsets; + std::vector<unsigned> offsets; + for (const auto& [key, offset] : annotation.offsets) { + offsets.push_back(offset); + } tester.compile();
🧹 Nitpick comments (3)
src/Server/Feature.cpp (2)
60-63: Consider externalizing the hover configuration.The
HoverOptionsinstance is hardcoded inline. If these settings are reused across multiple features or need to be user-configurable, consider moving them to a server-level configuration or a dedicated config file.
68-78: Improve fallback messages for production readiness.The fallback messages "Cannot display hover info" and "Cannot get hover info" are appropriate for debugging but may confuse end users. Consider returning a more informative message or silently returning null to let the client handle the absence of hover data gracefully.
For example:
- } else { - clice::logging::warn("Cannot display hover info"); - result.contents.value = "Cannot display hover info"; - } + } else { + clice::logging::warn("Cannot display hover info"); + return json::Value(nullptr); + } } else { clice::logging::warn("Cannot get hover info"); - result.contents.value = "Cannot get hover info"; + return json::Value(nullptr); }src/Feature/Hover.cpp (1)
110-115: Theoptparameter is unused.The
config::HoverOptions optparameter is not used in this overload ofget_source_code. Consider removing it or using it to control source code formatting.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
include/Feature/Hover.h(3 hunks)src/Feature/Hover.cpp(1 hunks)src/Server/Feature.cpp(1 hunks)tests/unit/Feature/Hover.cpp(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/Server/Feature.cpp (1)
src/Feature/Hover.cpp (8)
hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
tests/unit/Feature/Hover.cpp (1)
src/Feature/Hover.cpp (8)
hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
include/Feature/Hover.h (1)
src/Feature/Hover.cpp (12)
get_item_content(250-257)get_item_content(250-250)display(259-272)display(259-259)hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
src/Feature/Hover.cpp (2)
src/AST/Selection.cpp (15)
unit(718-727)unit(718-721)kind(1185-1190)kind(1185-1185)os(1154-1154)range(407-437)range(407-407)node(978-990)node(978-978)offset(592-606)offset(592-592)offset(1131-1136)offset(1131-1131)create_right(1233-1240)create_right(1233-1233)src/AST/Utility.cpp (3)
os(375-375)name_of(219-279)name_of(219-219)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: build (macos-15)
- GitHub Check: macos (macos-15, release)
- GitHub Check: macos (macos-15, debug)
- GitHub Check: linux (ubuntu-24.04, release)
- GitHub Check: linux (ubuntu-24.04, debug)
- GitHub Check: windows (windows-2025)
- GitHub Check: build (ubuntu-24.04)
- GitHub Check: build (windows-2025)
🔇 Additional comments (6)
src/Server/Feature.cpp (1)
68-78: LGTM: Optional checking correctly implemented.The code now properly checks both
hoverandhover->display(opt)before accessing their values, preventing the null-pointer dereference flagged in the past review.tests/unit/Feature/Hover.cpp (1)
35-55: LGTM: Inclusion test is complete.The "Inclusion" test properly extracts offsets from annotations and exercises the hover functionality for include directives.
include/Feature/Hover.h (3)
38-39: LGTM: Enum rename improves clarity.Renaming
EnumValuetoValuebroadens the semantic scope to cover variables, constants, and enum items, aligning with the updated comment.
68-74: LGTM: New methods support config-driven hover display.The added
hl_range,get_item_content, anddisplaymembers enable flexible hover content retrieval and formatting, integrating well with the updated hover API.
82-84: LGTM: Public API updated to return optional and accept config.The hover function signature now returns
std::optional<Hover>and acceptsconfig::HoverOptions, enabling guarded code paths and config-driven behavior.src/Feature/Hover.cpp (1)
250-272: LGTM: Hover display methods are well-structured.The
get_item_contentanddisplayimplementations provide clean accessors for hover data, enabling flexible presentation in the server layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (7)
tests/unit/Feature/Hover.cpp (3)
98-109: Test scaffolding still incomplete - offsets vector never populated.The
offsetsvector is declared at line 98 but never populated with values fromannotation.offsets. The loop at lines 101-109 iterates over an empty collection and doesn't exercise any hover functionality. This is the same issue flagged in the previous review.Populate the offsets vector before the loop:
auto annotation = AnnotatedSource::from(code); tester.add_main("main.cpp", annotation.content); - std::vector<unsigned> offsets; + std::vector<unsigned> offsets; + for(auto& [key, value] : annotation.offsets) { + offsets.push_back(value); + } tester.compile();
158-158: Fix malformed decltype syntax.Line 158 contains
decltyppos_13)ype(auto)which is malformed. This appears to be a typo mixing position marker annotation with thedecltypekeyword.Fix the syntax:
- decltyppos_13)ype(auto) r2 = get_ca(); // const int + decl$(pos_13)type(auto) r2 = get_ca(); // const int
173-187: Test scaffolding incomplete - offsets vector never populated.The
offsetsvector at line 173 is declared but never populated with values fromannotation.offsets. The loop at lines 177-187 iterates over an empty collection and doesn't test any hover functionality.Populate the offsets vector:
auto annotation = AnnotatedSource::from(code); tester.add_main("main.cpp", annotation.content); - std::vector<unsigned> offsets; + std::vector<unsigned> offsets; + for(auto& [key, value] : annotation.offsets) { + offsets.push_back(value); + } tester.compile();include/Feature/Hover.h (1)
77-79: Remove commented-out code.Rather than leaving the old function declaration commented out, please remove these lines entirely. If the signature needs to be referenced later, it will be available in version control history.
-// /// Generate the hover information for the given declaration(for test). -// Hover hover(CompilationUnit& unit, const clang::NamedDecl* decl, const config::HoverOptions& -// opt); -src/Feature/Hover.cpp (3)
71-81: Critical: Documentation is retrieved but never returned.Line 79 successfully retrieves
raw_stringfrom the raw comment, but line 80 immediately returns an empty string without using it. This means hover will never display documentation even when comments are present. This critical issue from the previous review remains unresolved.Return the raw string:
auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); - return ""; + // TODO: Parse comment according to opt.parse_comment_as_markdown + return raw_string;
130-138: Remove debug output before merging.Line 135 dumps AST node data directly to
stderrviatypeloc->dump(), and line 134 logs a warning. This debug instrumentation was flagged in the previous review and should be removed from the final implementation.static std::optional<Hover> hover(CompilationUnit& unit, const clang::TypeLoc* typeloc, const config::HoverOptions& opt) { // TODO: Hover for type - clice::logging::warn("Hit a typeloc"); - typeloc->dump(llvm::errs(), unit.context()); auto ty = typeloc->getType(); return Hover{.kind = SymbolKind::Type, .name = ty.getAsString()}; }
205-207: Critical: Validate offset bounds before constructing SourceLocation.The lambda
src_loc_in_main_fileat lines 205-207 constructs aSourceLocationfrom an arbitrary offset without validating that the offset is within the file's bounds. Out-of-range offsets can produce invalid locations and cause downstream crashes. This critical issue from the previous review remains unresolved.Add bounds checking:
auto src_loc_in_main_file = [&sm](uint32_t off) -> std::optional<clang::SourceLocation> { + auto fid = sm.getMainFileID(); + auto buf = sm.getBufferData(fid, /*Invalid=*/nullptr); + if(off > buf.size()) { + return std::nullopt; + } - return sm.getLocForStartOfFile(sm.getMainFileID()).getLocWithOffset(off); + return sm.getLocForStartOfFile(fid).getLocWithOffset(off); };Verify this pattern is correct for Clang's SourceManager API:
#!/bin/bash # Search for similar offset validation patterns in the codebase rg -nP -C3 'getBufferData|getBuffer.*size|FileIDSize' --type=cpp
🧹 Nitpick comments (3)
src/Feature/Hover.cpp (3)
18-63: Consider reducing logging verbosity in production.The function has several
logging::warncalls (lines 30, 53-55, 58) that appear to be for development/debugging. While acceptable during active development, consider moving these to debug-level logging or removing them before the feature is finalized.
140-196: Consider reducing logging verbosity.This function contains extensive
logging::warncalls at lines 145, 168, 171, 177, 181, 184, and 188. While useful during development, this level of logging may be excessive for production. Consider reducing to debug-level or removing most of these before finalization.
215-248: Include hover logic looks good; consider reducing logging.The logic for detecting and handling hover on include directives (lines 215-238) is well-structured. However, logging statements at lines 222 and 244 could be reduced or removed in the final version.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
include/Feature/Hover.h(3 hunks)src/Feature/Hover.cpp(1 hunks)src/Server/Feature.cpp(1 hunks)tests/unit/Feature/Hover.cpp(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
tests/unit/Feature/Hover.cpp (1)
src/Feature/Hover.cpp (8)
hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
src/Server/Feature.cpp (1)
src/Feature/Hover.cpp (8)
hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
include/Feature/Hover.h (1)
src/Feature/Hover.cpp (12)
get_item_content(250-257)get_item_content(250-250)display(259-272)display(259-259)hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
src/Feature/Hover.cpp (1)
src/AST/Selection.cpp (15)
unit(718-727)unit(718-721)kind(1185-1190)kind(1185-1185)os(1154-1154)range(407-437)range(407-407)node(978-990)node(978-978)offset(592-606)offset(592-592)offset(1131-1136)offset(1131-1131)create_right(1233-1240)create_right(1233-1233)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: build (macos-15)
- GitHub Check: build (ubuntu-24.04)
- GitHub Check: build (windows-2025)
- GitHub Check: macos (macos-15, release)
- GitHub Check: macos (macos-15, debug)
- GitHub Check: windows (windows-2025)
- GitHub Check: linux (ubuntu-24.04, release)
- GitHub Check: linux (ubuntu-24.04, debug)
🔇 Additional comments (5)
src/Server/Feature.cpp (1)
60-80: Previous critical issue resolved - proper optional handling implemented.The implementation now correctly checks both
hoverandhover->display(opt)before accessing their values, with appropriate fallback messages. This addresses the critical null-dereference concern from the previous review.The hardcoded
HoverOptionsat lines 61-63 could be extracted to a configuration class or constant for better maintainability, but this is acceptable for now.tests/unit/Feature/Hover.cpp (1)
35-55: Test exercises include hover functionality.The test successfully exercises hover on include directives at two different positions. While it doesn't yet assert specific outcomes, this is reasonable for work-in-progress testing to validate the basic code path.
include/Feature/Hover.h (2)
6-6: API enhancements look good.The additions are well-structured:
- Protocol/Basic.h include supports the new
hl_rangefield- Renamed enum value from
EnumValuetoValuewith clearer documentation- New
get_item_contentanddisplaymethods provide a clean API for hover content retrieval and formattingAlso applies to: 38-39, 68-74
82-84: Updated signature aligns with refactoring goals.The new signature returning
std::optional<Hover>and acceptingconfig::HoverOptionsproperly supports cases where hover information is unavailable and enables configurable hover behavior.src/Feature/Hover.cpp (1)
250-272: Helper methods are well-implemented.Both
get_item_contentanddisplaymethods provide clean, functional implementations:
get_item_contentefficiently searches for items by kinddisplayproduces well-structured, readable output with proper formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (5)
include/Feature/Hover.h (1)
77-79: Remove or document the commented code.This was previously flagged: commented-out code should either be removed for clarity or accompanied by a TODO comment explaining its future purpose.
tests/unit/Feature/Hover.cpp (2)
98-109: The offsets vector remains unpopulated.This issue was previously flagged: the
offsetsvector is declared but never populated, so the hover loop never runs. You need to extract positions fromannotation.offsets(e.g.,pos_0,pos_1, etc.) before the loop.
158-158: Fix the malformed token.This typo was previously flagged:
decltyppos_13)ypeshould be corrected to properdecltypesyntax with an appropriate position marker.src/Feature/Hover.cpp (2)
71-81: The get_document bug remains unfixed.This critical issue was previously flagged: line 79 retrieves
raw_stringfrom the comment, but line 80 immediately returns an empty string, so documentation is never shown in hover. At minimum, returnraw_stringinstead of"".
130-138: Remove the stderr dump.Line 135 dumps AST data directly to
stderr, which was previously flagged for removal. This debug artifact should not be in production code.
🧹 Nitpick comments (2)
src/Feature/Hover.cpp (2)
18-63: Consider using debug log level for routine operations.Lines 30, 53-55, and 58 use
warnlevel for normal hover item construction. Since these are routine operations (not warnings), consider usingdebuglevel to avoid cluttering production logs.
140-196: Consider reducing logging verbosity.This function contains numerous
warn-level logging statements (lines 145, 168, 171, 177, 181, 184, 188) that trace normal control flow. For production code, either remove these logs or change them todebuglevel to avoid cluttering logs.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
include/Feature/Hover.h(3 hunks)src/Feature/Hover.cpp(1 hunks)src/Server/Feature.cpp(1 hunks)tests/unit/Feature/Hover.cpp(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/Server/Feature.cpp (1)
src/Feature/Hover.cpp (8)
hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
tests/unit/Feature/Hover.cpp (1)
src/Feature/Hover.cpp (8)
hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
include/Feature/Hover.h (1)
src/Feature/Hover.cpp (12)
get_item_content(250-257)get_item_content(250-250)display(259-272)display(259-259)hover(117-128)hover(117-119)hover(130-138)hover(130-132)hover(140-196)hover(140-142)hover(200-248)hover(200-202)
src/Feature/Hover.cpp (3)
src/AST/Selection.cpp (15)
unit(718-727)unit(718-721)kind(1185-1190)kind(1185-1185)os(1154-1154)range(407-437)range(407-407)node(978-990)node(978-978)offset(592-606)offset(592-592)offset(1131-1136)offset(1131-1131)create_right(1233-1240)create_right(1233-1233)include/AST/SourceCode.h (2)
range(70-94)clang(24-38)src/Compiler/Directive.cpp (16)
loc(25-35)loc(25-28)loc(37-47)loc(37-40)loc(145-166)loc(145-146)loc(168-172)loc(168-170)loc(174-179)loc(174-177)loc(181-185)loc(181-183)loc(188-192)loc(188-190)loc(195-200)loc(195-197)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: macos (macos-15, release)
- GitHub Check: windows (windows-2025)
- GitHub Check: macos (macos-15, debug)
- GitHub Check: build (macos-15)
- GitHub Check: linux (ubuntu-24.04, debug)
- GitHub Check: build (windows-2025)
- GitHub Check: build (ubuntu-24.04)
- GitHub Check: linux (ubuntu-24.04, release)
🔇 Additional comments (2)
tests/unit/Feature/Hover.cpp (1)
35-55: The Inclusion test structure looks good.The test correctly extracts offsets from annotations and exercises the hover feature for include directives. The unused
HIvariable is acceptable for work-in-progress testing.src/Server/Feature.cpp (1)
60-80: LGTM! Proper null checks and error handling.The hover implementation now correctly checks both the hover result and display result before dereferencing, with appropriate fallback messages. This addresses the previous review concern about missing null checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (4)
include/Feature/Hover.h (1)
77-79: Remove the stale commented-out declaration.
Line 78 still carries the commentedhoverdeclaration. Either delete it or replace it with a documented TODO so it doesn’t linger as dead code.src/Feature/Hover.cpp (3)
146-148: Drop thetypeloc->dumpdebug print.
Line 147 dumps AST data tostderrduring normal hover handling; this floods logs in production. Remove the dump (or gate it behind a debug knob).- clice::logging::warn("Hit a typeloc"); - typeloc->dump(llvm::errs(), unit.context()); + clice::logging::debug("Hit a TypeLoc");
262-264: Null-checkgetFileEntryForID.
Line 263 dereferencessm.getFileEntryForID(inclusion.fid)without verifying it’s non-null; missing entries will crash the server.- auto dir = sm.getFileEntryForID(inclusion.fid)->tryGetRealPathName(); - hi.source = dir; + if(auto file_entry = sm.getFileEntryForID(inclusion.fid)) { + hi.source = file_entry->tryGetRealPathName(); + }
83-93: Returnstd::optionalfromget_document.
Lines 85-92 always return an empty string, soHover::documentbecomes engaged even when no comment exists, producing empty “Document” blocks. change the helper to surfacestd::nulloptunless a non-empty comment is available.-static std::string get_document(CompilationUnit& unit, - const clang::NamedDecl* decl, - config::HoverOptions opt) { +static std::optional<std::string> get_document(CompilationUnit& unit, + const clang::NamedDecl* decl, + config::HoverOptions opt) { clang::ASTContext& Ctx = unit.context(); const clang::RawComment* comment = Ctx.getRawCommentForAnyRedecl(decl); - if(!comment) { - return ""; - } - auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); - return ""; + if(!comment) { + return std::nullopt; + } + auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); + if(raw_string.empty()) { + return std::nullopt; + } + // TODO: respect opt.parse_comment_as_markdown when formatting + return raw_string; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
include/Feature/Hover.h(3 hunks)include/Protocol/Feature/Hover.h(1 hunks)src/Feature/Hover.cpp(1 hunks)src/Server/Feature.cpp(1 hunks)src/Server/Lifecycle.cpp(1 hunks)tests/unit/Feature/Hover.cpp(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- tests/unit/Feature/Hover.cpp
- src/Server/Feature.cpp
🧰 Additional context used
🧬 Code graph analysis (2)
include/Feature/Hover.h (1)
src/Feature/Hover.cpp (12)
get_item_content(329-336)get_item_content(329-329)display(338-356)display(338-338)hover(129-140)hover(129-131)hover(142-151)hover(142-144)hover(153-220)hover(153-155)hover(224-327)hover(224-226)
src/Feature/Hover.cpp (3)
include/AST/SourceCode.h (2)
range(70-94)clang(24-38)src/AST/Selection.cpp (18)
range(407-437)range(407-407)begin(565-589)begin(565-565)unit(718-727)unit(718-721)kind(1185-1190)kind(1185-1185)node(978-990)node(978-978)offset(592-606)offset(592-592)offset(1131-1136)offset(1131-1131)fid(513-562)fid(513-514)create_right(1233-1240)create_right(1233-1233)src/AST/Utility.cpp (2)
name_of(219-279)name_of(219-219)
| auto add_item = [&items](HoverItem::HoverKind kind, std::string&& val) { | ||
| items.emplace_back(kind, val); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix add_item construction.
Line 37 calls items.emplace_back(kind, val), but HoverItem has no (HoverKind, std::string) constructor, so this will not compile. Build the aggregate explicitly and move the value.
- auto add_item = [&items](HoverItem::HoverKind kind, std::string&& val) {
- items.emplace_back(kind, val);
+ auto add_item = [&items](HoverItem::HoverKind kind, std::string&& val) {
+ items.emplace_back(HoverItem{kind, std::move(val)});
};🤖 Prompt for AI Agents
In src/Feature/Hover.cpp around lines 36 to 38, the lambda calls
items.emplace_back(kind, val) but HoverItem has no constructor taking
(HoverKind, std::string), so replace the emplace call with construction of the
aggregate and moving the string into it (e.g., create a HoverItem aggregate from
kind and std::move(val) and emplace/push that into items); ensure you move val
to avoid copy.
src/Server/Lifecycle.cpp
Outdated
| /// /// Load compile commands.json | ||
| /// database.load_compile_database(config.project.compile_commands_dirs, workspace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Commenting out compile commands loading will break critical LSP features.
Disabling the loading of compile_commands.json removes essential compilation information (include paths, compiler flags, defines) that the language server needs to provide accurate hover information, completions, diagnostics, and other features. This is particularly concerning for a PR focused on refactoring the Hover feature.
Is this change intentional? If this is temporary for debugging or part of an incomplete refactoring, please clarify the plan to restore this functionality before merging.
Run the following script to verify if other parts of the codebase depend on the compilation database being loaded:
🏁 Script executed:
#!/bin/bash
# Description: Check for usages of the database object that may depend on compile commands being loaded
# Search for database usage in the codebase
rg -n -C3 'database\.' --type cpp
# Search for compile_commands references
rg -n -C3 'compile_commands' --type cppLength of output: 16964
---
🏁 Script executed:
```shell
#!/bin/bash
# Search for all calls to load_compile_database to verify if there are alternative initialization paths
rg -n 'load_compile_database' --type cpp --type h
Length of output: 357
---
🏁 Script executed:
```shell
#!/bin/bash
# Check the lookup() implementation to see if it has fallback behavior when database is empty
rg -n -A10 'auto.*lookup.*CommandOptions' include/Compiler/Command.h
Length of output: 224
---
🏁 Script executed:
```shell
#!/bin/bash
# Check the lookup() implementation to understand behavior when database is empty
rg -n -A20 'CompilationDatabase::lookup' src/Compiler/Command.cpp
Length of output: 939
---
🏁 Script executed:
```shell
#!/bin/bash
# Check the guess_or_fallback implementation to understand the impact of the fallback path
rg -n -A15 'guess_or_fallback' src/Compiler/Command.cpp
Length of output: 1733
Commenting out load_compile_database() disables project-specific compilation information.
The call to database.load_compile_database() at line 35 is the only place in the codebase where the compilation database is initialized. Commenting it out causes all downstream database.lookup() calls to fall back to a weak heuristic: guessing commands from neighboring files in the same directory (up to 3 levels). This loses critical compilation context (include paths, compiler flags, defines) needed for hover, completions, diagnostics, and indexing.
Is this intentional? If temporary for debugging or part of an incomplete refactoring, this must be restored before merging.
🤖 Prompt for AI Agents
In src/Server/Lifecycle.cpp around lines 34-35, the call to
database.load_compile_database(config.project.compile_commands_dirs, workspace)
has been commented out which disables loading the project-specific compilation
database and forces fallback heuristics; restore this line (uncomment it) so the
compilation database is initialized with config.project.compile_commands_dirs
and workspace, ensure those variables are in scope and valid, and add basic
error handling/logging if load_compile_database can fail so the server can
report failures rather than silently using weak heuristics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (4)
src/Server/Lifecycle.cpp (1)
38-39: The compile_commands.json loading remains disabled.This change was flagged in previous reviews as critical. Commenting out the compilation database loading removes essential compiler context (include paths, flags, defines) needed for accurate hover information and other LSP features. Since this PR is marked "In process," ensure this line is restored before merging.
src/Feature/Hover.cpp (3)
36-38: The add_item lambda has a potential compilation issue.The lambda calls
items.emplace_back(kind, val), butHoverItemis an aggregate with no constructor taking(HoverKind, std::string). This was flagged in a previous review.Apply this fix:
auto add_item = [&items](HoverItem::HoverKind kind, std::string&& val) { - items.emplace_back(kind, val); + items.emplace_back(HoverItem{kind, std::move(val)}); };
83-93: The get_document function returns an empty string instead of the comment text.Line 91 retrieves the raw comment but line 92 immediately returns an empty string, so documentation is never displayed. This was flagged in a previous review.
Apply this fix:
static std::string get_document(CompilationUnit& unit, const clang::NamedDecl* decl, config::HoverOptions opt) { clang::ASTContext& Ctx = unit.context(); const clang::RawComment* comment = Ctx.getRawCommentForAnyRedecl(decl); if(!comment) { return ""; } auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); - return ""; + // TODO: Parse comment according to opt.parse_comment_as_markdown + return raw_string; }
253-267: Missing null check before dereferencing FileEntry.Line 262 calls
sm.getFileEntryForID(inclusion.fid)->tryGetRealPathName()without checking ifgetFileEntryForIDreturns nullptr. This was flagged in a previous review.Apply this defensive check:
auto raw_name = get_source_code(unit, inclusion.filename_range); auto file_name = llvm::StringRef{raw_name}.trim("<>\""); Hover hi; hi.kind = SymbolKind::Directive; hi.name = file_name; - auto dir = sm.getFileEntryForID(inclusion.fid)->tryGetRealPathName(); - hi.source = dir; + if(auto file_entry = sm.getFileEntryForID(inclusion.fid)) { + hi.source = file_entry->tryGetRealPathName(); + } // TODO: Provides symbol return hi;
🧹 Nitpick comments (4)
src/Server/Feature.cpp (1)
60-63: Consider loading HoverOptions from server configuration.The options are currently hardcoded inline. Moving these to the server's configuration structure would improve maintainability and allow users to customize hover behavior without code changes.
tests/unit/Feature/Hover.cpp (1)
156-156: The offsets vector is declared but never used.The vector is initialized but the test directly extracts offsets from
annotation.offsetsin the loop below (lines 161-162). This variable can be removed.auto annotation = AnnotatedSource::from(code); tester.add_main("main.cpp", annotation.content); - std::vector<unsigned> offsets; tester.compile();include/Feature/Hover.h (1)
77-79: Commenting out the test helper function is acceptable.Since this function is for testing and may be re-enabled later, commenting it out is reasonable for a work-in-progress PR. Consider removing it entirely if it won't be used.
src/Feature/Hover.cpp (1)
42-42: Consider reducing debug logging verbosity.The
logging::warncalls throughout the implementation (lines 42, 65-67, 70, and many more below) are useful during development but should be reduced or removed before merging to avoid log clutter in production. Consider usinglogging::debugor removing them.Also applies to: 65-67, 70-70
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
include/Feature/Hover.h(3 hunks)include/Protocol/Feature/Hover.h(1 hunks)src/Feature/Hover.cpp(1 hunks)src/Server/Feature.cpp(1 hunks)src/Server/Lifecycle.cpp(1 hunks)tests/unit/Feature/Hover.cpp(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/Server/Feature.cpp (1)
src/Feature/Hover.cpp (8)
hover(129-140)hover(129-131)hover(142-151)hover(142-144)hover(153-220)hover(153-155)hover(224-327)hover(224-226)
include/Feature/Hover.h (2)
src/Feature/Hover.cpp (12)
get_item_content(329-336)get_item_content(329-329)display(338-356)display(338-338)hover(129-140)hover(129-131)hover(142-151)hover(142-144)hover(153-220)hover(153-155)hover(224-327)hover(224-226)include/Compiler/CompilationUnit.h (1)
CompilationUnit(15-204)
tests/unit/Feature/Hover.cpp (1)
src/Feature/Hover.cpp (8)
hover(129-140)hover(129-131)hover(142-151)hover(142-144)hover(153-220)hover(153-155)hover(224-327)hover(224-226)
src/Feature/Hover.cpp (1)
src/AST/Selection.cpp (11)
range(401-431)range(401-401)unit(712-721)unit(712-715)kind(1179-1184)kind(1179-1179)os(1148-1148)node(972-984)node(972-972)create_right(1227-1234)create_right(1227-1227)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: macos (macos-15, debug)
- GitHub Check: build (macos-15)
- GitHub Check: macos (macos-15, release)
- GitHub Check: build (ubuntu-24.04)
- GitHub Check: linux (ubuntu-24.04, debug)
- GitHub Check: build (windows-2025)
- GitHub Check: windows (windows-2025)
- GitHub Check: linux (ubuntu-24.04, release)
🔇 Additional comments (18)
include/Protocol/Feature/Hover.h (1)
20-20: LGTM!The addition of
std::optional<Range>to support hover range visualization is well-documented and aligns with the broader hover feature enhancements.src/Server/Feature.cpp (1)
68-82: Good defensive handling of optional hover results.The code properly checks for
std::nulloptbefore accessing hover data and provides clear fallback messages when hover information is unavailable or cannot be displayed. This addresses the past review concern about dereferencing without checking.tests/unit/Feature/Hover.cpp (3)
35-82: LGTM!The Inclusion tests properly exercise hover functionality for include directives with both PCH and non-PCH compilation paths, correctly extracting offsets from annotations and calling the hover API.
115-170: The DeducedType_Auto test looks good.The test properly compiles annotated code and exercises hover at each annotated position with appropriate display handling.
172-245: The DeducedType_Decltype test looks good.The test properly compiles annotated code and exercises hover at each annotated position with appropriate display handling.
include/Feature/Hover.h (4)
6-6: LGTM!Adding the Protocol/Basic.h include is necessary for the proto::Range type used in hl_range.
38-39: LGTM!Renaming
EnumValuetoValuewith the updated comment better reflects the broader semantics for variables, constants, and enum items.
60-74: LGTM!The structural changes are well-designed:
- Making
documentoptional is appropriate since not all symbols have documentation.- Adding
hl_rangesupports range-based highlighting.- The new helper methods
get_item_content()anddisplay()provide clean interfaces for content extraction and rendering.
82-84: LGTM!The updated signature returning
std::optional<Hover>and acceptingconfig::HoverOptionsproperly reflects that hover may not always be available and allows for configurable behavior.src/Feature/Hover.cpp (9)
20-28: LGTM!The
to_proto_rangehelper cleanly converts Clang's SourceRange to the protocol's Range format using spelling locations.
41-72: Good implementation of hover items for fields and variables.The code properly extracts type information, offsets, alignment, size, and bitfield data for field declarations, with appropriate checks for dependent types and unions.
95-127: LGTM!The
get_qualifierandget_source_codehelper functions properly extract qualified names and source text using Clang's APIs.
129-140: LGTM!The hover function for NamedDecl cleanly aggregates all hover information using the helper functions.
153-220: The node-based hover dispatch is well-structured.The function properly dispatches to type-specific hover handlers based on AST node kind, with appropriate handling for auto/decltype types and fallbacks for unhandled node types.
229-236: LGTM!The
src_loc_in_main_filelambda now includes proper bounds checking, which addresses a previous review concern about validating offsets against file size.
270-313: Good implementation of macro hover support.The code properly extracts macro names, definitions, and expansions with appropriate range information. The macro expansion text extraction is a nice feature.
315-327: LGTM!The fallback to SelectionTree-based hover with proper range attachment is well-implemented.
329-356: LGTM!The
get_item_contentanddisplaymember functions provide clean interfaces for extracting and rendering hover information. The markdown-like formatting is readable and informative.
| auto annotation = AnnotatedSource::from(code); | ||
| tester.add_main("main.cpp", annotation.content); | ||
| for(unsigned idx = 0; idx < annotation.offsets.size(); ++idx) {} | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Macros test loop body is empty.
The test sets up annotated code with macro positions but the loop at line 112 iterates over annotation.offsets.size() without actually calling the hover API or making any assertions. This test doesn't verify any behavior.
Populate the loop body to exercise hover functionality:
auto annotation = AnnotatedSource::from(code);
tester.add_main("main.cpp", annotation.content);
- for(unsigned idx = 0; idx < annotation.offsets.size(); ++idx) {}
+ tester.compile();
+ expect(tester.unit.has_value());
+ for(unsigned idx = 0; idx < annotation.offsets.size(); ++idx) {
+ unsigned offset = annotation.offsets[std::format("pos_{}", idx)];
+ auto HI = clice::feature::hover(*tester.unit, offset, {});
+ if(HI.has_value()) {
+ auto msg = HI->display({});
+ std::println("```\n{}```\n", *msg);
+ } else {
+ std::println("No hover info for pos_{}", idx);
+ }
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| auto annotation = AnnotatedSource::from(code); | |
| tester.add_main("main.cpp", annotation.content); | |
| for(unsigned idx = 0; idx < annotation.offsets.size(); ++idx) {} | |
| }; | |
| auto annotation = AnnotatedSource::from(code); | |
| tester.add_main("main.cpp", annotation.content); | |
| tester.compile(); | |
| expect(tester.unit.has_value()); | |
| for(unsigned idx = 0; idx < annotation.offsets.size(); ++idx) { | |
| unsigned offset = annotation.offsets[std::format("pos_{}", idx)]; | |
| auto HI = clice::feature::hover(*tester.unit, offset, {}); | |
| if(HI.has_value()) { | |
| auto msg = HI->display({}); | |
| std::println(" |
🤖 Prompt for AI Agents
In tests/unit/Feature/Hover.cpp around lines 110 to 113, the for-loop over
annotation.offsets is empty so the test never exercises hover behavior; update
the loop to iterate each annotated offset, convert each offset to a
file/position, call the hover API (via the existing tester helper), and assert
or check the returned hover response (e.g., expect non-empty hover or match
against annotation.expected content), otherwise print/log "No hover info for
pos_{idx}" to make failures visible; ensure any required file/URI/position
construction uses the same helpers as above and add appropriate assertions so
the test validates hover results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
♻️ Duplicate comments (5)
src/Feature/Hover.cpp (5)
37-39: Fix aggregate construction inadd_itemlambda.This issue was previously flagged:
HoverItemhas no constructor taking(HoverKind, std::string). The lambda must construct the aggregate explicitly.Apply this diff:
auto add_item = [&items](HoverItem::HoverKind kind, std::string&& val) { - items.emplace_back(kind, val); + items.emplace_back(HoverItem{kind, std::move(val)}); };
84-94: Fix the documentation retrieval logic.This critical issue was previously flagged: Line 92 retrieves
raw_stringbut Line 93 immediately returns an empty string, so hover will never display documentation.Apply this diff to return the retrieved documentation:
static std::string get_document(CompilationUnit& unit, const clang::NamedDecl* decl, config::HoverOptions opt) { clang::ASTContext& Ctx = unit.context(); const clang::RawComment* comment = Ctx.getRawCommentForAnyRedecl(decl); if(!comment) { return ""; } auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); - return ""; + // TODO: Parse comment according to opt.parse_comment_as_markdown + return raw_string; }
86-86: Address unusedoptparameters.This issue was previously flagged: The
optparameter of typeconfig::HoverOptionsis not used inget_document,get_qualifier, orget_source_code. Unused parameters can be misleading.Either implement the configuration options (e.g., parse comments as markdown based on
opt.parse_comment_as_markdown) or remove the parameters if they're not yet needed.Also applies to: 98-98, 327-327
349-350: Remove debug dump to stderr.This issue was previously flagged: Line 350 dumps AST data directly to stderr. This is useful for debugging but should not be part of the final implementation.
Apply this diff:
static std::optional<Hover> hover(CompilationUnit& unit, const clang::TypeLoc* typeloc, const config::HoverOptions& opt) { // TODO: Hover for type LOGGING_WARN("Hit a typeloc"); - typeloc->dump(); auto ty = typeloc->getType();
467-468: Add null check for FileEntry before dereferencing.This critical issue was previously flagged: Line 467 calls
sm.getFileEntryForID(inclusion.fid)->tryGetRealPathName()without checking ifgetFileEntryForIDreturns nullptr.Apply this defensive check:
Hover hi; hi.kind = SymbolKind::Directive; hi.name = file_name; - auto dir = sm.getFileEntryForID(inclusion.fid)->tryGetRealPathName(); - hi.source = dir; + if(auto file_entry = sm.getFileEntryForID(inclusion.fid)) { + hi.source = file_entry->tryGetRealPathName(); + } // TODO: Provides symbol return hi;
🧹 Nitpick comments (1)
src/Feature/Hover.cpp (1)
476-477: Remove or downgrade verbose logging.This logging may be useful for development but should be removed or converted to debug-level logging for production.
auto tokens_under_cursor = unit.spelled_tokens_touch(*loc); if(tokens_under_cursor.empty()) { - LOGGING_WARN("Cannot detect tokens"); return std::nullopt; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Feature/Hover.cpp(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Feature/Hover.cpp (2)
src/AST/Selection.cpp (17)
range(401-431)range(401-401)begin(559-583)begin(559-559)unit(712-721)unit(712-715)kind(1179-1184)kind(1179-1179)os(1148-1148)node(972-984)node(972-972)offset(586-600)offset(586-586)offset(1125-1130)offset(1125-1125)create_right(1227-1234)create_right(1227-1227)src/Compiler/CompilationUnit.cpp (2)
resolver(317-320)resolver(317-317)
🔇 Additional comments (5)
src/Feature/Hover.cpp (5)
486-488: Verify the need to remove the last character from macro name.Line 487 calls
pop_back()on the macro name without explanation. This seems unusual and could indicate a workaround for an extraction issue.Verify that this is intentional. If
get_source_codeconsistently includes an unwanted trailing character, consider fixing the root cause in the extraction function rather than working around it here. Add a comment explaining why this is necessary if it's intentional.
118-155: Template helper functions look good.The
getContainedAutoParamTypeand template instantiation helpers are well-structured and handle the necessary type unwrapping and template specialization logic correctly.
165-303: DeducedTypeVisitor implementation is well-structured.The visitor pattern correctly handles various auto/decltype type deduction scenarios including function returns, declarators, and template parameters. The logic for unwrapping types and finding instantiations appears sound.
Note the FIXME at line 191 regarding resolver usage for undeduced auto types in variable declarations.
434-441: Offset validation is correctly implemented.The bounds checking added here addresses a previously flagged critical issue. The function now validates that the offset is within the file buffer before constructing a SourceLocation, preventing potential crashes from out-of-range offsets.
543-561: Display method provides good structured output.The
displaymethod correctly formats hover information with items, documentation, and source code. The TODO comment appropriately indicates future markdown generation capability.
| /// addItem(HoverItem::BitWidth, FD->getBitWidthValue()); | ||
| /// TODO: Add other hover items. | ||
| if(auto fd = llvm::dyn_cast<clang::FieldDecl>(decl)) { | ||
| LOGGING_WARN("Got a field decl"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Remove verbose debug logging.
This logging statement appears to be for development/debugging purposes and should be removed before merging, as it will clutter production logs.
Apply this diff:
if(auto fd = llvm::dyn_cast<clang::FieldDecl>(decl)) {
- LOGGING_WARN("Got a field decl");
const auto record = fd->getParent();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| LOGGING_WARN("Got a field decl"); | |
| if(auto fd = llvm::dyn_cast<clang::FieldDecl>(decl)) { | |
| const auto record = fd->getParent(); |
🤖 Prompt for AI Agents
In src/Feature/Hover.cpp around line 43, remove the development/debug verbose
logging call LOGGING_WARN("Got a field decl") because it clutters production
logs; delete that line (or replace it with a non-verbose conditional debug log
guarded by a debug flag if needed) and run a build to ensure no unused includes
or references remain.
| LOGGING_WARN("Got bit field, name: {}, bitwidth: {}", | ||
| fd->getName(), | ||
| fd->getBitWidthValue()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Remove verbose debug logging.
This logging is appropriate during development but should be removed before merging to avoid cluttering production logs with routine field processing information.
Apply this diff:
if(fd->isBitField()) {
add_item(HoverItem::BitWidth, llvm::Twine(fd->getBitWidthValue()).str());
- LOGGING_WARN("Got bit field, name: {}, bitwidth: {}",
- fd->getName(),
- fd->getBitWidthValue());
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| LOGGING_WARN("Got bit field, name: {}, bitwidth: {}", | |
| fd->getName(), | |
| fd->getBitWidthValue()); | |
| } | |
| if(fd->isBitField()) { | |
| add_item(HoverItem::BitWidth, llvm::Twine(fd->getBitWidthValue()).str()); | |
| } |
🤖 Prompt for AI Agents
In src/Feature/Hover.cpp around lines 66 to 69, remove the verbose LOGGING_WARN
call that logs bit field name and bitwidth; delete the three-line logging
statement (including the surrounding braces if they only exist to enclose that
log) so routine field processing no longer emits this debug output in
production.
| fd->getBitWidthValue()); | ||
| } | ||
| } else if(auto vd = llvm::dyn_cast<clang::VarDecl>(decl)) { | ||
| LOGGING_WARN("Got a var decl"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Remove verbose debug logging.
Remove this development logging statement to keep production logs clean.
Apply this diff:
} else if(auto vd = llvm::dyn_cast<clang::VarDecl>(decl)) {
- LOGGING_WARN("Got a var decl");
add_item(HoverItem::Type, vd->getType().getAsString());📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| LOGGING_WARN("Got a var decl"); | |
| } else if(auto vd = llvm::dyn_cast<clang::VarDecl>(decl)) { | |
| add_item(HoverItem::Type, vd->getType().getAsString()); |
🤖 Prompt for AI Agents
In src/Feature/Hover.cpp around line 71, remove the verbose development log
statement "LOGGING_WARN(\"Got a var decl\");" — delete that line from the file
(or replace it with a conditional/debug-only log behind an #ifdef DEBUG if you
need it during development) and ensure the removal doesn't leave any stray
punctuation or break compilation.
| static std::vector<HoverItem> get_hover_items(CompilationUnit& unit, | ||
| const clang::TypeLoc* typeloc, | ||
| const config::HoverOptions& opt) { | ||
| return {}; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeLoc hover items implementation is empty.
This overload returns an empty vector without any TODO comment. If hover items for TypeLoc are not yet supported, consider adding a TODO comment to track this.
Add a TODO comment if this is planned future work:
static std::vector<HoverItem> get_hover_items(CompilationUnit& unit,
const clang::TypeLoc* typeloc,
const config::HoverOptions& opt) {
+ // TODO: Implement hover items for TypeLoc (e.g., size, alignment)
return {};
}🤖 Prompt for AI Agents
In src/Feature/Hover.cpp around lines 78 to 82, the get_hover_items overload
that accepts a clang::TypeLoc currently returns an empty vector with no
indication why; add a single-line TODO comment above the function explaining
that TypeLoc hover item generation is not yet implemented (include a short note
about intended behavior or a reference to a tracking issue/PR number if
available) so future maintainers know this is planned work rather than an
omission.
| LOGGING_WARN("Hit a `NestedNameSpecifierLoc`"); | ||
| } else if(is_in_range(QualType, TypeLoc)) { | ||
| // Typeloc | ||
| LOGGING_WARN("Hit a `TypeLoc`"); | ||
| if(auto typeloc = node->get<clang::TypeLoc>()) { | ||
| return hover(unit, typeloc, opt); | ||
| } | ||
| } else if(is_in_range(Decl, Stmt)) { | ||
| // Decl | ||
| LOGGING_WARN("Hit a `Decl`"); | ||
| if(auto decl = node->get<clang::NamedDecl>()) { | ||
| return hover(unit, decl, opt); | ||
| } else { | ||
| LOGGING_WARN("Not intersted"); | ||
| } | ||
| } else if(is_in_range(Attr, ObjCProtocolLoc)) { | ||
| LOGGING_WARN("Hit an `Attr`"); | ||
| // TODO: Attr | ||
| } else { | ||
| // Not interested | ||
| LOGGING_WARN("Not interested"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Reduce verbose logging in node routing logic.
These logging statements appear to be for debugging the node kind routing logic. They should be removed or converted to debug-level logging to avoid cluttering production logs.
Consider removing these logging statements:
if(is(NestedNameSpecifierLoc)) {
- LOGGING_WARN("Hit a `NestedNameSpecifierLoc`");
} else if(is_in_range(QualType, TypeLoc)) {
// Typeloc
- LOGGING_WARN("Hit a `TypeLoc`");
if(auto typeloc = node->get<clang::TypeLoc>()) {
return hover(unit, typeloc, opt);
}
} else if(is_in_range(Decl, Stmt)) {
// Decl
- LOGGING_WARN("Hit a `Decl`");
if(auto decl = node->get<clang::NamedDecl>()) {
return hover(unit, decl, opt);
} else {
- LOGGING_WARN("Not intersted");
}
} else if(is_in_range(Attr, ObjCProtocolLoc)) {
- LOGGING_WARN("Hit an `Attr`");
// TODO: Attr
} else {
// Not interested
- LOGGING_WARN("Not interested");
}🤖 Prompt for AI Agents
In src/Feature/Hover.cpp around lines 397 to 417 the code emits multiple
LOGGING_WARN messages used only for routing/debugging; change these to a
debug-level logger (e.g., LOGGING_DEBUG) or remove them entirely to avoid
verbose production logs, keeping only meaningful warnings/errors; update the
messages consistently (or drop the "Not interested"/"Not intersted" ones) so
routing logic no longer floods warning logs.
| LOGGING_WARN("Got node: {}", node->kind()); | ||
| if(auto info = hover(unit, node, opt)) { | ||
| info->hl_range = to_proto_range(sm, hl_range); | ||
| return info; | ||
| } | ||
| return std::nullopt; | ||
| } else { | ||
| LOGGING_WARN("Not an ast node"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Remove verbose debug logging.
These logging statements appear to be for development purposes and should be removed to keep production logs clean.
auto tree = SelectionTree::create_right(unit, {offset, offset});
if(auto node = tree.common_ancestor()) {
- LOGGING_WARN("Got node: {}", node->kind());
if(auto info = hover(unit, node, opt)) {
info->hl_range = to_proto_range(sm, hl_range);
return info;
}
return std::nullopt;
} else {
- LOGGING_WARN("Not an ast node");
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| LOGGING_WARN("Got node: {}", node->kind()); | |
| if(auto info = hover(unit, node, opt)) { | |
| info->hl_range = to_proto_range(sm, hl_range); | |
| return info; | |
| } | |
| return std::nullopt; | |
| } else { | |
| LOGGING_WARN("Not an ast node"); | |
| } | |
| if(auto info = hover(unit, node, opt)) { | |
| info->hl_range = to_proto_range(sm, hl_range); | |
| return info; | |
| } | |
| return std::nullopt; | |
| } else { | |
| } |
🤖 Prompt for AI Agents
In src/Feature/Hover.cpp around lines 521 to 529, remove the two development
debug logging calls (LOGGING_WARN("Got node: {}", node->kind()); and
LOGGING_WARN("Not an ast node");) so they no longer emit verbose warnings in
production; simply delete those lines and keep the existing logic (call hover
and return info or std::nullopt) intact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (10)
src/Feature/Hover.cpp (10)
43-43: Remove verbose debug logging.This development logging statement clutters production logs and was flagged in previous reviews.
Apply this diff:
if(auto fd = llvm::dyn_cast<clang::FieldDecl>(decl)) { - LOGGING_WARN("Got a field decl"); const auto record = fd->getParent();
66-68: Remove verbose debug logging.This was flagged in previous reviews. Routine field processing should not emit warnings to production logs.
Apply this diff:
if(fd->isBitField()) { add_item(HoverItem::BitWidth, llvm::Twine(fd->getBitWidthValue()).str()); - LOGGING_WARN("Got bit field, name: {}, bitwidth: {}", - fd->getName(), - fd->getBitWidthValue()); }
71-71: Remove verbose debug logging.This development logging statement was flagged in previous reviews and should be removed.
Apply this diff:
} else if(auto vd = llvm::dyn_cast<clang::VarDecl>(decl)) { - LOGGING_WARN("Got a var decl"); add_item(HoverItem::Type, vd->getType().getAsString());
392-413: Reduce verbose logging in node routing logic.These logging statements were flagged in a previous review. They clutter production logs and should be removed or converted to debug-level logging.
Consider removing or downgrading these logging statements:
if(is(NestedNameSpecifierLoc)) { - LOGGING_WARN("Hit a `NestedNameSpecifierLoc`"); } else if(is_in_range(QualType, TypeLoc)) { - LOGGING_WARN("Hit a `TypeLoc`"); if(auto typeloc = node->get<clang::TypeLoc>()) { return hover(unit, typeloc->getType(), opt); } } else if(is_in_range(Decl, Stmt)) { - LOGGING_WARN("Hit a `Decl`"); if(auto decl = node->get<clang::NamedDecl>()) { return hover(unit, decl, opt); } else { - LOGGING_WARN("Not intersted"); } } else if(is_in_range(Attr, ObjCProtocolLoc)) { - LOGGING_WARN("Hit an `Attr`"); // TODO: Attr } else { - LOGGING_WARN("Not interested"); }
471-471: Remove verbose debug logging.This was flagged in previous reviews and clutters production logs.
Apply this diff:
auto tokens_under_cursor = unit.spelled_tokens_touch(*loc); if(tokens_under_cursor.empty()) { - LOGGING_WARN("Cannot detect tokens"); return std::nullopt; }
516-524: Remove verbose debug logging.These logging statements were flagged in a previous review and should be removed to keep production logs clean.
auto tree = SelectionTree::create_right(unit, {offset, offset}); if(auto node = tree.common_ancestor()) { - LOGGING_WARN("Got node: {}", node->kind()); if(auto info = hover(unit, node, opt)) { info->hl_range = to_proto_range(sm, hl_range); return info; } return std::nullopt; } else { - LOGGING_WARN("Not an ast node"); }
37-38: Fixadd_itemconstruction.This was flagged in a previous review:
HoverItemhas no(HoverKind, std::string)constructor, soitems.emplace_back(kind, val)will not compile. Build the aggregate explicitly.Apply this diff:
- auto add_item = [&items](HoverItem::HoverKind kind, std::string&& val) { - items.emplace_back(kind, val); + auto add_item = [&items](HoverItem::HoverKind kind, std::string&& val) { + items.emplace_back(HoverItem{kind, std::move(val)}); };
78-82: TypeLoc hover items implementation is empty.This was flagged in a previous review. Add a TODO comment to track future work if this is planned.
Add a TODO comment:
static std::vector<HoverItem> get_hover_items(CompilationUnit& unit, const clang::TypeLoc* typeloc, const config::HoverOptions& opt) { + // TODO: Implement hover items for TypeLoc (e.g., size, alignment) return {}; }
84-94: Fix the logic bug in get_document.This was flagged in a previous review. Line 92 retrieves the raw comment but line 93 returns an empty string, so documentation is never shown.
Apply this diff:
auto raw_string = comment->getRawText(Ctx.getSourceManager()).str(); - return ""; + // TODO: Parse comment according to opt.parse_comment_as_markdown + return raw_string; }
462-463: Check for null FileEntry before dereferencing.This was marked as addressed in previous commits, but the code still dereferences
getFileEntryForIDwithout checking for nullptr, which can crash.Apply this defensive check:
hi.kind = SymbolKind::Directive; hi.name = file_name; - auto dir = sm.getFileEntryForID(inclusion.fid)->tryGetRealPathName(); - hi.source = dir; + if(auto file_entry = sm.getFileEntryForID(inclusion.fid)) { + hi.source = file_entry->tryGetRealPathName(); + } // TODO: Provides symbol
🧹 Nitpick comments (1)
src/Feature/Hover.cpp (1)
47-48: Remove commented-out code.Commented code marked for removal creates maintenance debt. Either delete it or move it behind a debug flag if needed for development.
Apply this diff:
add_item(HoverItem::Type, fd->getType().getAsString()); - /// Remove in release mode - /// add_item(HoverItem::FieldIndex, llvm::Twine(fd->getFieldIndex()).str()); if(!record->isDependentType()) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Feature/Hover.cpp(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Feature/Hover.cpp (2)
src/AST/Selection.cpp (17)
range(401-431)range(401-401)begin(559-583)begin(559-559)unit(712-721)unit(712-715)kind(1179-1184)kind(1179-1179)os(1148-1148)node(972-984)node(972-972)offset(586-600)offset(586-586)offset(1125-1130)offset(1125-1125)create_right(1227-1234)create_right(1227-1227)src/Compiler/CompilationUnit.cpp (2)
resolver(317-320)resolver(317-317)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: build (macos-15)
- GitHub Check: build (ubuntu-24.04)
- GitHub Check: build (windows-2025)
- GitHub Check: macos (macos-15, debug)
- GitHub Check: linux (ubuntu-24.04, release)
- GitHub Check: linux (ubuntu-24.04, debug)
- GitHub Check: windows (windows-2025)
- GitHub Check: macos (macos-15, release)
🔇 Additional comments (1)
src/Feature/Hover.cpp (1)
480-482: Review comment remains valid—request manual verification of thepop_back()behavior.The investigation confirms this is an unusual pattern. The
token.range().toCharRange().getAsRange()conversion sequence appears only once in the codebase (line 480), andpop_back()is only applied here when extracting macro token names. Line 457 uses a different strategy—.trim()with known delimiters—suggesting these are intentional but unexplained differences.The boundary calculation through
clang::Lexer::getLocForEndOfToken()combined withCharSourceRange::getCharRange()andgetAsRange()could plausibly result in an off-by-one character. However, without test execution or Clang API validation, the correctness cannot be definitively determined. The "TODO: Found macro" comment suggests this code may still be under development.Please verify: (1) that macro names are extracted correctly with the
pop_back()call, (2) whether test coverage exists for this code path, and (3) whether similar token range conversions elsewhere in the codebase should also apply this trimming.
In process
Summary by CodeRabbit
New Features
Tests