v.fmt #
fn fmt #
fn fmt(file ast.File, mut table ast.Table, pref_ &pref.Preferences, is_debug bool, options FmtOptions) string
enum CommentsLevel #
enum CommentsLevel {
keep
indent
}
struct AttrsOptions #
@[params]
struct AttrsOptions {
pub:
same_line bool
}
struct CommentsOptions #
@[minify]
@[params]
struct CommentsOptions {
has_nl bool = true
same_line bool
level CommentsLevel
prev_line int = -1
}
CommentsOptions defines the way comments are going to be written- has_nl: adds an newline at the end of a list of comments
- same_line: line comments will be on the same line as the last statement
- level: either .keep (don't indent), or .indent (increment indentation)
- prev_line: the line number of the previous token to save linebreaks
struct Fmt #
@[minify]
struct Fmt {
pub:
pref &pref.Preferences = unsafe { nil }
pub mut:
file ast.File
table &ast.Table = unsafe { nil }
is_debug bool
out strings.Builder
out_imports strings.Builder
indent int
empty_line bool
line_len int // the current line length, Note: it counts \t as 4 spaces, and starts at 0 after f.writeln
buffering bool // disables line wrapping for exprs that will be analyzed later
par_level int // how many parentheses are put around the current expression
array_init_break []bool // line breaks after elements in hierarchy level of multi dimensional array
array_init_depth int // current level of hierarchy in array init
single_line_if bool
cur_mod string
did_imports bool
import_pos int // position of the imports in the resulting string
auto_imports map[string]bool // potentially hidden imports(`sync` when using channels) and preludes(when embedding files)
used_imports map[string]bool // to remove unused imports
import_syms_used map[string]bool // to remove unused import symbols
mod2alias map[string]string // for `import time as t`, will contain: 'time'=>'t'
mod2syms map[string]string // import time { now } 'time.now'=>'now'
use_short_fn_args bool
single_line_fields bool // should struct fields be on a single line
in_lambda_depth int
inside_const bool
inside_unsafe bool
inside_comptime_if bool
is_assign bool
is_index_expr bool
is_mbranch_expr bool // match a { x...y { } }
is_struct_init bool
fn_scope &ast.Scope = unsafe { nil }
wsinfix_depth int
format_state FormatState
source_text string // can be set by `echo "println('hi')" | v fmt`, i.e. when processing source not from a file, but from stdin. In this case, it will contain the entire input text. You can use f.file.path otherwise, and read from that file.
}
fn (Fmt) alias_type_decl #
fn (mut f Fmt) alias_type_decl(node ast.AliasTypeDecl)
fn (Fmt) anon_fn #
fn (mut f Fmt) anon_fn(node ast.AnonFn)
fn (Fmt) array_decompose #
fn (mut f Fmt) array_decompose(node ast.ArrayDecompose)
=== Specific Expr methods ===//
fn (Fmt) array_init #
fn (mut f Fmt) array_init(node ast.ArrayInit)
fn (Fmt) as_cast #
fn (mut f Fmt) as_cast(node ast.AsCast)
fn (Fmt) assert_stmt #
fn (mut f Fmt) assert_stmt(node ast.AssertStmt)
=== Specific Stmt methods ===//
fn (Fmt) assign_stmt #
fn (mut f Fmt) assign_stmt(node ast.AssignStmt)
fn (Fmt) assoc #
fn (mut f Fmt) assoc(node ast.Assoc)
fn (Fmt) at_expr #
fn (mut f Fmt) at_expr(node ast.AtExpr)
fn (Fmt) attrs #
fn (mut f Fmt) attrs(attrs []ast.Attr)
fn (Fmt) block #
fn (mut f Fmt) block(node ast.Block)
fn (Fmt) branch_stmt #
fn (mut f Fmt) branch_stmt(node ast.BranchStmt)
fn (Fmt) calculate_alignment #
fn (mut f Fmt) calculate_alignment(fields []ast.StructField, mut type_align FieldAlign, mut comment_align FieldAlign,
mut default_expr_align FieldAlign, mut attr_align FieldAlign, mut field_types []string)
fn (Fmt) call_args #
fn (mut f Fmt) call_args(args []ast.CallArg)
fn (Fmt) call_expr #
fn (mut f Fmt) call_expr(node ast.CallExpr)
fn (Fmt) cast_expr #
fn (mut f Fmt) cast_expr(node ast.CastExpr)
fn (Fmt) chan_init #
fn (mut f Fmt) chan_init(mut node ast.ChanInit)
fn (Fmt) char_literal #
fn (mut f Fmt) char_literal(node ast.CharLiteral)
fn (Fmt) comment #
fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions)
fn (Fmt) comments #
fn (mut f Fmt) comments(comments []ast.Comment, options CommentsOptions)
fn (Fmt) comments_after_last_field #
fn (mut f Fmt) comments_after_last_field(comments []ast.Comment)
fn (Fmt) comments_before_field #
fn (mut f Fmt) comments_before_field(comments []ast.Comment)
fn (Fmt) comptime_call #
fn (mut f Fmt) comptime_call(node ast.ComptimeCall)
fn (Fmt) comptime_for #
fn (mut f Fmt) comptime_for(node ast.ComptimeFor)
fn (Fmt) comptime_selector #
fn (mut f Fmt) comptime_selector(node ast.ComptimeSelector)
fn (Fmt) concat_expr #
fn (mut f Fmt) concat_expr(node ast.ConcatExpr)
fn (Fmt) const_decl #
fn (mut f Fmt) const_decl(node ast.ConstDecl)
fn (Fmt) debugger_stmt #
fn (mut f Fmt) debugger_stmt(node ast.DebuggerStmt)
fn (Fmt) dump_expr #
fn (mut f Fmt) dump_expr(node ast.DumpExpr)
fn (Fmt) enum_decl #
fn (mut f Fmt) enum_decl(node ast.EnumDecl)
fn (Fmt) enum_val #
fn (mut f Fmt) enum_val(node ast.EnumVal)
fn (Fmt) expr #
fn (mut f Fmt) expr(node_ ast.Expr)
=== General Expr-related methods and helpers ===//
fn (Fmt) expr_stmt #
fn (mut f Fmt) expr_stmt(node ast.ExprStmt)
fn (Fmt) fn_decl #
fn (mut f Fmt) fn_decl(node ast.FnDecl)
fn (Fmt) fn_type_decl #
fn (mut f Fmt) fn_type_decl(node ast.FnTypeDecl)
fn (Fmt) for_c_stmt #
fn (mut f Fmt) for_c_stmt(node ast.ForCStmt)
fn (Fmt) for_in_stmt #
fn (mut f Fmt) for_in_stmt(node ast.ForInStmt)
fn (Fmt) for_stmt #
fn (mut f Fmt) for_stmt(node ast.ForStmt)
fn (Fmt) get_source_lines #
fn (mut f Fmt) get_source_lines() []string
fn (Fmt) global_decl #
fn (mut f Fmt) global_decl(node ast.GlobalDecl)
fn (Fmt) go_expr #
fn (mut f Fmt) go_expr(node ast.GoExpr)
fn (Fmt) goto_label #
fn (mut f Fmt) goto_label(node ast.GotoLabel)
fn (Fmt) goto_stmt #
fn (mut f Fmt) goto_stmt(node ast.GotoStmt)
fn (Fmt) hash_stmt #
fn (mut f Fmt) hash_stmt(node ast.HashStmt)
fn (Fmt) ident #
fn (mut f Fmt) ident(node ast.Ident)
fn (Fmt) if_expr #
fn (mut f Fmt) if_expr(node ast.IfExpr)
fn (Fmt) if_guard_expr #
fn (mut f Fmt) if_guard_expr(node ast.IfGuardExpr)
fn (Fmt) imp_stmt_str #
fn (f &Fmt) imp_stmt_str(imp ast.Import) string
fn (Fmt) import_comments #
fn (mut f Fmt) import_comments(comments []ast.Comment, options CommentsOptions)
fn (Fmt) imports #
fn (mut f Fmt) imports(imports []ast.Import)
fn (Fmt) index_expr #
fn (mut f Fmt) index_expr(node ast.IndexExpr)
fn (Fmt) infix_expr #
fn (mut f Fmt) infix_expr(node ast.InfixExpr)
fn (Fmt) interface_decl #
fn (mut f Fmt) interface_decl(node ast.InterfaceDecl)
fn (Fmt) interface_field #
fn (mut f Fmt) interface_field(field ast.StructField, mut type_align FieldAlign, mut comment_align FieldAlign)
fn (Fmt) interface_method #
fn (mut f Fmt) interface_method(method ast.FnDecl, mut comment_align FieldAlign)
fn (Fmt) is_ref_type #
fn (mut f Fmt) is_ref_type(node ast.IsRefType)
fn (Fmt) likely #
fn (mut f Fmt) likely(node ast.Likely)
fn (Fmt) lock_expr #
fn (mut f Fmt) lock_expr(node ast.LockExpr)
fn (Fmt) map_init #
fn (mut f Fmt) map_init(node ast.MapInit)
fn (Fmt) mark_import_as_used #
fn (mut f Fmt) mark_import_as_used(name string)
fn (Fmt) mark_types_import_as_used #
fn (mut f Fmt) mark_types_import_as_used(typ ast.Type)
=== Import-related methods ===//
fn (Fmt) match_expr #
fn (mut f Fmt) match_expr(node ast.MatchExpr)
fn (Fmt) module_stmt #
fn (mut f Fmt) module_stmt(mod ast.Module)
fn (Fmt) no_cur_mod #
fn (mut f Fmt) no_cur_mod(typename string) string
fn (Fmt) node_str #
fn (mut f Fmt) node_str(node ast.Node) string
fn (Fmt) offset_of #
fn (mut f Fmt) offset_of(node ast.OffsetOf)
fn (Fmt) or_expr #
fn (mut f Fmt) or_expr(node ast.OrExpr)
fn (Fmt) par_expr #
fn (mut f Fmt) par_expr(node ast.ParExpr)
fn (Fmt) postfix_expr #
fn (mut f Fmt) postfix_expr(node ast.PostfixExpr)
fn (Fmt) prefix_expr #
fn (mut f Fmt) prefix_expr(node ast.PrefixExpr)
fn (Fmt) process_file_imports #
fn (mut f Fmt) process_file_imports(file &ast.File)
fn (Fmt) range_expr #
fn (mut f Fmt) range_expr(node ast.RangeExpr)
fn (Fmt) remove_new_line #
fn (mut f Fmt) remove_new_line(cfg RemoveNewLineConfig) string
When the removal action actually occurs, the string of the last line after the removal is returned
fn (Fmt) return_stmt #
fn (mut f Fmt) return_stmt(node ast.Return)
fn (Fmt) select_expr #
fn (mut f Fmt) select_expr(node ast.SelectExpr)
fn (Fmt) selector_expr #
fn (mut f Fmt) selector_expr(node ast.SelectorExpr)
fn (Fmt) set_current_module_name #
fn (mut f Fmt) set_current_module_name(cmodname string)
=== Module handling helper methods ===//
fn (Fmt) short_module #
fn (mut f Fmt) short_module(name string) string
foo.bar.fn() => bar.fn()
fn (Fmt) single_line_attrs #
fn (mut f Fmt) single_line_attrs(attrs []ast.Attr, options AttrsOptions)
fn (Fmt) size_of #
fn (mut f Fmt) size_of(node ast.SizeOf)
fn (Fmt) spawn_expr #
fn (mut f Fmt) spawn_expr(node ast.SpawnExpr)
fn (Fmt) sql_expr #
fn (mut f Fmt) sql_expr(node ast.SqlExpr)
fn (Fmt) sql_stmt #
fn (mut f Fmt) sql_stmt(node ast.SqlStmt)
fn (Fmt) sql_stmt_line #
fn (mut f Fmt) sql_stmt_line(node ast.SqlStmtLine)
fn (Fmt) stmt #
fn (mut f Fmt) stmt(node ast.Stmt)
fn (Fmt) stmts #
fn (mut f Fmt) stmts(stmts []ast.Stmt)
=== General Stmt-related methods and helpers ===//
fn (Fmt) string_inter_literal #
fn (mut f Fmt) string_inter_literal(node ast.StringInterLiteral)
fn (Fmt) string_literal #
fn (mut f Fmt) string_literal(node ast.StringLiteral)
fn (Fmt) struct_decl #
fn (mut f Fmt) struct_decl(node ast.StructDecl, is_anon bool)
fn (Fmt) struct_init #
fn (mut f Fmt) struct_init(node ast.StructInit)
fn (Fmt) sum_type_decl #
fn (mut f Fmt) sum_type_decl(node ast.SumTypeDecl)
fn (Fmt) type_decl #
fn (mut f Fmt) type_decl(node ast.TypeDecl)
fn (Fmt) type_expr #
fn (mut f Fmt) type_expr(node ast.TypeNode)
fn (Fmt) type_of #
fn (mut f Fmt) type_of(node ast.TypeOf)
fn (Fmt) unsafe_expr #
fn (mut f Fmt) unsafe_expr(node ast.UnsafeExpr)
fn (Fmt) vfmt_off #
fn (mut f Fmt) vfmt_off(off_line int)
fn (Fmt) vfmt_on #
fn (mut f Fmt) vfmt_on(on_line int)
fn (Fmt) wrap_infix #
fn (mut f Fmt) wrap_infix(start_pos int, start_len int, is_cond bool)
fn (Fmt) wrap_long_line #
fn (mut f Fmt) wrap_long_line(penalty_idx int, add_indent bool) bool
fn (Fmt) write #
fn (mut f Fmt) write(s string)
=== Basic buffer write operations ===//
fn (Fmt) writeln #
fn (mut f Fmt) writeln(s string)
struct FmtOptions #
@[params]
struct FmtOptions {
pub:
source_text string
}
struct RemoveNewLineConfig #
@[params]
struct RemoveNewLineConfig {
pub:
imports_buffer bool // Work on f.out_imports instead of f.out
}
- fn fmt
- enum CommentsLevel
- struct AttrsOptions
- struct CommentsOptions
- struct Fmt
- fn alias_type_decl
- fn anon_fn
- fn array_decompose
- fn array_init
- fn as_cast
- fn assert_stmt
- fn assign_stmt
- fn assoc
- fn at_expr
- fn attrs
- fn block
- fn branch_stmt
- fn calculate_alignment
- fn call_args
- fn call_expr
- fn cast_expr
- fn chan_init
- fn char_literal
- fn comment
- fn comments
- fn comments_after_last_field
- fn comments_before_field
- fn comptime_call
- fn comptime_for
- fn comptime_selector
- fn concat_expr
- fn const_decl
- fn debugger_stmt
- fn dump_expr
- fn enum_decl
- fn enum_val
- fn expr
- fn expr_stmt
- fn fn_decl
- fn fn_type_decl
- fn for_c_stmt
- fn for_in_stmt
- fn for_stmt
- fn get_source_lines
- fn global_decl
- fn go_expr
- fn goto_label
- fn goto_stmt
- fn hash_stmt
- fn ident
- fn if_expr
- fn if_guard_expr
- fn imp_stmt_str
- fn import_comments
- fn imports
- fn index_expr
- fn infix_expr
- fn interface_decl
- fn interface_field
- fn interface_method
- fn is_ref_type
- fn likely
- fn lock_expr
- fn map_init
- fn mark_import_as_used
- fn mark_types_import_as_used
- fn match_expr
- fn module_stmt
- fn no_cur_mod
- fn node_str
- fn offset_of
- fn or_expr
- fn par_expr
- fn postfix_expr
- fn prefix_expr
- fn process_file_imports
- fn range_expr
- fn remove_new_line
- fn return_stmt
- fn select_expr
- fn selector_expr
- fn set_current_module_name
- fn short_module
- fn single_line_attrs
- fn size_of
- fn spawn_expr
- fn sql_expr
- fn sql_stmt
- fn sql_stmt_line
- fn stmt
- fn stmts
- fn string_inter_literal
- fn string_literal
- fn struct_decl
- fn struct_init
- fn sum_type_decl
- fn type_decl
- fn type_expr
- fn type_of
- fn unsafe_expr
- fn vfmt_off
- fn vfmt_on
- fn wrap_infix
- fn wrap_long_line
- fn write
- fn writeln
- struct FmtOptions
- struct RemoveNewLineConfig