-
-
Notifications
You must be signed in to change notification settings - Fork 398
Add code action for organizing imports #881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Just my two cents.
const account = @import("account.zig");
const arch = @import("arch.zig");
const arm = @import("arch/arm.zig");
const riscv = @import("arch/riscv.zig");
const x86 = @import("arch/x86.zig");
const base = @import("base.zig");
const PhysAddr = @import("paging/PhysAddr.zig");
const VirtAddr = @import("paging/VirtAddr.zig");
pub const build_options = @import("build_options");
const std = @import("std");
const builtin = @import("builtin");
pub const tres = @import("tres");
const known_folders = @import("known-folders");
pub const debug = @import("debug.zig");
const Config = @import("Config.zig");
const Server = @import("Server.zig");Actually have differnet sections for pub vs non-pub: pub const build_options = @import("build_options");
const std = @import("std");
const builtin = @import("builtin");
pub const tres = @import("tres");
const known_folders = @import("known-folders");
pub const debug = @import("debug.zig");
const Config = @import("Config.zig");
const Server = @import("Server.zig");Or something else?
|
Yes. Looks nicer.
Prefix based sorting is simpler and reproducible with other tooling ([neo]vim has
KISS, if nobody has a feasible use case.
Take a look at os.zig in my PR for how to make things nice and which stuff should be preserved (the posix stuff has empty line separations): https://github.com/ziglang/zig/pull/14726/files#diff-4284cdf770ea88be46f4aab7f82ed3c58821e4b3433b7c6152278a9911348dc5R21-R179 |
|
Just some bikeshedding: What does it mean for "capitalisation to matter"? I personally think it shouldn't matter in that adding more rules to sorting will make things annoying to deal with. Sorting things in order of ASCII/Unicode values make the most sense, imo. I personally prefer what |
80ace37 to
35a2a2d
Compare
|
I'm gonna close this PR instead of keeping this old PR around forever. See #1637 |
This PR adds a code action for automatically sorting imports.
The current implementation has this sorting order:
How exactly imports should be sorted needs a more thorough discussion.
Some of the questions that need to be answered include:
@import()?pubor not?@import("subdirectory/file.zig")sorted?const Server = @This();orconst Ast = std.zig.Ast;?There are also some issues in this implementation that need to be fixed:
pubkeyword andvarorconstkeywordconst name = @import("file.zig").Decl;