Is it possible to put const a = @This() on the top of a file when run code action organize @import?
#3218
|
When a file itself is an anonymous struct, I would like to put the statement |
Replies: 1 comment 1 reply
|
I do not think this is currently configurable. const a = @ This(); is just a normal top-level declaration from ZLS’s point of view. The organize-imports action mainly tries to collect/sort top-level @ import and related alias declarations, so it will tend to keep the import block together and move non-import declarations such as @ This() outside that block. So if you start with something like: const Self = @This();
const std = @import("std");
const foo = @import("foo.zig");organize imports may rewrite it toward the more conventional import-first layout: const std = @import("std");
const foo = @import("foo.zig");
const Self = @This();As far as I know, there is currently no per-declaration “keep this above imports” or “do not move this declaration” option for organize imports. For now the practical options seem to be:
Personally, I would probably frame this as a feature request rather than a bug, because @ This() is not an import and ZLS currently has no way to know that you want it treated as a special file-header declaration. |
I do not think this is currently configurable.
const a = @ This(); is just a normal top-level declaration from ZLS’s point of view. The organize-imports action mainly tries to collect/sort top-level @ import and related alias declarations, so it will tend to keep the import block together and move non-import declarations such as @ This() outside that block.
So if you start with something like:
organize imports may rewrite it toward the more conventional import-first layout:
As far as I know, there is currently no per-declaratio…