JSS*_*all 11 rust visual-studio-code rust-analyzer
我见过 youtube 等人使用 rust-analyzer 插件在 VSC 中使用 Rust,他们会显示可选的类型注释,即使它不一定写在代码中。就像我foo(a,b)在编辑器中输入内容一样,它会自动显示和为淡灰色的foo(a: A, b: B)位置,可能甚至没有写在文件中,只是视觉提示?很好,但我不知道这是 VSC 还是 rust-analyzer 的功能吗?我的 rust-analyzer 有两个设置 Parameter Hints 和 TypeHints 均设置为启用。:A:B
您正在寻找parameter hints这种情况。您想要显示提示的函数也需要有多个参数。
确保该设置已启用:
设置(用户界面)
Inlay hints: Parameter hints
Run Code Online (Sandbox Code Playgroud)
设置(JSON)
Inlay hints: Parameter hints
Run Code Online (Sandbox Code Playgroud)
然后您应该得到类似于以下内容的结果:
"rust-analyzer.inlayHints.parameterHints": true
Run Code Online (Sandbox Code Playgroud)
确保仅rust-analyzer启用,因为它可能与rls. 如果两者都启用,则添加一条警告,其中提到以下内容:
fn add(x: u32, y: u32) -> u32 {
x + y
}
fn main() {
let result = add(x: 4, y: 2);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16812 次 |
| 最近记录: |