diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index 164e6e7db7..3d38486864 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -112,15 +112,17 @@ fn convert_pos(file_path string, pos token.Position) DocPos { } } -pub fn (d Doc) get_signature(stmt ast.Stmt) string { +pub fn (d Doc) get_signature(stmt ast.Stmt, file &ast.File) string { mut f := fmt.Fmt{ out: strings.new_builder(1000) out_imports: strings.new_builder(200) table: d.table + file: file cur_mod: d.head.name.split('.').last() indent: 0 is_debug: false } + f.process_file_imports(file) match stmt { ast.Module { return 'module $it.name' @@ -331,7 +333,7 @@ pub fn (mut d Doc) generate() ?bool { if stmt is ast.Import { continue } - signature := d.get_signature(stmt) + signature := d.get_signature(stmt, file_ast) pos := d.get_pos(stmt) mut name := d.get_name(stmt) if (!signature.starts_with('pub') && d.pub_only) || stmt is ast.GlobalDecl { diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index cf13b3d389..58d9c777b0 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -45,9 +45,7 @@ pub fn fmt(file ast.File, table &table.Table, is_debug bool) string { file: file is_debug: is_debug } - for imp in file.imports { - f.mod2alias[imp.mod.all_after_last('.')] = imp.alias - } + f.process_file_imports(file) f.cur_mod = 'main' for stmt in file.stmts { if stmt is ast.Import { @@ -63,6 +61,12 @@ pub fn fmt(file ast.File, table &table.Table, is_debug bool) string { return res[..f.import_pos] + f.out_imports.str() + res[f.import_pos..] // + '\n' } +pub fn (mut f Fmt) process_file_imports(file &ast.File) { + for imp in file.imports { + f.mod2alias[imp.mod.all_after_last('.')] = imp.alias + } +} + /* fn (mut f Fmt) find_comment(line_nr int) { for comment in f.file.comments {