-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
A tool to perform renames #151
Comments
I thought about how to implement this a bit already:
|
@infinisil I was trying to describe the minimal implementation that would be viable for the un-categorization refactoring. Your suggestions seem to ask for more than what is strictly necessary.
I disagree. This is an optimization that's only necessary when the performance isn't good enough.
I agree that this would be a familiar interface, but the performance optimization required for this is a lot to ask.
This is LSP or other standardization territory. It's not necessary.
No such step needs to be implemented, but I agree that it's ok for the operation to be lossy in this way.
It's rare for renames to be entirely undetectable, being guaranteed to work. Nix has
This contradicts the earlier idea that implicitly canonicalizing path expressions is ok. We can restrict the reversibility property to expressions with canonical paths only.
The renames are a function between paths. Operations on this function should take into account the hierarchical nature of paths, but do not need to know the types of paths as could be learned from |
I have started with something like this here: nixpkgs-architecture/simple-package-paths#22. It doesn't implement the renaming yet, but only the first step towards that, I plan to work more on this |
I too am interested in this. The thing I am getting stuck on -- how can I create an ast node from another node while changing some of its values? Would someone be able to provide any example code? I will keep playing around to see if I can get this, but am a bit lost as to this at the moment (especially because, afaict, methods that would allow this seem to be private). |
Perhaps related, which doesn't require private calls. Taken via https://github.com/nix-community/rnix-parser/blob/master/src/ast/str_util.rs#L273. fn main() {
let content = "cool";
let mut builder = GreenNodeBuilder::new();
builder.start_node(NixLanguage::kind_to_raw(NODE_STRING));
builder.token(NixLanguage::kind_to_raw(TOKEN_STRING_START), "''");
builder.token(NixLanguage::kind_to_raw(TOKEN_STRING_CONTENT), content);
builder.token(NixLanguage::kind_to_raw(TOKEN_STRING_END), "''");
builder.finish_node();
let zzz: rnix::ast::Str = ast::Str::cast(SyntaxNode::new_root(builder.finish())).unwrap();
println!("{}", zzz);
} |
Description
When renaming a file in a collection of Nix files, the relative path expressions that referenced the old location become invalid.
The Nixpkgs architecture team is working on a cleanup operation that will move a huge number of files. Being able to do so in an automated and accurate manner would be a game changer.
The code that supports this operation may also benefit rnix-lsp, although the LSP rename functionality doesn't appear to be as advanced as, say, IntelliJ's.
Considered alternatives
We might hack the paths using
sed
and friends, but this runs the risk of breaking some paths whose use is optional and therefore not revealed by testing the evaluation.Additional context
This is a call for help.
I don't have the rust experience to pull this off, but I know rnix is well suited, because it can preserve syntax and it supports an lsp.
Considering the O(n²) nature of all possible file-to-file references, we'll want to perform the renames in batches. Non-Nix files may be referenced and renamed.
Example interface:
--project
scans the passed directory recursively for.nix
files that may reference the moved files.Our use case is https://github.com/nixpkgs-architecture/auto-called-packages
If you're interested on working on this, reach out to us on https://matrix.to/#/#nixpkgs-architecture:nixos.org
The text was updated successfully, but these errors were encountered: