diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index afa479944f..351ff603fb 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -23,6 +23,7 @@ mut: empty_line bool line_len int single_line_if bool + cur_mod string } pub fn fmt(file ast.File, table &table.Table) string { @@ -63,6 +64,7 @@ fn (f mut Fmt) mod(mod ast.Module) { if mod.name != 'main' { f.writeln('module ${mod.name}\n') } + f.cur_mod = mod.name } fn (f mut Fmt) imports(imports []ast.Import) { @@ -197,11 +199,16 @@ fn (f mut Fmt) struct_decl(node ast.StructDecl) { for field in node.fields { f.write('\t$field.name ') f.write(strings.repeat(` `, max - field.name.len)) - f.writeln(f.table.type_to_str(field.typ)) + f.writeln(f.type_to_str(field.typ)) } f.writeln('}\n') } +fn (f &Fmt) type_to_str(t table.Type) string { + res := f.table.type_to_str(t) + return res.replace(f.cur_mod + '.', '') +} + fn (f mut Fmt) expr(node ast.Expr) { match node { ast.ArrayInit { diff --git a/vlib/v/table/atype_symbols.v b/vlib/v/table/atype_symbols.v index 4a91298c97..64d9423321 100644 --- a/vlib/v/table/atype_symbols.v +++ b/vlib/v/table/atype_symbols.v @@ -400,6 +400,13 @@ pub mut: pub fn (table &Table) type_to_str(t Type) string { sym := table.get_type_symbol(t) mut res := sym.name.replace('array_', '[]') + // mod.submod.submod2.Type => submod2.Type + if res.contains('.') { + vals := res.split('.') + if vals.len > 2 { + res = vals[vals.len - 2] + '.' + vals[vals.len - 1] + } + } if type_is_optional(t) { res = '?' + res } @@ -407,5 +414,11 @@ pub fn (table &Table) type_to_str(t Type) string { if nr_muls > 0 { res = strings.repeat(`&`, nr_muls) + res } + /* + if res.starts_with(cur_mod +'.') { + res = res[cur_mod.len+1.. ] + } + */ + return res }