mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
fix proc group, struct align with internal structs
This commit is contained in:
@@ -483,7 +483,10 @@ align_var_decls :: proc(p: ^Printer) {
|
|||||||
not_mutable = true;
|
not_mutable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if tokenizer.Token_Kind.B_Keyword_Begin <= line.format_tokens[i].kind && line.format_tokens[i].kind <= tokenizer.Token_Kind.B_Keyword_End {
|
if line.format_tokens[i].kind == tokenizer.Token_Kind.Proc ||
|
||||||
|
line.format_tokens[i].kind == tokenizer.Token_Kind.Union ||
|
||||||
|
line.format_tokens[i].kind == tokenizer.Token_Kind.Enum ||
|
||||||
|
line.format_tokens[i].kind == tokenizer.Token_Kind.Struct {
|
||||||
continue_flag = true;
|
continue_flag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -496,6 +499,7 @@ align_var_decls :: proc(p: ^Printer) {
|
|||||||
|
|
||||||
if p.config.align_style == .Align_On_Colon_And_Equals || !current_typed || current_not_mutable {
|
if p.config.align_style == .Align_On_Colon_And_Equals || !current_typed || current_not_mutable {
|
||||||
for colon_token in colon_tokens {
|
for colon_token in colon_tokens {
|
||||||
|
fmt.println(colon_token);
|
||||||
colon_token.format_token.spaces_before = largest_lhs - colon_token.length + 1;
|
colon_token.format_token.spaces_before = largest_lhs - colon_token.length + 1;
|
||||||
}
|
}
|
||||||
} else if p.config.align_style == .Align_On_Type_And_Equals {
|
} else if p.config.align_style == .Align_On_Type_And_Equals {
|
||||||
@@ -703,7 +707,7 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
largest := 0;
|
largest := 0;
|
||||||
comma_count := 0;
|
comma_count := 0;
|
||||||
|
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
for line, line_index in p.lines[brace_line + 1:] {
|
||||||
@@ -781,30 +785,14 @@ align_struct :: proc(p: ^Printer, index: int) {
|
|||||||
|
|
||||||
largest := 0;
|
largest := 0;
|
||||||
colon_count := 0;
|
colon_count := 0;
|
||||||
|
seen_brace := false;
|
||||||
|
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
TokenAndLength :: struct {
|
||||||
length := 0;
|
format_token: ^Format_Token,
|
||||||
|
length: int,
|
||||||
|
};
|
||||||
|
|
||||||
for format_token in line.format_tokens {
|
format_tokens := make([] TokenAndLength, brace_token.parameter_count, context.temp_allocator);
|
||||||
if format_token.kind == .Comment {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if format_token.kind == .Colon {
|
|
||||||
colon_count += 1;
|
|
||||||
largest = max(length, largest);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
length += len(format_token.text) + format_token.spaces_before;
|
|
||||||
}
|
|
||||||
|
|
||||||
if colon_count >= brace_token.parameter_count {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
colon_count = 0;
|
|
||||||
|
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
for line, line_index in p.lines[brace_line + 1:] {
|
||||||
length := 0;
|
length := 0;
|
||||||
@@ -812,12 +800,18 @@ align_struct :: proc(p: ^Printer, index: int) {
|
|||||||
for format_token, i in line.format_tokens {
|
for format_token, i in line.format_tokens {
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
continue;
|
continue;
|
||||||
|
} else if format_token.kind == .Open_Brace {
|
||||||
|
seen_brace = true;
|
||||||
|
} else if format_token.kind == .Close_Brace {
|
||||||
|
seen_brace = false;
|
||||||
|
} else if seen_brace {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if format_token.kind == .Colon {
|
if format_token.kind == .Colon {
|
||||||
|
format_tokens[colon_count] = { format_token = &line.format_tokens[i + 1], length = length };
|
||||||
colon_count += 1;
|
colon_count += 1;
|
||||||
line.format_tokens[i + 1].spaces_before = largest - length + 1;
|
largest = max(length, largest);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
length += len(format_token.text) + format_token.spaces_before;
|
length += len(format_token.text) + format_token.spaces_before;
|
||||||
@@ -827,6 +821,11 @@ align_struct :: proc(p: ^Printer, index: int) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for token in format_tokens {
|
||||||
|
token.format_token.spaces_before = largest - token.length + 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
align_comments :: proc(p: ^Printer) {
|
align_comments :: proc(p: ^Printer) {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ sort_attribute :: proc(s: ^[dynamic]^ast.Attribute) -> sort.Interface {
|
|||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
comment_before_position :: proc(p: ^Printer, pos: tokenizer.Pos) -> bool {
|
comment_before_position :: proc(p: ^Printer, pos: tokenizer.Pos) -> bool {
|
||||||
|
|
||||||
if len(p.comments) <= p.latest_comment_index {
|
if len(p.comments) <= p.latest_comment_index {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ comment_before_position :: proc(p: ^Printer, pos: tokenizer.Pos) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
next_comment_group :: proc(p: ^Printer) {
|
next_comment_group :: proc(p: ^Printer) {
|
||||||
p.latest_comment_index += 1;
|
p.latest_comment_index += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ push_comment :: proc(p: ^Printer, comment: tokenizer.Token) -> int {
|
|||||||
|
|
||||||
builder := strings.make_builder(context.temp_allocator);
|
builder := strings.make_builder(context.temp_allocator);
|
||||||
|
|
||||||
c_len := len(comment.text);
|
c_len := len(comment.text);
|
||||||
trim_space := true;
|
trim_space := true;
|
||||||
|
|
||||||
multilines: [dynamic]string;
|
multilines: [dynamic]string;
|
||||||
@@ -157,7 +157,7 @@ push_comment :: proc(p: ^Printer, comment: tokenizer.Token) -> int {
|
|||||||
@(private)
|
@(private)
|
||||||
push_comments :: proc(p: ^Printer, pos: tokenizer.Pos) {
|
push_comments :: proc(p: ^Printer, pos: tokenizer.Pos) {
|
||||||
|
|
||||||
prev_comment: ^tokenizer.Token;
|
prev_comment: ^tokenizer.Token;
|
||||||
prev_comment_lines: int;
|
prev_comment_lines: int;
|
||||||
|
|
||||||
for comment_before_position(p, pos) {
|
for comment_before_position(p, pos) {
|
||||||
@@ -1141,7 +1141,7 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr) {
|
|||||||
push_generic_token(p, .Close_Bracket, 0);
|
push_generic_token(p, .Close_Bracket, 0);
|
||||||
case Proc_Group:
|
case Proc_Group:
|
||||||
|
|
||||||
push_generic_token(p, v.tok.kind, 0);
|
push_generic_token(p, v.tok.kind, 1);
|
||||||
|
|
||||||
if len(v.args) != 0 && v.pos.line != v.args[len(v.args) - 1].pos.line {
|
if len(v.args) != 0 && v.pos.line != v.args[len(v.args) - 1].pos.line {
|
||||||
visit_begin_brace(p, v.pos, .Generic);
|
visit_begin_brace(p, v.pos, .Generic);
|
||||||
@@ -1354,7 +1354,7 @@ visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type) {
|
|||||||
push_generic_token(p, .Gt, 0);
|
push_generic_token(p, .Gt, 0);
|
||||||
|
|
||||||
use_parens := false;
|
use_parens := false;
|
||||||
use_named := false;
|
use_named := false;
|
||||||
|
|
||||||
if len(proc_type.results.list) > 1 {
|
if len(proc_type.results.list) > 1 {
|
||||||
use_parens = true;
|
use_parens = true;
|
||||||
@@ -1497,4 +1497,4 @@ visit_signature_list :: proc(p: ^Printer, list: ^ast.Field_List, remove_blank :=
|
|||||||
push_generic_token(p, .Comma, 0);
|
push_generic_token(p, .Comma, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user