From c36984cc9435253b5f3ff2cc3e79feb87a1d85b6 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 13 Apr 2020 16:36:32 +0200 Subject: [PATCH] fmt: handle indents --- vlib/v/fmt/fmt.v | 5 +++++ vlib/v/fmt/tests/import_multiple_expected.vv | 5 +++++ vlib/v/fmt/tests/import_multiple_input.vv | 5 +++++ vlib/v/fmt/tests/import_multiple_with_alias_expected.vv | 9 +++++++-- vlib/v/fmt/tests/import_multiple_with_alias_input.vv | 9 +++++++-- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 2ca92a6099..572a0d1bfa 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -529,7 +529,11 @@ fn (f mut Fmt) expr(node ast.Expr) { f.write('_') } else { name := short_module(it.name) + //f.write('<$it.name => $name>') f.write(name) + if name.contains('.') { + f.mark_module_as_used(name) + } } } ast.InfixExpr { @@ -669,6 +673,7 @@ fn (f mut Fmt) expr(node ast.Expr) { } ast.StructInit { type_sym := f.table.get_type_symbol(it.typ) + //f.write('') mut name := short_module(type_sym.name).replace(f.cur_mod + '.', '') // TODO f.type_to_str? if name == 'void' { name = '' diff --git a/vlib/v/fmt/tests/import_multiple_expected.vv b/vlib/v/fmt/tests/import_multiple_expected.vv index 2bb2bf691a..1fcc0a0244 100644 --- a/vlib/v/fmt/tests/import_multiple_expected.vv +++ b/vlib/v/fmt/tests/import_multiple_expected.vv @@ -3,5 +3,10 @@ import ( os ) +const ( + mypi = math.pi +) + fn main() { + println(os.path_separator) } diff --git a/vlib/v/fmt/tests/import_multiple_input.vv b/vlib/v/fmt/tests/import_multiple_input.vv index eccd1049e2..5769710c0f 100644 --- a/vlib/v/fmt/tests/import_multiple_input.vv +++ b/vlib/v/fmt/tests/import_multiple_input.vv @@ -1,5 +1,10 @@ import math import os +const ( + mypi = math.pi +) + fn main() { + println(os.path_separator) } diff --git a/vlib/v/fmt/tests/import_multiple_with_alias_expected.vv b/vlib/v/fmt/tests/import_multiple_with_alias_expected.vv index 55f87b91bb..3839113d42 100644 --- a/vlib/v/fmt/tests/import_multiple_with_alias_expected.vv +++ b/vlib/v/fmt/tests/import_multiple_with_alias_expected.vv @@ -1,8 +1,13 @@ import ( - math as m os - math.complex as c + math ) fn main() { + // println(m.pi) + println(os.path_separator) + println(math.pi) + // math as m + // import math.complex as c + // num := c.Complex{} TODO } diff --git a/vlib/v/fmt/tests/import_multiple_with_alias_input.vv b/vlib/v/fmt/tests/import_multiple_with_alias_input.vv index dec354c660..e2ee3220ce 100644 --- a/vlib/v/fmt/tests/import_multiple_with_alias_input.vv +++ b/vlib/v/fmt/tests/import_multiple_with_alias_input.vv @@ -1,6 +1,11 @@ -import math as m import os -import math.complex as c +import math fn main() { + // println(m.pi) + println(os.path_separator) + println(math.pi) + // math as m + // import math.complex as c + // num := c.Complex{} TODO }