Skip to content

Refactor for 2.0 #4168

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

Merged
merged 14 commits into from
May 20, 2020
Merged

Refactor for 2.0 #4168

merged 14 commits into from
May 20, 2020

Conversation

topecongiro
Copy link
Contributor

@topecongiro topecongiro commented May 10, 2020

This PR makes extensive internal/public changes to rustfmt codebase. It touches and modifies many files, which makes it hard to review this PR. I will try to follow up with a detailed explanation, but please feel free to ask questions if anything is unclear.

This PR specifically does the following:

  • Separate emitting into a different stage from formatting.
  • Remove internal configuration options from Config.
  • Update the public interface.
  • Organize internal module structure.

Comment on lines +85 to +94
/// Client-preference for coloured output.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Color {
/// Always use color, whether it is a piped or terminal output
Always,
/// Never use color
Never,
/// Automatically use color, if supported by terminal
Auto,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there plans to re-add support for color as a config option later on? If not it may be worth getting rid of the Always and Never variants, looks like they aren't used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there are not. We may add it back to the command-line interface. I would prefer to keep these variants as a part of the public API for rustfmt-as-a-library.

Comment on lines -1580 to -1593
// We missed some comments. Warn and keep the original text.
if context.config.error_on_unformatted() {
context.report.append(
context.parse_sess.span_to_filename(span),
vec![FormattingError::from_span(
span,
&context.parse_sess,
ErrorKind::LostComment,
)],
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is for rustfmt developers, so end-users should not see them. I guess we can keep this as a log message instead.

Comment on lines +66 to +74
pub fn newline_style(&self) -> NewlineStyle {
self.newline_style.clone()
}

pub fn original_text(&self) -> Option<&str> {
self.original_snippet.as_ref().map(|s| s.as_str())
}

pub fn formatted_text(&self) -> &str {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make these crate public too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are a part of the public API of rustfmt-as-a-library.

Comment on lines +123 to +125
if original_format_result.original_snippet.is_none() {
original_format_result.original_snippet = format_result.original_snippet;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not just perform the assignment?

for (file, errors) in errors_by_file {
for error in errors {
for (file, errors) in self.report.format_result_as_rc().borrow().iter() {
for error in errors.errors_excluding_macro() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are macro errors excluded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Macro-related errors are filtered because they are for internal use, and we don't want users to see them.

@topecongiro topecongiro force-pushed the rearch branch 2 times, most recently from 2ff3afd to 1265561 Compare May 12, 2020 04:50
@calebcartwright
Copy link
Member

I can set aside some time this weekend to read through this one in more detail, but generally good with the changes if you want to go ahead and merge as well

use crate::{
formatting::report::FormatReport,
result::{ErrorKind, FormatError},
};
use annotate_snippets::display_list::DisplayList;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems there's a decent amount of changes with the latest version of annotate_snippets and #4161 was opened to apply those changes to rustfmt. Not sure what the best merge sequencing would be between these two PRs

@@ -1,4 +1,5 @@
// rustfmt-config: issue-3933.toml
// rustfmt-recursive: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@topecongiro topecongiro merged commit e44a71c into rust-lang:master May 20, 2020
@topecongiro topecongiro deleted the rearch branch May 20, 2020 07:50
@karyon
Copy link
Contributor

karyon commented Oct 28, 2021

backport not needed (doesn't look to me like it's feasible)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants