-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[feat] Optional Inlay Hint for Too Many Implicit Returns in One Function #18924
Comments
What do you mean? I don't see any (early) exit points in there. |
There are too many implicit returns used in |
I still don't see them, but okay. |
Can you give a concrete example? The only exit point in that mentioned function is
|
As shown in the screenshot, there are too many implicit returns used in the nesting I think an inlay hint would be helpful to identify this kind of implicit returns. |
What exactly will the hint show? |
@Veykril @lnicola @ChayimFriedman2 I have designed a scheme to give a inlay hint to the reader, but it's my first time to issue a new feature request. Thus, it needs more discussion. I use two code snippets in Example 1 for piece in asm.asm_pieces() {
let slot = operands.len();
let mut ▶lower_reg = |reg: Option<ast::AsmRegSpec>| {
let reg = reg?;
if let Some(string) = reg.string_token() {
reg_args.insert(slot);
⏎Some(InlineAsmRegOrRegClass::Reg(Symbol::intern(string.text())))
} else {
⏎reg.name_ref().map(|name_ref| {
InlineAsmRegOrRegClass::RegClass(Symbol::intern(&name_ref.text()))
}) // The cursor is in this line.
}
}; Example 2 ast::AsmPiece::AsmOperandNamed(op) => {
let name = op.name().map(|name| Symbol::intern(&name.text()));
if let Some(name) = &name {
named_args.insert(name.clone(), slot);
named_pos.insert(slot, name.clone());
}
let Some(op) = op.asm_operand() else { continue };
(
name.map(Name::new_symbol_root),
▶match op { // This is a rvalue, not a lvalue receiving the implicit return.
ast::AsmOperand::AsmLabel(l) => {
⏎AsmOperand::Label(self.collect_block_opt(l.block_expr()))
}
ast::AsmOperand::AsmConst(c) => {
⏎AsmOperand::Const(self.collect_expr_opt(c.expr())) // The cursor is in this line.
}
ast::AsmOperand::AsmSym(s) => {
let Some(path) =
s.path().and_then(|p| self.expander.parse_path(self.db, p))
else {
continue;
};
⏎AsmOperand::Sym(path)
}
},
)
}
}; When a user hovers and clicks the line of the implicit return in the nesting match block, the lsp would give inlay hints of When user changes the cursor to the other line, the It is also helpful to add an comtemporary inlay hint of |
It it not clear about what's the relationship between the screenshot and this issue? My plan does not include any drawn lines or any collapsing, expanding operations shown in the screenshot. It just adds some inlay hints of unicode symbols before some line. |
I have previewed the history of issues, and noticed that the optional inlay hint for the implicit returns would be useful when there are too many returns in one function.
For example, in
crates\hir-def\src\body\lower\asm.rs
, thelower_inline_asm
function has too many returns for readers to distinguish the difference.I also see the similar issues in the history, e.g. #9969, #4691.
I think adding inlay hint for the implicit return would be a useful option.
The text was updated successfully, but these errors were encountered: