Repository navigation
feat: classify more semantic token modifiers - #395
Conversation
📝 WalkthroughWalkthroughAdded helper predicates to classify declarations (default library, static, const, abstract, virtual) in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/feature/semantic_tokens.cpp (2)
190-195: Consider using a separate variable for the unwrapped declaration.Reassigning
declmid-function can be error-prone for maintainability. If future code is added above line 190 expecting the unwrapped decl, or vice versa, subtle bugs could occur.♻️ Suggested refactor using a separate variable
- // Apply attribute-style modifiers to the underlying declaration. - // The attribute tests don't want to look at the template. - if(const auto* template_decl = llvm::dyn_cast<clang::TemplateDecl>(decl)) { - if(const auto* templated_decl = template_decl->getTemplatedDecl()) - decl = templated_decl; - } + // Apply attribute-style modifiers to the underlying declaration. + // The attribute tests don't want to look at the template. + const clang::NamedDecl* attr_decl = decl; + if(const auto* template_decl = llvm::dyn_cast<clang::TemplateDecl>(decl)) { + if(const auto* templated_decl = template_decl->getTemplatedDecl()) + attr_decl = templated_decl; + }Then use
attr_declfor the modifier checks below.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/feature/semantic_tokens.cpp` around lines 190 - 195, The code reassigns the local variable decl to the templated declaration which is fragile; instead introduce a new variable (e.g., attr_decl or unwrapped_decl) to hold the result of llvm::dyn_cast<clang::TemplateDecl>(decl)->getTemplatedDecl() when present and use that new variable for the subsequent attribute/modifier checks, leaving the original decl untouched; update references in the surrounding logic that currently use decl for attribute-style modifier application to use attr_decl (falling back to decl when no templated decl exists).
138-140: Questionable: Marking functions as readonly based on return type.A function returning a
consttype (e.g.,const int* foo()) isn't inherently "readonly"—it may still have side effects. This could lead to misleading highlighting whereconst int* getData()is marked readonly butvoid logAccess()(a pure side-effect function) isn't.Consider whether this case should be removed, or if the intent is specifically to highlight functions that return something immutable (in which case a different modifier like
Constmight be more appropriate thanReadonly).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/feature/semantic_tokens.cpp` around lines 138 - 140, The current logic in semantic_tokens.cpp marks functions as readonly by checking the return type (the dyn_cast<clang::FunctionDecl>(decl) branch returning is_const(function->getReturnType())), which is misleading; update this by removing that return-type-based readonly check or by mapping it to a distinct modifier (e.g., "Const" rather than "Readonly"). Concretely: locate the dyn_cast<clang::FunctionDecl>(decl) branch and either delete the return of is_const(function->getReturnType()) so functions are not marked readonly based on return type, or replace the behavior so that when is_const(function->getReturnType()) is true you emit a different token/modifier name (e.g., Const) and leave Readonly for true side-effect-free analysis; ensure the token emission functions and modifier enums are updated accordingly (adjust any uses of is_const, the FunctionDecl branch, and the token/modifier mapping).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/feature/semantic_tokens.cpp`:
- Around line 85-87: Remove the clang::FunctionDecl special-case that returns
function->isStatic(): locate the llvm::dyn_cast<clang::FunctionDecl>(decl) block
(the one that does "if(const auto* function =
llvm::dyn_cast<clang::FunctionDecl>(decl)) { return function->isStatic(); }")
and delete it so namespace-scoped functions marked static are no longer treated
as having the 'static' modifier; allow the function to fall through to the
existing handling used for other decl kinds instead.
---
Nitpick comments:
In `@src/feature/semantic_tokens.cpp`:
- Around line 190-195: The code reassigns the local variable decl to the
templated declaration which is fragile; instead introduce a new variable (e.g.,
attr_decl or unwrapped_decl) to hold the result of
llvm::dyn_cast<clang::TemplateDecl>(decl)->getTemplatedDecl() when present and
use that new variable for the subsequent attribute/modifier checks, leaving the
original decl untouched; update references in the surrounding logic that
currently use decl for attribute-style modifier application to use attr_decl
(falling back to decl when no templated decl exists).
- Around line 138-140: The current logic in semantic_tokens.cpp marks functions
as readonly by checking the return type (the dyn_cast<clang::FunctionDecl>(decl)
branch returning is_const(function->getReturnType())), which is misleading;
update this by removing that return-type-based readonly check or by mapping it
to a distinct modifier (e.g., "Const" rather than "Readonly"). Concretely:
locate the dyn_cast<clang::FunctionDecl>(decl) branch and either delete the
return of is_const(function->getReturnType()) so functions are not marked
readonly based on return type, or replace the behavior so that when
is_const(function->getReturnType()) is true you emit a different token/modifier
name (e.g., Const) and leave Readonly for true side-effect-free analysis; ensure
the token emission functions and modifier enums are updated accordingly (adjust
any uses of is_const, the FunctionDecl branch, and the token/modifier mapping).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ec9a4842-4210-46a1-a769-d41a466fbdfa
📒 Files selected for processing (1)
src/feature/semantic_tokens.cpp
Summary
semantic_tokens.cppTesting
Summary by CodeRabbit