2.8 KiB
Code actions
Code actions are applicable code transformations.
- In coc.nvim, they can be triggered on cursor position via
<Plug>(coc-codeaction-cursor)
, which by default binds to<leader>ac
.
- In VSCode, they can be triggered by clicking the lightbulb 💡 icon at the beginning of the cursor line.
Here is the list of all implemented code actions, sorted by their mod
name in code
crates/ide/src/ide/assists
.
Currently documentations below are simply copied from doc-comments of their mod
s.
add_to_top_level_lambda_param
Add an undefined name to the top-level lambda.
{ foo }: foo + bar
=>
{ foo, bar }: foo + bar
convert_to_inherit
Convert path = value;
into inherit key;
.
This covers,
prefix.key = key;
=>prefix = { inherit key; };
Here theprefix
set mut not berec
. The code before is actually an infinite recursion while the code after is not.prefix.key = from.key;
=>prefix = [rec] { inherit (from) key; };
Since thefrom
is resolved in theprefix
scope thus it is allowed to have recursive references (but may not be infinite recursion).
flatten_attrset
Flatten binding with Attrset RHS into multiple bindings of outer level. FIXME: Indentations are not reformatted well.
{
foo = {
bar = 1;
baz = 2;
};
}
=>
{
foo.bar = 1;
foo.baz = 2;
}
pack_bindings
Pack one or more implicit bindings of implicit Attrset into explicit nested one. FIXME: Indentations are not reformatted well.
{
foo.bar = 1;
foo.baz = 2;
}
=>
{
foo = {
bar = 1;
baz = 2;
};
}
quote_attr
and unquote_attr
Rewrite between attribute names and double quoted strings
{ foo = bar; }
<=>
{ "foo" = bar; }
remove_empty_inherit
Remove empty inherit;
or inherit (...);
.
{ foo = "bar"; inherit; }
=>
{ foo = "bar"; }
remove_empty_let_in
Remove empty let in ...
.
let in { foo = "bar"; }
=>
{ foo = "bar"; }
remove_unused_binding
Remove an unused pattern binding.
{ foo, bar }: { foo = 1; }
=>
{ foo }: { foo = 1; }
Or, remove an unused let binding.
let
foo.bar = 1;
foo.baz = 2;
in {}
=>
let
in {}
rewrite_string_to_indented
and rewrite_indented_to_string
Rewrite between double quoted strings and indented strings
"foo\nbar\n"
=>
''
foo
bar
''
rewrite_uri_to_string
Rewrite URI literals to double quoted strings
https://nixos.org
=>
"https://nixos.org"
inline
Rewrite a binding to its definition.
let id = x: x; in a 1
=>
let id = x: x; in (x: x) 1