-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
refactoring.nix
162 lines (134 loc) · 5.17 KB
/
refactoring.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
helpers.neovim-plugin.mkNeovimPlugin config {
name = "refactoring";
originalName = "refactoring.nvim";
defaultPackage = pkgs.vimPlugins.refactoring-nvim;
maintainers = [ helpers.maintainers.MattSturgeon ];
# TODO: introduced 2024-05-24, remove on 2024-08-24
optionsRenamedToSettings = [
"promptFuncReturnType"
"promptFuncParamType"
"printVarStatements"
"printfStatements"
"extractVarStatements"
];
extraOptions = {
enableTelescope = mkEnableOption "telescope integration";
};
extraConfig = cfg: {
assertions = [
{
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''
Nixvim: You have enabled the `telescope` integration with refactoring-nvim.
However, you have not enabled the `telescope` plugin itself (`plugins.telescope.enable = true`).
'';
}
];
plugins.telescope.enabledExtensions = mkIf cfg.enableTelescope [ "refactoring" ];
};
settingsOptions = with helpers.nixvimTypes; {
prompt_func_return_type =
helpers.defaultNullOpts.mkAttrsOf bool
{
go = false;
java = false;
cpp = false;
c = false;
h = false;
hpp = false;
cxx = false;
}
''
For certain languages like Golang, types are required for functions that return an object(s).
Unfortunately, for some functions there is no way to automatically find their type. In those instances,
we want to provide a way to input a type instead of inserting a placeholder value.
Set the relevant language(s) to `true` to enable prompting for a return type, e.g:
```nix
{
go = true;
cpp = true;
c = true;
java = true;
}
```
'';
prompt_func_param_type =
helpers.defaultNullOpts.mkAttrsOf bool
{
go = false;
java = false;
cpp = false;
c = false;
h = false;
hpp = false;
cxx = false;
}
''
For certain languages like Golang, types are required for functions parameters.
Unfortunately, for some parameters there is no way to automatically find their type. In those instances,
we want to provide a way to input a type instead of inserting a placeholder value.
Set the relevant language(s) to `true` to enable prompting for parameter types, e.g:
```nix
{
go = true;
cpp = true;
c = true;
java = true;
}
'';
printf_statements = helpers.defaultNullOpts.mkAttrsOf (listOf (maybeRaw str)) { } ''
In any custom printf statement, it is possible to optionally add a **max of one `%s` pattern**, which is where the debug path will go.
For an example custom printf statement, go to [this folder][folder], select your language, and click on `multiple-statements/printf.config`.
Note: if you have multiple custom statements, the plugin will prompt for which one should be inserted.
If you just have one custom statement in your config, it will override the default automatically.
Example:
```nix
{
# add a custom printf statement for cpp
cpp = [ "std::cout << \"%s\" << std::endl;" ];
}
```
[folder]: https://github.com/ThePrimeagen/refactoring.nvim/blob/master/lua/refactoring/tests/debug/printf
'';
print_var_statements = helpers.defaultNullOpts.mkAttrsOf (listOf (maybeRaw str)) { } ''
In any custom print var statement, it is possible to optionally add a **max of two `%s` patterns**, which is where the debug path and
the actual variable reference will go, respectively. To add a literal `"%s"` to the string, escape the sequence like this: `%%s`.
For an example custom print var statement, go to [this folder][folder], select your language, and view `multiple-statements/print_var.config`.
Note: if you have multiple custom statements, the plugin will prompt for which one should be inserted.
If you just have one custom statement in your config, it will override the default automatically.
Example:
```nix
{
# add a custom print var statement for cpp
cpp = [ "printf(\"a custom statement %%s %s\", %s)" ];
}
```
[folder]: https://github.com/ThePrimeagen/refactoring.nvim/blob/master/lua/refactoring/tests/debug/print_var
'';
extract_var_statements = helpers.defaultNullOpts.mkAttrsOf str { } ''
When performing an `extract_var` refactor operation, you can custom how the new variable would be declared by setting configuration
like the below example.
Example:
```nix
{
# overriding extract statement for go
go = "%s := %s // poggers";
}
```
'';
show_success_message = helpers.defaultNullOpts.mkBool false ''
Shows a message with information about the refactor on success. Such as:
```
[Refactor] Inlined 3 variable occurrences
```
'';
};
}