mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: keep module alias in struct decl field types (#7305)
This commit is contained in:
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 {
|
||||
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
|
||||
if ft.len > max_type {
|
||||
max_type = ft.len
|
||||
@ -1290,13 +1293,13 @@ pub fn (mut f Fmt) short_module(name string) string {
|
||||
if vals.len < 2 {
|
||||
return name
|
||||
}
|
||||
mname := vals[vals.len - 2]
|
||||
mname, tprefix := f.get_modname_prefix(vals[vals.len - 2])
|
||||
symname := vals[vals.len - 1]
|
||||
aname := f.mod2alias[mname]
|
||||
if aname == '' {
|
||||
return symname
|
||||
}
|
||||
return '${aname}.$symname'
|
||||
return '$tprefix${aname}.$symname'
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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 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() {
|
||||
println('start')
|
||||
t.sleep_ms(500)
|
||||
|
Loading…
Reference in New Issue
Block a user