Merge pull request #2181 from topecongiro/issue-2111

Use vertical layout when there are single line comments in import
This commit is contained in:
Nick Cameron 2017-11-24 11:03:00 +13:00 committed by GitHub
commit f5dd4591cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 7 deletions

View File

@ -137,10 +137,10 @@ impl ListItem {
pub fn has_comment(&self) -> bool {
self.pre_comment
.as_ref()
.map_or(false, |comment| comment.starts_with("//"))
.map_or(false, |comment| comment.trim_left().starts_with("//"))
|| self.post_comment
.as_ref()
.map_or(false, |comment| comment.starts_with("//"))
.map_or(false, |comment| comment.trim_left().starts_with("//"))
}
pub fn from_str<S: Into<String>>(s: S) -> ListItem {
@ -410,7 +410,9 @@ where
formatting.config.max_width(),
));
}
let overhead = if let Some(max_width) = *item_max_width {
let overhead = if starts_with_newline(comment) {
0
} else if let Some(max_width) = *item_max_width {
max_width + 2
} else {
// 1 = space between item and comment.
@ -425,12 +427,17 @@ where
|| comment.trim().contains('\n')
|| comment.trim().len() > width;
rewrite_comment(comment, block_style, comment_shape, formatting.config)
rewrite_comment(
comment.trim_left(),
block_style,
comment_shape,
formatting.config,
)
};
let mut formatted_comment = rewrite_post_comment(&mut item_max_width)?;
if !starts_with_newline(&formatted_comment) {
if !starts_with_newline(&comment) {
let mut comment_alignment =
post_comment_alignment(item_max_width, inner_item.len());
if first_line_width(&formatted_comment) + last_line_width(&result)
@ -448,6 +455,9 @@ where
{
result.push(' ');
}
} else {
result.push('\n');
result.push_str(&indent_str);
}
if formatted_comment.contains('\n') {
item_max_width = None;

View File

@ -0,0 +1,28 @@
// rustfmt-normalize_comments: false
// An import with single line comments.
use super::{
SCHEMA_VERSIONS,
LodaModel,
ModelProperties,
StringMap,
ModelSelector,
RequestDescription,
MethodDescription,
ModelBehaviour,
ModelRequestGraph,
DelayChoice,
Holding,
Destinations,
ModelEdges,
Switch,
// ModelMetaData,
// Generated,
// SecondsString,
// DateString,
// ModelConfiguration,
// ModelRequests,
// RestResponse,
// RestResponseCode,
// UniformHolding
};

View File

@ -18,7 +18,7 @@ fn foo(
arg5: LongTypeName,
arg6: LongTypeName,
arg7: LongTypeName,
//arg8: LongTypeName,
//arg8: LongTypeName,
) {
// do stuff
}

View File

@ -0,0 +1,26 @@
// rustfmt-normalize_comments: false
// An import with single line comments.
use super::{DelayChoice,
Destinations,
Holding,
LodaModel,
MethodDescription,
ModelBehaviour,
ModelEdges,
ModelProperties,
ModelRequestGraph,
ModelSelector,
RequestDescription,
StringMap,
Switch,
// ModelMetaData,
// Generated,
// SecondsString,
// DateString,
// ModelConfiguration,
// ModelRequests,
// RestResponse,
// RestResponseCode,
// UniformHolding
SCHEMA_VERSIONS};

View File

@ -47,7 +47,8 @@ pub type GenericsFitButNotEqualTest<
pub type CommentTest<
// Lifetime
'a, // Type
'a,
// Type
T,
> = ();