-
Notifications
You must be signed in to change notification settings - Fork 924
tracking issue: file-lines #1514
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
Comments
It is probably worth clearly defining what sorts of things should and shouldn't be formatted when they partially overlap a range specified by file_lines. There are tons of possible edge cases and it is worth making sure that the code makes consistent and reasonable choices throughout. Another test that would be worth having would be one that run rustfmt over a large collection of files (perhaps all of the integration tests?) with file_lines set to the empty set. Ideally this should leave everything unchanged, but I suspect that there are places that forget to check file_lines at all before applying formatting. |
My perspective here is purely from IDEs, I'm not sure if there are other applications which have other needs. I would expect that formatting with file lines would be expected to be approximate, so there would probably never be a spec for what gets formatted and what doesn't. I would expect the lines specified would be the minimum and that the maximum would be the entire file. If there is a I would expect any module-level AST-node which overlaps the specified lines to be formatted. That is, any AST node which can appear in a module (and thus can be parsed alone). This covers functions, consts/statics, modules, data structures, impls, and traits. I would expect that only the smallest module-level node would be reformatted. E.g.,
lines: 4 would only reformat In the future we might change this to any AST node, rather than any module-level node, but that will require fairly deep changes to both the parser and Rustfmt. I would expect comment formatting to be a bit rough around the boundary. Basically, if a comment is inside the lines but outside any AST reformatted nodes, or outside the lines, but inside (or adjacent to) a reformatted node, then the comments may or may not be reformatted. I feel like there should be more. What am I missing? |
Unless someone has done any work with it in the last year since I touched it, the status is that it's very much incomplete. I believe that I implemented argument parsing and threading the file lines through the context, as well as a not-really-reliable proof of concept for statements.
Does this mean |
There has been some work - @fintelia has done some good stuff recently
This seems doable as a long term thing, but I think it pretty tricky to get into a 'good-enough' milestone. |
Dear members, What is the most stable revision of rustfmt with support for I have tried the nightly-mode master branch (Built via Background: I am currently maintaining rust-lang/rust.vim and trying to integrate with a working version for the Given the input fn main() {
let a = 2;
let x = 1;
let c = 2;
let b = 2;
let d = 3;
} Both of the following two modes of executions that I am trying do not work: 1
Result: The entirety of 2 (older method)
Result: rustfmt waits for stdin and does nothing to a.rs. If I prepend Thanks! |
The current implementation overestimates the lines to format. I don't recall the exact logic used, but in your example, this causes everything in the main function to be reformatted. If you added additional functions to that same file, those should not get formatted. |
Thanks, that really clarifies :) |
What is the expected format of the |
file-lines is an option to format only a range of a file, rather than a whole project. It is important for using rustfmt from editors or the RLS.
I must admit I'm not exactly sure on the status of the feature. I'll attempt to track what needs doing here.
cc @kamalmarhubi @topecongiro @fintelia
The text was updated successfully, but these errors were encountered: