fmt: keep module alias in struct decl field types (#7305)
parent
d59c5b01e1
commit
9b139c58ca
|
@ -615,7 +615,10 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
||||||
if comments_len + field.name.len > max {
|
if comments_len + field.name.len > max {
|
||||||
max = comments_len + field.name.len
|
max = comments_len + field.name.len
|
||||||
}
|
}
|
||||||
ft := f.no_cur_mod(f.table.type_to_str(field.typ))
|
mut ft := f.no_cur_mod(f.table.type_to_str(field.typ))
|
||||||
|
if !ft.starts_with('C.') && !ft.starts_with('JS.') {
|
||||||
|
ft = f.short_module(ft)
|
||||||
|
}
|
||||||
field_types << ft
|
field_types << ft
|
||||||
if ft.len > max_type {
|
if ft.len > max_type {
|
||||||
max_type = ft.len
|
max_type = ft.len
|
||||||
|
@ -1290,13 +1293,13 @@ pub fn (mut f Fmt) short_module(name string) string {
|
||||||
if vals.len < 2 {
|
if vals.len < 2 {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
mname := vals[vals.len - 2]
|
mname, tprefix := f.get_modname_prefix(vals[vals.len - 2])
|
||||||
symname := vals[vals.len - 1]
|
symname := vals[vals.len - 1]
|
||||||
aname := f.mod2alias[mname]
|
aname := f.mod2alias[mname]
|
||||||
if aname == '' {
|
if aname == '' {
|
||||||
return symname
|
return symname
|
||||||
}
|
}
|
||||||
return '${aname}.$symname'
|
return '$tprefix${aname}.$symname'
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) lock_expr(lex ast.LockExpr) {
|
pub fn (mut f Fmt) lock_expr(lex ast.LockExpr) {
|
||||||
|
@ -1987,3 +1990,14 @@ fn (mut f Fmt) is_external_name(name string) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (f Fmt) get_modname_prefix(mname string) (string, string) {
|
||||||
|
// ./tests/proto_module_importing_vproto_keep.vv to know, why here is checked for ']' and '&'
|
||||||
|
if !mname.contains(']') && !mname.contains('&') {
|
||||||
|
return mname, ''
|
||||||
|
}
|
||||||
|
after_rbc := mname.all_after_last(']')
|
||||||
|
after_ref := mname.all_after_last('&')
|
||||||
|
modname := if after_rbc.len < after_ref.len { after_rbc } else { after_ref }
|
||||||
|
return modname, mname.trim_suffix(modname)
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
import os
|
import os
|
||||||
import time as t
|
import time as t
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
bar t.Time
|
||||||
|
bars []t.Time
|
||||||
|
barref &t.Time
|
||||||
|
barrefs []&t.Time
|
||||||
|
c_type C.some_struct
|
||||||
|
js_type JS.other_struct
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println('start')
|
println('start')
|
||||||
t.sleep_ms(500)
|
t.sleep_ms(500)
|
||||||
|
|
Loading…
Reference in New Issue