fmt: fix import aliases in type declarations (#9483)
parent
cbf4715804
commit
cd74273869
|
@ -118,10 +118,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
||||||
mut default_expr_aligns := []CommentAndExprAlignInfo{}
|
mut default_expr_aligns := []CommentAndExprAlignInfo{}
|
||||||
mut field_types := []string{cap: node.fields.len}
|
mut field_types := []string{cap: node.fields.len}
|
||||||
for i, field in node.fields {
|
for i, field in node.fields {
|
||||||
mut ft := f.no_cur_mod(f.table.type_to_str_using_aliases(field.typ, f.mod2alias))
|
ft := f.no_cur_mod(f.table.type_to_str_using_aliases(field.typ, f.mod2alias))
|
||||||
if !ft.contains('C.') && !ft.contains('JS.') && !ft.contains('fn (') && !ft.contains('chan') {
|
|
||||||
ft = f.short_module(ft)
|
|
||||||
}
|
|
||||||
field_types << ft
|
field_types << ft
|
||||||
attrs_len := inline_attrs_len(field.attrs)
|
attrs_len := inline_attrs_len(field.attrs)
|
||||||
end_pos := field.pos.pos + field.pos.len
|
end_pos := field.pos.pos + field.pos.len
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import os
|
import os
|
||||||
import time as t
|
import time as t
|
||||||
|
import some.library as slib
|
||||||
|
|
||||||
|
type my_alias = fn (t slib.MyType)
|
||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
bar t.Time
|
bar t.Time
|
||||||
|
|
|
@ -922,8 +922,16 @@ fn (t Table) shorten_user_defined_typenames(originalname string, import_aliases
|
||||||
} else {
|
} else {
|
||||||
// types defined by the user
|
// types defined by the user
|
||||||
// mod.submod.submod2.Type => submod2.Type
|
// mod.submod.submod2.Type => submod2.Type
|
||||||
parts := res.split('.')
|
mut parts := res.split('.')
|
||||||
res = if parts.len > 1 { parts[parts.len - 2..].join('.') } else { parts[0] }
|
if parts.len > 1 {
|
||||||
|
ind := parts.len - 2
|
||||||
|
if parts[ind] in import_aliases {
|
||||||
|
parts[ind] = import_aliases[parts[ind]]
|
||||||
|
}
|
||||||
|
res = parts[ind..].join('.')
|
||||||
|
} else {
|
||||||
|
res = parts[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue