From 6070844d69cab5b4a5bb50473bd6ccc2343ff7dd Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Tue, 21 Jun 2022 23:22:40 +0200 Subject: Add new json variable for picking the space amount --- src/server/format.odin | 1 + 1 file changed, 1 insertion(+) (limited to 'src/server') diff --git a/src/server/format.odin b/src/server/format.odin index 4c51943..3cf8de6 100644 --- a/src/server/format.odin +++ b/src/server/format.odin @@ -21,6 +21,7 @@ get_complete_format :: proc(document: ^common.Document, config: ^common.Config) style := printer.default_style style.max_characters = config.formatter.characters style.tabs = config.formatter.tabs + style.spaces = config.formatter.spaces prnt := printer.make_printer(style, context.temp_allocator) -- cgit v1.2.3 From b0e274b53936eac2c751d3d04a7b1bcd432cfe91 Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Wed, 22 Jun 2022 00:08:21 +0200 Subject: Use the default values if not specified in json --- src/server/format.odin | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/server') diff --git a/src/server/format.odin b/src/server/format.odin index 3cf8de6..0035545 100644 --- a/src/server/format.odin +++ b/src/server/format.odin @@ -19,10 +19,16 @@ DocumentFormattingParams :: struct { get_complete_format :: proc(document: ^common.Document, config: ^common.Config) -> ([]TextEdit, bool) { style := printer.default_style - style.max_characters = config.formatter.characters style.tabs = config.formatter.tabs - style.spaces = config.formatter.spaces + if characters, ok := config.formatter.characters.(int); ok { + style.max_characters = characters + } + + if spaces, ok := config.formatter.spaces.(int); ok { + style.spaces = spaces + } + prnt := printer.make_printer(style, context.temp_allocator) if document.ast.syntax_error_count > 0 { -- cgit v1.2.3 From 352221c8688e47364b0fa6c4e436f3e0a2dfc131 Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Tue, 28 Jun 2022 22:43:40 +0200 Subject: odinfmt: fix proc tags being printed --- src/odin/printer/visit.odin | 53 +++++++++++++++++++++++++++++++++++++++------ src/server/analysis.odin | 12 +++++++++- src/server/format.odin | 7 ++++-- 3 files changed, 62 insertions(+), 10 deletions(-) (limited to 'src/server') diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index fccecf6..98ab030 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -424,7 +424,7 @@ visit_union_exprs :: proc(p: ^Printer, union_type: ast.Union_Type, options := Li for expr, i in union_type.variants { if i == 0 && .Enforce_Newline in options { - comment, ok := visit_comments(p, union_type.variants[i].pos) + comment, ok := visit_comments(p, union_type.variants[i].pos) if _, is_nil := comment.(Document_Nil); !is_nil { comment = cons(comment, newline(1)) } @@ -533,6 +533,9 @@ visit_state_flags :: proc(p: ^Printer, flags: ast.Node_State_Flags) -> ^Document if .No_Bounds_Check in flags { return cons(text("#no_bounds_check"), break_with_no_newline()) } + if .Bounds_Check in flags { + return cons(text("#bounds_check"), break_with_no_newline()) + } return empty() } @@ -703,11 +706,18 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener assign_document := group(cons_with_nopl(visit_exprs(p, v.lhs, {.Add_Comma, .Glue}), text(v.op.text))) if block_stmt { - assign_document = cons_with_opl(assign_document, group(visit_exprs(p, v.rhs, {.Add_Comma}, .Assignment_Stmt))) + if is_values_binary(p, v.rhs) { + document = group(nest(p.indentation_count, cons_with_opl(assign_document, group(visit_exprs(p, v.rhs, {.Add_Comma}, .Assignment_Stmt))))) + } else { + document = cons_with_nopl(assign_document, group(visit_exprs(p, v.rhs, {.Add_Comma}, .Assignment_Stmt))) + } } else { - assign_document = cons_with_nopl(assign_document, group(visit_exprs(p, v.rhs, {.Add_Comma}, .Assignment_Stmt))) + if is_values_binary(p, v.rhs) { + document = group(nest(p.indentation_count, cons_with_opl(assign_document, group(visit_exprs(p, v.rhs, {.Add_Comma}, .Assignment_Stmt))))) + } else { + document = cons_with_nopl(assign_document, group(visit_exprs(p, v.rhs, {.Add_Comma}, .Assignment_Stmt))) + } } - document = cons(document, group(nest(p.indentation_count, assign_document))) case ^Expr_Stmt: document = cons(document, visit_expr(p, v.expr)) case ^For_Stmt: @@ -1251,7 +1261,10 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, called_from: Expr_Called_Type = document = cons(document, text("]")) document = cons(document, visit_expr(p, v.value)) case ^Helper_Type: - document = visit_expr(p, v.type) + if v.tok == .Hash { + document = cons(document, text("#type")) + } + document = cons_with_nopl(document, visit_expr(p, v.type)) case ^Matrix_Type: document = text_position(p, "matrix", v.pos) document = cons(document, text("[")) @@ -1441,6 +1454,29 @@ visit_field_list :: proc(p: ^Printer, list: ^ast.Field_List, options := List_Opt return document } +@(private) +visit_proc_tags :: proc(p: ^Printer, proc_tags: ast.Proc_Tags) -> ^Document { + document := empty() + + if .Bounds_Check in proc_tags { + document = cons_with_opl(document, text("#bounds_check")) + } + + if .No_Bounds_Check in proc_tags { + document = cons_with_opl(document, text("#no_bounds_check")) + } + + if .Optional_Ok in proc_tags { + document = cons_with_opl(document, text("#optional_ok")) + } + + if .Optional_Second in proc_tags { + document = cons_with_opl(document, text("#optional_second")) + } + + return document +} + @(private) visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type) -> ^Document { document := text("proc") @@ -1492,6 +1528,8 @@ visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type) -> ^Document { document = cons_with_nopl(document, text("!")) } + document = cons_with_opl(document, visit_proc_tags(p, proc_type.tags)) + return document } @@ -1511,11 +1549,12 @@ visit_binary_expr :: proc(p: ^Printer, binary: ast.Binary_Expr, first := false) } } - if first { + if true { if nest_first_expression { document = nest(p.indentation_count, document) + document = group(document) } - document = group(document) + } document = cons_with_nopl(document, text(binary.op.text)) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 5c40e7e..c22c1e8 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1785,8 +1785,18 @@ make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type, symbol.name = "union" } + types := make([dynamic]^ast.Expr, ast_context.allocator) + + for variant in v.variants { + if v.poly_params != nil { + append(&types, clone_type(variant, ast_context.allocator, nil)) + } else { + append(&types, variant) + } + } + symbol.value = SymbolUnionValue { - types = v.variants, + types = types[:], } if v.poly_params != nil { diff --git a/src/server/format.odin b/src/server/format.odin index 0035545..219d7d9 100644 --- a/src/server/format.odin +++ b/src/server/format.odin @@ -1,9 +1,10 @@ package server import "shared:common" - import "shared:odin/printer" +import "core:log" + FormattingOptions :: struct { tabSize: uint, insertSpaces: bool, //tabs or spaces @@ -41,7 +42,9 @@ get_complete_format :: proc(document: ^common.Document, config: ^common.Config) src := printer.print(&prnt, &document.ast) - end_line := 0 + log.error(src) + + end_line := 0 end_charcter := 0 last := document.text[0] -- cgit v1.2.3 From 9b19888219305c3740f36d9490e08e04e148a413 Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Wed, 29 Jun 2022 23:09:14 +0200 Subject: Remove Maybe for now because json serialization messes it up. --- src/common/config.odin | 4 ++-- src/server/format.odin | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/server') diff --git a/src/common/config.odin b/src/common/config.odin index c510e57..d90e5fa 100644 --- a/src/common/config.odin +++ b/src/common/config.odin @@ -27,8 +27,8 @@ Config :: struct { Format_Config :: struct { tabs: bool, - characters: Maybe(int), - spaces: Maybe(int), + characters: int, + spaces: int, } config: Config; \ No newline at end of file diff --git a/src/server/format.odin b/src/server/format.odin index 219d7d9..041b204 100644 --- a/src/server/format.odin +++ b/src/server/format.odin @@ -22,12 +22,12 @@ get_complete_format :: proc(document: ^common.Document, config: ^common.Config) style := printer.default_style style.tabs = config.formatter.tabs - if characters, ok := config.formatter.characters.(int); ok { - style.max_characters = characters + if config.formatter.characters != 0 { + style.max_characters = config.formatter.characters } - if spaces, ok := config.formatter.spaces.(int); ok { - style.spaces = spaces + if config.formatter.spaces != 0 { + style.spaces = config.formatter.spaces } prnt := printer.make_printer(style, context.temp_allocator) -- cgit v1.2.3