Add FmtVisitor::from_context()

This commit is contained in:
Seiichi Uchida 2017-12-07 13:53:10 +09:00
parent 1d9a10e00e
commit c0eb8c3212
3 changed files with 7 additions and 5 deletions

View File

@ -629,7 +629,7 @@ pub fn rewrite_block_with_visitor(
return rw;
}
let mut visitor = FmtVisitor::from_codemap(context.parse_session, context.config, block.span);
let mut visitor = FmtVisitor::from_context(context);
visitor.block_indent = shape.indent;
visitor.is_if_else_block = context.is_if_else_block;
match block.rules {

View File

@ -657,8 +657,7 @@ pub fn format_impl(
let open_pos = snippet.find_uncommented("{")? + 1;
if !items.is_empty() || contains_comment(&snippet[open_pos..]) {
let mut visitor =
FmtVisitor::from_codemap(context.parse_session, context.config, item.span);
let mut visitor = FmtVisitor::from_context(context);
visitor.block_indent = offset.block_only().block_indent(context.config);
visitor.last_pos = item.span.lo() + BytePos(open_pos as u32);
@ -1056,8 +1055,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
let open_pos = snippet.find_uncommented("{")? + 1;
if !trait_items.is_empty() || contains_comment(&snippet[open_pos..]) {
let mut visitor =
FmtVisitor::from_codemap(context.parse_session, context.config, item.span);
let mut visitor = FmtVisitor::from_context(context);
visitor.block_indent = offset.block_only().block_indent(context.config);
visitor.last_pos = item.span.lo() + BytePos(open_pos as u32);

View File

@ -531,6 +531,10 @@ pub fn push_rewrite(&mut self, span: Span, rewrite: Option<String>) {
self.last_pos = source!(self, span).hi();
}
pub fn from_context(ctx: &'a RewriteContext) -> FmtVisitor<'a> {
FmtVisitor::from_codemap(ctx.parse_session, ctx.config, ctx.snippet_provider)
}
pub fn from_codemap(
parse_session: &'a ParseSess,
config: &'a Config,