diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-08-20 18:05:41 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-08-20 18:05:41 +0200 |
| commit | f5fe104fd6662156c2cb219f24f17769af2d30e6 (patch) | |
| tree | ce46cf82281535b7ec633d666e29cf75072d28d1 | |
| parent | f6f2eb760d4b11630dc0719c8893383bed20cd9a (diff) | |
Fix `->` gotos and some odinfmt fixes
| -rw-r--r-- | src/common/position.odin | 53 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 4 | ||||
| -rw-r--r-- | src/server/analysis.odin | 23 | ||||
| -rw-r--r-- | src/server/format.odin | 28 |
4 files changed, 55 insertions, 53 deletions
diff --git a/src/common/position.odin b/src/common/position.odin index 5d2ae4f..b8f921d 100644 --- a/src/common/position.odin +++ b/src/common/position.odin @@ -107,28 +107,29 @@ get_relative_token_position :: proc( return position } +go_backwards_to_endline :: proc(offset: int, document_text: []u8) -> int { + index := offset + + for + index > 0 && + document_text[index] != '\n' && + document_text[index] != '\r' { + index -= 1 + } + + if index == 0 { + return 0 + } + + return index + 1 +} + /* Get the range of a token in utf16 space */ get_token_range :: proc(node: ast.Node, document_text: string) -> Range { range: Range - go_backwards_to_endline :: proc(offset: int, document_text: []u8) -> int { - index := offset - - for - index > 0 && - document_text[index] != '\n' && - document_text[index] != '\r' { - index -= 1 - } - - if index == 0 { - return 0 - } - - return index + 1 - } pos_offset := min(len(document_text) - 1, node.pos.offset) end_offset := min(len(document_text) - 1, node.end.offset) @@ -311,3 +312,23 @@ get_character_offset_u8_to_u16 :: proc( return utf16_idx } + +get_document_range :: proc(document_text: []u8) -> (range: Range) { + for current_index := 0; current_index < len(document_text); { + r, w := utf8.decode_rune(document_text[current_index:]) + + if r == '\n' { + range.end.line += 1 + range.end.character = 0 + } else if w == 0 { + return + } else if r < 0x10000 { + range.end.character += 1 + } else { + range.end.character += 2 + } + current_index += w + } + + return +} diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 134c4ee..c7c852e 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -1218,11 +1218,9 @@ visit_stmt :: proc( document = cons(document, text("return")) document = cons_with_nopl( document, - visit_exprs(p, v.results, {.Add_Comma}), + visit_exprs(p, v.results, {.Add_Comma, .Group}), ) } - - case ^Defer_Stmt: document = cons(document, text("defer")) document = cons_with_nopl(document, visit_stmt(p, v.stmt)) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 6113b63..e3bfb9a 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1400,12 +1400,14 @@ get_local_lhs_and_rhs :: proc( if _, ok := ast_context.parameters[ident.name]; ok { - return local_stack[i - - previous].lhs, local_stack[i - previous].rhs + return local_stack[ + i - previous \ + ].lhs, local_stack[i - previous].rhs } } - return local_stack[i - - previous].lhs, local_stack[i - previous].rhs + return local_stack[ + i - previous \ + ].lhs, local_stack[i - previous].rhs } } } @@ -4348,6 +4350,14 @@ get_document_position_node :: proc( } get_document_position(n.expr, position_context) get_document_position(n.args, position_context) + case ^Selector_Call_Expr: + if position_context.hint == .Definition || position_context.hint == .Hover { + position_context.selector = n.expr + position_context.field = n.call + position_context.selector_expr = cast(^Selector_Expr)node + get_document_position(n.expr, position_context) + get_document_position(n.call, position_context) + } case ^Selector_Expr: if position_context.hint == .Completion { if n.field != nil && @@ -4356,9 +4366,8 @@ get_document_position_node :: proc( //position_context.selector = n.expr; //position_context.field = n.field; } - } else if (position_context.hint == .Definition || - position_context.hint == .Hover) && - n.field != nil { + } else if position_context.hint == .Definition || + position_context.hint == .Hover && n.field != nil { position_context.selector = n.expr position_context.field = n.field position_context.selector_expr = cast(^Selector_Expr)node diff --git a/src/server/format.odin b/src/server/format.odin index cbb4082..d0c939b 100644 --- a/src/server/format.odin +++ b/src/server/format.odin @@ -42,35 +42,9 @@ get_complete_format :: proc( src := printer.print(&prnt, &document.ast) - log.error(src) - - end_line := 0 - end_charcter := 0 - - last := document.text[0] - line := 0 - - for current_index := 0; - current_index < len(document.text); - current_index += 1 { - current := document.text[current_index] - - if last == '\r' && current == '\n' { - line += 1 - current_index += 1 - } else if current == '\n' { - line += 1 - } - - last = current - } - edit := TextEdit { newText = src, - range = { - start = {character = 0, line = 0}, - end = {character = 1, line = line + 1}, - }, + range = common.get_document_range(document.text[0:document.used_text]), } edits := make([dynamic]TextEdit, context.temp_allocator) |