rust-lang / rust-lang/rust-analyzer
how to make custom snippets work?
Open
Nobody has claimed this yet.
C-support
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
considering my current config:
{
settings = {
["rust-analyzer"] = {
inlayHints = {
bindingModeHints = { enable = false },
chainingHints = { enable = false },
closingBraceHints = { enable = false },
closureReturnTypeHints = { enable = "never" },
discriminantHints = { enable = "never" },
expressionAdjustmentHints = { enable = "never" },
lifetimeElisionHints = { enable = "never" },
parameterHints = { enable = false },
reborrowHints = { enable = "never" },
typeHints = { enable = false },
},
completion = {
callable = { snippets = "add_parentheses" },
autoimport = { enable = false },
postfix = {
granularity = {
group = "module",
},
enable = false,
},
snippets = {
custom = {
Ok = {
postfix = "ok",
body = "Ok(${receiver})",
description = "Wrap the expression in a `Result::Ok`",
scope = "expr",
},
["Box::pin"] = {
postfix = "pinbox",
body = "Box::pin(${receiver})",
requires = "std::boxed::Box",
description = "Put the expression into a pinned `Box`",
scope = "expr",
},
["Arc::new"] = {
postfix = "arc",
body = "Arc::new(${receiver})",
requires = "std::sync::Arc",
description = "Put the expression into an `Arc`",
scope = "expr",
},
Some = {
postfix = "some",
body = "Some(${receiver})",
description = "Wrap the expression in an `Option::Some`",
scope = "expr",
},
Err = {
postfix = "err",
body = "Err(${receiver})",
description = "Wrap the expression in a `Result::Err`",
scope = "expr",
},
["Rc::new"] = {
postfix = "rc",
body = "Rc::new(${receiver})",
requires = "std::rc::Rc",
description = "Put the expression into an `Rc`",
scope = "expr",
},
},
},
},
imports = { prefix = "crate" },
diagnostics = {
disabled = { "inactive-code", "unlinked-file", "type-mismatch", "macro-error" },
enable = true,
experimental = { enable = false },
},
procMacro = {
enable = false,
attributes = { enable = false },
},
checkOnSave = true,
lens = {
enable = false,
run = { enable = false },
references = { method = { enable = false } },
implementations = { enable = false },
},
check = {
allTargets = true,
extraArgs = {},
},
cargo = {
buildScripts = { enable = false },
features = {},
},
runnables = { extraArgs = {} },
rustfmt = {
extraArgs = {},
rangeFormatting = { enable = true },
},
trace = { server = "off" },
},
},
on_attach = rust_analyzer_on_attach,
while I try to use a.pinbox or a.ok etc, it doesn't do anything or propose me anything. This feature is a bit wierd for me, it worked me years ago then suddenly it disappered and I cannot use them anymore
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported custom-snippet configuration in a Rust buffer, trying a.pinbox and a.ok with the supplied rust-analyzer settings. Check whether the snippets are offered at all and document the configuration or environment detail that determines whether the expected suggestions appear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100