diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-10-25 00:02:21 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-10-25 00:02:21 +0200 |
| commit | 83c61f4f5f439b476855a3f5ca7e49c6ac0df465 (patch) | |
| tree | aeba655772843960a2e660256b2a0875246cf2e3 /src | |
| parent | ed1a43af18f4cce0cbe18b59e3265a9b495a381f (diff) | |
Improve smenatic token for distinct typing
Diffstat (limited to 'src')
| -rw-r--r-- | src/odin/printer/document.odin | 20 | ||||
| -rw-r--r-- | src/odin/printer/printer.odin | 12 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 36 | ||||
| -rw-r--r-- | src/server/analysis.odin | 12 | ||||
| -rw-r--r-- | src/server/collector.odin | 21 | ||||
| -rw-r--r-- | src/server/completion.odin | 24 | ||||
| -rw-r--r-- | src/server/documents.odin | 2 | ||||
| -rw-r--r-- | src/server/semantic_tokens.odin | 15 |
8 files changed, 83 insertions, 59 deletions
diff --git a/src/odin/printer/document.odin b/src/odin/printer/document.odin index 5ab8ea3..3dd9eda 100644 --- a/src/odin/printer/document.odin +++ b/src/odin/printer/document.odin @@ -43,8 +43,8 @@ Document_Break :: struct { Document_If_Break_Or :: struct { break_document: ^Document, - fit_document: ^Document, - group_id: string, + fit_document: ^Document, + group_id: string, } Document_Group :: struct { @@ -181,10 +181,7 @@ align :: proc( return document } -if_break :: proc( - value: string, - allocator := context.allocator, -) -> ^Document { +if_break :: proc(value: string, allocator := context.allocator) -> ^Document { return if_break_or_document(text(value, allocator), nil, "", allocator) } @@ -199,7 +196,12 @@ if_break_or_string :: proc( group_id := "", allocator := context.allocator, ) -> ^Document { - return if_break_or_document(text(break_value, allocator), text(fit_value, allocator), group_id, allocator) + return if_break_or_document( + text(break_value, allocator), + text(fit_value, allocator), + group_id, + allocator, + ) } if_break_or_document :: proc( @@ -211,8 +213,8 @@ if_break_or_document :: proc( document := new(Document, allocator) document^ = Document_If_Break_Or { break_document = break_document, - fit_document = fit_document, - group_id = group_id, + fit_document = fit_document, + group_id = group_id, } return document } diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin index dd724c9..d918cf2 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -31,10 +31,10 @@ Printer :: struct { } Disabled_Info :: struct { - text: string, - empty: bool, + text: string, + empty: bool, start_line: int, - end_line: int, + end_line: int, } Config :: struct { @@ -137,9 +137,9 @@ build_disabled_lines_info :: proc(p: ^Printer) { disabled_info := Disabled_Info { start_line = disable_position.line, - end_line = comment.pos.line, - text = p.src[begin:end], - empty = empty, + end_line = comment.pos.line, + text = p.src[begin:end], + empty = empty, } for line := disable_position.line; diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index b04fe1d..85ab6b7 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -990,7 +990,13 @@ visit_stmt :: proc( if v.init != nil { begin_document = cons_with_nopl( begin_document, - cons(group(visit_stmt(p, v.init), Document_Group_Options {id = "init"}), text(";")), + cons( + group( + visit_stmt(p, v.init), + Document_Group_Options{id = "init"}, + ), + text(";"), + ), ) } @@ -1006,14 +1012,26 @@ visit_stmt :: proc( } - - if v.init != nil && is_value_decl_statement_ending_with_call(v.init) || - v.cond != nil && - v.init == nil && - is_value_expression_call(v.cond) { - document = cons(document, group(cons(begin_document, if_break_or(end_document, hang(3, end_document), "init")))) - } else { - document = cons(document, group(hang(3, cons(begin_document, end_document)))) + if v.init != nil && is_value_decl_statement_ending_with_call(v.init) || + v.cond != nil && v.init == nil && is_value_expression_call(v.cond) { + document = cons( + document, + group( + cons( + begin_document, + if_break_or( + end_document, + hang(3, end_document), + "init", + ), + ), + ), + ) + } else { + document = cons( + document, + group(hang(3, cons(begin_document, end_document))), + ) } set_source_position(p, v.body.pos) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index e354d1d..1e32fe6 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1088,7 +1088,7 @@ internal_resolve_type_expression :: proc( } if check_node_recursion(ast_context, node) { - log.error("Recursion detected") + //log.error("Recursion detected") return {}, false } @@ -1530,7 +1530,7 @@ internal_resolve_type_identifier :: proc( using ast if check_node_recursion(ast_context, node.derived.(^ast.Ident)) { - log.error("Recursion detected") + //log.error("Recursion detected") return {}, false } @@ -2287,7 +2287,7 @@ make_symbol_array_from_ast :: proc( ) -> Symbol { symbol := Symbol { range = common.get_token_range(v.node, ast_context.file.src), - type = .Variable, + type = .Constant, pkg = get_package_from_node(v.node), name = name.name, } @@ -2313,7 +2313,7 @@ make_symbol_dynamic_array_from_ast :: proc( ) -> Symbol { symbol := Symbol { range = common.get_token_range(v.node, ast_context.file.src), - type = .Variable, + type = .Constant, pkg = get_package_from_node(v.node), name = name.name, } @@ -2332,7 +2332,7 @@ make_symbol_multi_pointer_from_ast :: proc( ) -> Symbol { symbol := Symbol { range = common.get_token_range(v.node, ast_context.file.src), - type = .Variable, + type = .Constant, pkg = get_package_from_node(v.node), name = name.name, } @@ -2351,7 +2351,7 @@ make_symbol_map_from_ast :: proc( ) -> Symbol { symbol := Symbol { range = common.get_token_range(v.node, ast_context.file.src), - type = .Variable, + type = .Constant, pkg = get_package_from_node(v.node), name = name.name, } diff --git a/src/server/collector.odin b/src/server/collector.odin index 11b6b89..f08c74f 100644 --- a/src/server/collector.odin +++ b/src/server/collector.odin @@ -500,11 +500,6 @@ collect_symbols :: proc( package_map, uri, ) - if expr.mutable { - token_type = .Variable - } else { - token_type = .Constant - } case ^ast.Ident: token = v^ symbol.value = collect_generic( @@ -513,11 +508,6 @@ collect_symbols :: proc( package_map, uri, ) - if expr.mutable { - token_type = .Variable - } else { - token_type = .Unresolved - } case: // default symbol.value = collect_generic( @@ -526,14 +516,15 @@ collect_symbols :: proc( package_map, uri, ) - if expr.mutable { - token_type = .Variable - } else { - token_type = .Unresolved - } token = expr.expr } + if expr.mutable { + token_type = .Variable + } else { + token_type = .Constant + } + symbol.range = common.get_token_range(expr.name_expr, file.src) symbol.name = get_index_unique_string(collection, name) symbol.type = token_type diff --git a/src/server/completion.odin b/src/server/completion.odin index 91d8231..823a8df 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -499,7 +499,7 @@ get_selector_completion :: proc( } if symbol, ok := resolve_type_expression(ast_context, v.types[i]); - ok { + ok { if expr, ok := position_context.selector.derived.(^ast.Selector_Expr); ok { if expr.op.text == "->" && symbol.type != .Function { @@ -822,7 +822,7 @@ get_implicit_completion :: proc( } } } else if s, ok := unwrap_bitset(ast_context, comp_symbol); - ok { + ok { for enum_name in s.names { item := CompletionItem { label = enum_name, @@ -847,15 +847,15 @@ get_implicit_completion :: proc( enum_node: ^ast.Expr if position_in_node( - position_context.binary.right, - position_context.position, - ) { + position_context.binary.right, + position_context.position, + ) { context_node = position_context.binary.right enum_node = position_context.binary.left } else if position_in_node( - position_context.binary.left, - position_context.position, - ) { + position_context.binary.left, + position_context.position, + ) { context_node = position_context.binary.left enum_node = position_context.binary.right } @@ -889,7 +889,7 @@ get_implicit_completion :: proc( } else { //procedures are the only types that can return more than one value if symbol, ok := resolve_type_expression(ast_context, elem); - ok { + ok { if procedure, ok := symbol.value.(SymbolProcedureValue); ok { if procedure.return_types == nil { @@ -975,7 +975,7 @@ get_implicit_completion :: proc( call^, ) if symbol, ok := resolve_type_expression(ast_context, call.expr); - ok && parameter_ok { + ok && parameter_ok { if proc_value, ok := symbol.value.(SymbolProcedureValue); ok { if len(proc_value.arg_types) <= parameter_index { return @@ -1146,7 +1146,7 @@ get_identifier_completion :: proc( build_procedure_symbol_signature(&symbol) if score, ok := common.fuzzy_match(matcher, ident.name); - ok == 1 { + ok == 1 { append( &combined, CombinedResult{ @@ -1590,8 +1590,6 @@ append_magic_map_completion :: proc( append(items, item) } - - } append_magic_dynamic_array_completion :: proc( diff --git a/src/server/documents.odin b/src/server/documents.odin index 65b176e..5adfdfb 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -456,7 +456,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) { //collection specified if i := strings.index(imp.fullpath, ":"); - i != -1 && i > 1 && i < len(imp.fullpath) - 1 { + i != -1 && i > 1 && i < len(imp.fullpath) - 1 { if len(imp.fullpath) < 2 { continue } diff --git a/src/server/semantic_tokens.odin b/src/server/semantic_tokens.odin index b22d53f..44eebe2 100644 --- a/src/server/semantic_tokens.odin +++ b/src/server/semantic_tokens.odin @@ -260,6 +260,21 @@ visit_node :: proc( visit(n.expr, builder, ast_context) case ^Ident: if symbol_and_node, ok := builder.symbols[cast(uintptr)node]; ok { + + if .Distinct in symbol_and_node.symbol.flags && + symbol_and_node.symbol.type == .Constant { + log.error(symbol_and_node.symbol) + write_semantic_node( + builder, + node, + ast_context.file.src, + .Type, + .None, + ) + return + } + + if symbol_and_node.symbol.type == .Variable || symbol_and_node.symbol.type == .Constant { write_semantic_node( |