mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
align not mutable correctly
This commit is contained in:
@@ -449,6 +449,7 @@ align_var_decls :: proc(p: ^Printer) {
|
|||||||
|
|
||||||
current_line: int;
|
current_line: int;
|
||||||
current_typed: bool;
|
current_typed: bool;
|
||||||
|
current_not_mutable: bool;
|
||||||
|
|
||||||
largest_lhs := 0;
|
largest_lhs := 0;
|
||||||
largest_rhs := 0;
|
largest_rhs := 0;
|
||||||
@@ -470,17 +471,31 @@ align_var_decls :: proc(p: ^Printer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typed := true;
|
typed := true;
|
||||||
|
not_mutable := false;
|
||||||
|
continue_flag := false;
|
||||||
|
|
||||||
for i := 0; i < len(line.format_tokens) - 1; i += 1 {
|
for i := 0; i < len(line.format_tokens) - 1; i += 1 {
|
||||||
if line.format_tokens[i].kind == .Colon && line.format_tokens[i + 1].kind == .Eq {
|
if line.format_tokens[i].kind == .Colon && line.format_tokens[i + 1].kind == .Eq {
|
||||||
typed = false;
|
typed = false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if line.format_tokens[i].kind == .Colon && line.format_tokens[i + 1].kind == .Colon {
|
||||||
|
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 {
|
||||||
|
continue_flag = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if line_index != current_line + 1 || typed != current_typed {
|
if continue_flag {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if p.config.align_style == .Align_On_Colon_And_Equals || !current_typed {
|
if line_index != current_line + 1 || typed != current_typed || not_mutable != 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 {
|
||||||
colon_token.format_token.spaces_before = largest_lhs - colon_token.length + 1;
|
colon_token.format_token.spaces_before = largest_lhs - colon_token.length + 1;
|
||||||
}
|
}
|
||||||
@@ -507,6 +522,7 @@ align_var_decls :: proc(p: ^Printer) {
|
|||||||
largest_rhs = 0;
|
largest_rhs = 0;
|
||||||
largest_lhs = 0;
|
largest_lhs = 0;
|
||||||
current_typed = typed;
|
current_typed = typed;
|
||||||
|
current_not_mutable = not_mutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_line = line_index;
|
current_line = line_index;
|
||||||
@@ -549,7 +565,7 @@ align_var_decls :: proc(p: ^Printer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//repeating myself, move to sub procedure
|
//repeating myself, move to sub procedure
|
||||||
if p.config.align_style == .Align_On_Colon_And_Equals || !current_typed {
|
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 {
|
||||||
colon_token.format_token.spaces_before = largest_lhs - colon_token.length + 1;
|
colon_token.format_token.spaces_before = largest_lhs - colon_token.length + 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -424,11 +424,12 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
|
|||||||
|
|
||||||
visit_exprs(p, v.names, true);
|
visit_exprs(p, v.names, true);
|
||||||
|
|
||||||
|
hint_current_line(p, {.Value_Decl});
|
||||||
|
|
||||||
if v.type != nil {
|
if v.type != nil {
|
||||||
if !v.is_mutable {
|
if !v.is_mutable {
|
||||||
push_generic_token(p, .Colon, 0);
|
push_generic_token(p, .Colon, 0);
|
||||||
} else {
|
} else {
|
||||||
hint_current_line(p, {.Value_Decl});
|
|
||||||
push_generic_token(p, .Colon, 0);
|
push_generic_token(p, .Colon, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,7 +439,6 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
|
|||||||
push_generic_token(p, .Colon, 1);
|
push_generic_token(p, .Colon, 1);
|
||||||
push_generic_token(p, .Colon, 0);
|
push_generic_token(p, .Colon, 0);
|
||||||
} else {
|
} else {
|
||||||
hint_current_line(p, {.Value_Decl});
|
|
||||||
push_generic_token(p, .Colon, 1);
|
push_generic_token(p, .Colon, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user