aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-08-10 18:16:26 +0200
committerDanielGavin <danielgavin5@hotmail.com>2024-08-10 18:16:26 +0200
commit64b23cd4ca41bfd44a83f945b0704df1021e7c9c (patch)
tree0f2620f2c45d0fba965a94ab1665b5d4d06c986f /src
parentfe8353ad6e852275570b6fb90e472f3f96d445f7 (diff)
Change odinfmt to use 120 characters instead. Add support for infering Maybe in comp literals.
Diffstat (limited to 'src')
-rw-r--r--src/server/analysis.odin1273
-rw-r--r--src/server/build.odin37
-rw-r--r--src/server/caches.odin10
-rw-r--r--src/server/check.odin69
-rw-r--r--src/server/clone.odin42
-rw-r--r--src/server/collector.odin284
-rw-r--r--src/server/completion.odin506
-rw-r--r--src/server/definition.odin55
-rw-r--r--src/server/document_links.odin16
-rw-r--r--src/server/document_symbols.odin15
-rw-r--r--src/server/documents.odin78
-rw-r--r--src/server/file_resolve.odin68
-rw-r--r--src/server/format.odin16
-rw-r--r--src/server/generics.odin226
-rw-r--r--src/server/hover.odin160
-rw-r--r--src/server/inlay_hints.odin36
-rw-r--r--src/server/lens.odin8
-rw-r--r--src/server/log.odin12
-rw-r--r--src/server/marshal.odin146
-rw-r--r--src/server/memory_index.odin21
-rw-r--r--src/server/methods.odin55
-rw-r--r--src/server/reader.odin8
-rw-r--r--src/server/references.odin130
-rw-r--r--src/server/rename.odin67
-rw-r--r--src/server/requests.odin342
-rw-r--r--src/server/response.odin7
-rw-r--r--src/server/semantic_tokens.odin78
-rw-r--r--src/server/signature.odin73
-rw-r--r--src/server/snippets.odin42
-rw-r--r--src/server/symbol.odin15
-rw-r--r--src/server/unmarshal.odin43
31 files changed, 771 insertions, 3167 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 7a970f2..c088d11 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -113,11 +113,7 @@ make_ast_context :: proc(
allocator := context.temp_allocator,
) -> AstContext {
ast_context := AstContext {
- locals = make(
- map[int]map[string][dynamic]DocumentLocal,
- 0,
- allocator,
- ),
+ locals = make(map[int]map[string][dynamic]DocumentLocal, 0, allocator),
globals = make(map[string]common.GlobalExpr, 0, allocator),
usings = make([dynamic]string, allocator),
recursion_map = make(map[rawptr]bool, 0, allocator),
@@ -141,8 +137,7 @@ set_ast_package_deferred :: proc(ast_context: ^AstContext, pkg: string) {
return
}
ast_context.deferred_count -= 1
- ast_context.current_package =
- ast_context.deferred_package[ast_context.deferred_count]
+ ast_context.current_package = ast_context.deferred_package[ast_context.deferred_count]
}
@(deferred_in = set_ast_package_deferred)
@@ -150,8 +145,7 @@ set_ast_package_set_scoped :: proc(ast_context: ^AstContext, pkg: string) {
if ast_context.deferred_count >= DeferredDepth {
return
}
- ast_context.deferred_package[ast_context.deferred_count] =
- ast_context.current_package
+ ast_context.deferred_package[ast_context.deferred_count] = ast_context.current_package
ast_context.deferred_count += 1
ast_context.current_package = pkg
}
@@ -161,8 +155,7 @@ set_ast_package_none_deferred :: proc(ast_context: ^AstContext) {
return
}
ast_context.deferred_count -= 1
- ast_context.current_package =
- ast_context.deferred_package[ast_context.deferred_count]
+ ast_context.current_package = ast_context.deferred_package[ast_context.deferred_count]
}
@(deferred_in = set_ast_package_none_deferred)
@@ -170,34 +163,25 @@ set_ast_package_scoped :: proc(ast_context: ^AstContext) {
if ast_context.deferred_count >= DeferredDepth {
return
}
- ast_context.deferred_package[ast_context.deferred_count] =
- ast_context.current_package
+ ast_context.deferred_package[ast_context.deferred_count] = ast_context.current_package
ast_context.deferred_count += 1
}
-set_ast_package_from_symbol_deferred :: proc(
- ast_context: ^AstContext,
- symbol: Symbol,
-) {
+set_ast_package_from_symbol_deferred :: proc(ast_context: ^AstContext, symbol: Symbol) {
if ast_context.deferred_count <= 0 {
return
}
ast_context.deferred_count -= 1
- ast_context.current_package =
- ast_context.deferred_package[ast_context.deferred_count]
+ ast_context.current_package = ast_context.deferred_package[ast_context.deferred_count]
}
@(deferred_in = set_ast_package_from_symbol_deferred)
-set_ast_package_from_symbol_scoped :: proc(
- ast_context: ^AstContext,
- symbol: Symbol,
-) {
+set_ast_package_from_symbol_scoped :: proc(ast_context: ^AstContext, symbol: Symbol) {
if ast_context.deferred_count >= DeferredDepth {
return
}
- ast_context.deferred_package[ast_context.deferred_count] =
- ast_context.current_package
+ ast_context.deferred_package[ast_context.deferred_count] = ast_context.current_package
ast_context.deferred_count += 1
if symbol.pkg != "" {
@@ -244,19 +228,28 @@ resolve_type_comp_literal :: proc(
if comp_lit, ok := field_value.value.derived.(^ast.Comp_Lit); ok {
if s, ok := current_symbol.value.(SymbolStructValue); ok {
for name, i in s.names {
- if name ==
- field_value.field.derived.(^ast.Ident).name {
- if symbol, ok := resolve_type_expression(
- ast_context,
- s.types[i],
- ); ok {
+ if name == field_value.field.derived.(^ast.Ident).name {
+ if symbol, ok := resolve_type_expression(ast_context, s.types[i]); ok {
//Stop at bitset, because we don't want to enter a comp_lit of a bitset
- if _, ok := symbol.value.(SymbolBitSetValue);
- ok {
- return current_symbol,
- current_comp_lit,
- true
+ if _, ok := symbol.value.(SymbolBitSetValue); ok {
+ return current_symbol, current_comp_lit, true
}
+
+ //If we get an union, we just need return the argument expression in the union.
+ if _, ok := symbol.value.(SymbolUnionValue); ok {
+ if call_expr, ok := s.types[i].derived.(^ast.Call_Expr);
+ ok && len(call_expr.args) == 1 {
+ if symbol, ok := resolve_type_expression(ast_context, call_expr.args[0]); ok {
+ return resolve_type_comp_literal(
+ ast_context,
+ position_context,
+ symbol,
+ cast(^ast.Comp_Lit)field_value.value,
+ )
+ }
+ }
+ }
+
return resolve_type_comp_literal(
ast_context,
position_context,
@@ -266,21 +259,13 @@ resolve_type_comp_literal :: proc(
}
}
}
- } else if s, ok := current_symbol.value.(SymbolBitFieldValue);
- ok {
+ } else if s, ok := current_symbol.value.(SymbolBitFieldValue); ok {
for name, i in s.names {
- if name ==
- field_value.field.derived.(^ast.Ident).name {
- if symbol, ok := resolve_type_expression(
- ast_context,
- s.types[i],
- ); ok {
+ if name == field_value.field.derived.(^ast.Ident).name {
+ if symbol, ok := resolve_type_expression(ast_context, s.types[i]); ok {
//Stop at bitset, because we don't want to enter a comp_lit of a bitset
- if _, ok := symbol.value.(SymbolBitSetValue);
- ok {
- return current_symbol,
- current_comp_lit,
- true
+ if _, ok := symbol.value.(SymbolBitSetValue); ok {
+ return current_symbol, current_comp_lit, true
}
return resolve_type_comp_literal(
ast_context,
@@ -300,72 +285,38 @@ resolve_type_comp_literal :: proc(
return {}, {}, false
}
- if symbol, ok := resolve_type_expression(
- ast_context,
- s.types[element_index],
- ); ok {
+ if symbol, ok := resolve_type_expression(ast_context, s.types[element_index]); ok {
//Stop at bitset, because we don't want to enter a comp_lit of a bitset
if _, ok := symbol.value.(SymbolBitSetValue); ok {
return current_symbol, current_comp_lit, true
}
- return resolve_type_comp_literal(
- ast_context,
- position_context,
- symbol,
- comp_value,
- )
+ return resolve_type_comp_literal(ast_context, position_context, symbol, comp_value)
}
case SymbolBitFieldValue:
if len(s.types) <= element_index {
return {}, {}, false
}
- if symbol, ok := resolve_type_expression(
- ast_context,
- s.types[element_index],
- ); ok {
+ if symbol, ok := resolve_type_expression(ast_context, s.types[element_index]); ok {
//Stop at bitset, because we don't want to enter a comp_lit of a bitset
if _, ok := symbol.value.(SymbolBitSetValue); ok {
return current_symbol, current_comp_lit, true
}
- return resolve_type_comp_literal(
- ast_context,
- position_context,
- symbol,
- comp_value,
- )
+ return resolve_type_comp_literal(ast_context, position_context, symbol, comp_value)
}
case SymbolSliceValue:
- if symbol, ok := resolve_type_expression(ast_context, s.expr);
- ok {
- return resolve_type_comp_literal(
- ast_context,
- position_context,
- symbol,
- comp_value,
- )
+ if symbol, ok := resolve_type_expression(ast_context, s.expr); ok {
+ return resolve_type_comp_literal(ast_context, position_context, symbol, comp_value)
}
case SymbolDynamicArrayValue:
- if symbol, ok := resolve_type_expression(ast_context, s.expr);
- ok {
- return resolve_type_comp_literal(
- ast_context,
- position_context,
- symbol,
- comp_value,
- )
+ if symbol, ok := resolve_type_expression(ast_context, s.expr); ok {
+ return resolve_type_comp_literal(ast_context, position_context, symbol, comp_value)
}
case SymbolFixedArrayValue:
- if symbol, ok := resolve_type_expression(ast_context, s.expr);
- ok {
- return resolve_type_comp_literal(
- ast_context,
- position_context,
- symbol,
- comp_value,
- )
+ if symbol, ok := resolve_type_expression(ast_context, s.expr); ok {
+ return resolve_type_comp_literal(ast_context, position_context, symbol, comp_value)
}
}
}
@@ -375,26 +326,14 @@ resolve_type_comp_literal :: proc(
}
-is_symbol_same_typed :: proc(
- ast_context: ^AstContext,
- a, b: Symbol,
- flags: ast.Field_Flags = {},
-) -> bool {
+is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast.Field_Flags = {}) -> bool {
//relying on the fact that a is the call argument to avoid checking both sides for untyped.
if untyped, ok := a.value.(SymbolUntypedValue); ok {
if basic, ok := b.value.(SymbolBasicValue); ok {
switch untyped.type {
case .Integer:
switch basic.ident.name {
- case "int",
- "uint",
- "u32",
- "i32",
- "u8",
- "i8",
- "u64",
- "u16",
- "i16":
+ case "int", "uint", "u32", "i32", "u8", "i8", "u64", "u16", "i16":
return true
case:
return false
@@ -439,10 +378,7 @@ is_symbol_same_typed :: proc(
return false
}
- if .Distinct in a.flags == .Distinct in b.flags &&
- .Distinct in a.flags &&
- a.name == b.name &&
- a.pkg == b.pkg {
+ if .Distinct in a.flags == .Distinct in b.flags && .Distinct in a.flags && a.name == b.name && a.pkg == b.pkg {
return true
}
@@ -461,10 +397,7 @@ is_symbol_same_typed :: proc(
#partial switch a_value in a.value {
case SymbolBasicValue:
return a.name == b.name && a.pkg == b.pkg
- case SymbolStructValue,
- SymbolEnumValue,
- SymbolUnionValue,
- SymbolBitSetValue:
+ case SymbolStructValue, SymbolEnumValue, SymbolUnionValue, SymbolBitSetValue:
return a.name == b.name && a.pkg == b.pkg
case SymbolSliceValue:
b_value := b.value.(SymbolSliceValue)
@@ -492,10 +425,7 @@ is_symbol_same_typed :: proc(
a_is_soa := .Soa in a_symbol.flags
b_is_soa := .Soa in a_symbol.flags
- return(
- is_symbol_same_typed(ast_context, a_symbol, b_symbol) &&
- a_is_soa == b_is_soa \
- )
+ return is_symbol_same_typed(ast_context, a_symbol, b_symbol) && a_is_soa == b_is_soa
case SymbolFixedArrayValue:
b_value := b.value.(SymbolFixedArrayValue)
@@ -570,10 +500,7 @@ is_symbol_same_typed :: proc(
a_is_soa := .Soa in a_symbol.flags
b_is_soa := .Soa in a_symbol.flags
- return(
- is_symbol_same_typed(ast_context, a_symbol, b_symbol) &&
- a_is_soa == b_is_soa \
- )
+ return is_symbol_same_typed(ast_context, a_symbol, b_symbol) && a_is_soa == b_is_soa
case SymbolMapValue:
b_value := b.value.(SymbolMapValue)
@@ -602,10 +529,7 @@ is_symbol_same_typed :: proc(
set_ast_package_from_symbol_scoped(ast_context, a)
- a_value_symbol, ok = resolve_type_expression(
- ast_context,
- a_value.value,
- )
+ a_value_symbol, ok = resolve_type_expression(ast_context, a_value.value)
if !ok {
return false
@@ -613,10 +537,7 @@ is_symbol_same_typed :: proc(
set_ast_package_from_symbol_scoped(ast_context, b)
- b_value_symbol, ok = resolve_type_expression(
- ast_context,
- b_value.value,
- )
+ b_value_symbol, ok = resolve_type_expression(ast_context, b_value.value)
if !ok {
return false
@@ -631,13 +552,7 @@ is_symbol_same_typed :: proc(
return false
}
-get_field_list_name_index :: proc(
- name: string,
- field_list: []^ast.Field,
-) -> (
- int,
- bool,
-) {
+get_field_list_name_index :: proc(name: string, field_list: []^ast.Field) -> (int, bool) {
for field, i in field_list {
for field_name in field.names {
if ident, ok := field_name.derived.(^ast.Ident); ok {
@@ -654,13 +569,7 @@ get_field_list_name_index :: proc(
/*
Figure out which function the call expression is using out of the list from proc group
*/
-resolve_function_overload :: proc(
- ast_context: ^AstContext,
- group: ast.Proc_Group,
-) -> (
- Symbol,
- bool,
-) {
+resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Group) -> (Symbol, bool) {
old_overloading := ast_context.overloading
ast_context.overloading = true
@@ -680,10 +589,7 @@ resolve_function_overload :: proc(
candidates := make([dynamic]Symbol, context.temp_allocator)
for arg_expr in group.args {
- next_fn: if f, ok := internal_resolve_type_expression(
- ast_context,
- arg_expr,
- ); ok {
+ next_fn: if f, ok := internal_resolve_type_expression(ast_context, arg_expr); ok {
if call_expr == nil || len(call_expr.args) == 0 {
append(&candidates, f)
break next_fn
@@ -715,18 +621,13 @@ resolve_function_overload :: proc(
}
//named parameter
- if field, is_field := arg.derived.(^ast.Field_Value);
- is_field {
- call_symbol, ok = resolve_type_expression(
- ast_context,
- field.value,
- )
+ if field, is_field := arg.derived.(^ast.Field_Value); is_field {
+ call_symbol, ok = resolve_type_expression(ast_context, field.value)
if !ok {
break next_fn
}
- if ident, is_ident := field.field.derived.(^ast.Ident);
- is_ident {
+ if ident, is_ident := field.field.derived.(^ast.Ident); is_ident {
i, ok = get_field_list_name_index(
field.field.derived.(^ast.Ident).name,
procedure.arg_types,
@@ -735,10 +636,7 @@ resolve_function_overload :: proc(
break next_fn
}
} else {
- call_symbol, ok = resolve_type_expression(
- ast_context,
- arg,
- )
+ call_symbol, ok = resolve_type_expression(ast_context, arg)
}
if !ok {
@@ -749,36 +647,22 @@ resolve_function_overload :: proc(
if len(p.return_types) != 1 {
break next_fn
}
- if s, ok := resolve_type_expression(
- ast_context,
- p.return_types[0].type,
- ); ok {
+ if s, ok := resolve_type_expression(ast_context, p.return_types[0].type); ok {
call_symbol = s
}
}
if procedure.arg_types[i].type != nil {
- arg_symbol, ok = resolve_type_expression(
- ast_context,
- procedure.arg_types[i].type,
- )
+ arg_symbol, ok = resolve_type_expression(ast_context, procedure.arg_types[i].type)
} else {
- arg_symbol, ok = resolve_type_expression(
- ast_context,
- procedure.arg_types[i].default_value,
- )
+ arg_symbol, ok = resolve_type_expression(ast_context, procedure.arg_types[i].default_value)
}
if !ok {
break next_fn
}
- if !is_symbol_same_typed(
- ast_context,
- call_symbol,
- arg_symbol,
- procedure.arg_types[i].flags,
- ) {
+ if !is_symbol_same_typed(ast_context, call_symbol, arg_symbol, procedure.arg_types[i].flags) {
break next_fn
}
}
@@ -803,13 +687,7 @@ resolve_function_overload :: proc(
return Symbol{}, false
}
-resolve_basic_lit :: proc(
- ast_context: ^AstContext,
- basic_lit: ast.Basic_Lit,
-) -> (
- Symbol,
- bool,
-) {
+resolve_basic_lit :: proc(ast_context: ^AstContext, basic_lit: ast.Basic_Lit) -> (Symbol, bool) {
symbol := Symbol {
type = .Constant,
}
@@ -855,12 +733,7 @@ resolve_basic_directive :: proc(
) {
switch directive.name {
case "caller_location":
- ident := new_type(
- ast.Ident,
- directive.pos,
- directive.end,
- ast_context.allocator,
- )
+ ident := new_type(ast.Ident, directive.pos, directive.end, ast_context.allocator)
ident.name = "Source_Code_Location"
set_ast_package_set_scoped(ast_context, ast_context.document_package)
return internal_resolve_type_identifier(ast_context, ident^)
@@ -869,10 +742,7 @@ resolve_basic_directive :: proc(
return {}, false
}
-check_node_recursion :: proc(
- ast_context: ^AstContext,
- node: ^ast.Node,
-) -> bool {
+check_node_recursion :: proc(ast_context: ^AstContext, node: ^ast.Node) -> bool {
raw := cast(rawptr)node
if raw in ast_context.recursion_map {
@@ -884,24 +754,12 @@ check_node_recursion :: proc(
return false
}
-resolve_type_expression :: proc(
- ast_context: ^AstContext,
- node: ^ast.Expr,
-) -> (
- Symbol,
- bool,
-) {
+resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (Symbol, bool) {
clear(&ast_context.recursion_map)
return internal_resolve_type_expression(ast_context, node)
}
-internal_resolve_type_expression :: proc(
- ast_context: ^AstContext,
- node: ^ast.Expr,
-) -> (
- Symbol,
- bool,
-) {
+internal_resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (Symbol, bool) {
if node == nil {
return {}, false
}
@@ -931,91 +789,27 @@ internal_resolve_type_expression :: proc(
return internal_resolve_type_expression(ast_context, v.values[0])
}
case ^Union_Type:
- return make_symbol_union_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- true,
- ),
- true
+ return make_symbol_union_from_ast(ast_context, v^, ast_context.field_name, true), true
case ^Enum_Type:
- return make_symbol_enum_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- true,
- ),
- true
+ return make_symbol_enum_from_ast(ast_context, v^, ast_context.field_name, true), true
case ^Struct_Type:
- return make_symbol_struct_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- {},
- true,
- ),
- true
+ return make_symbol_struct_from_ast(ast_context, v^, ast_context.field_name, {}, true), true
case ^Bit_Set_Type:
- return make_symbol_bitset_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- true,
- ),
- true
+ return make_symbol_bitset_from_ast(ast_context, v^, ast_context.field_name, true), true
case ^Array_Type:
- return make_symbol_array_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- ),
- true
+ return make_symbol_array_from_ast(ast_context, v^, ast_context.field_name), true
case ^Matrix_Type:
- return make_symbol_matrix_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- ),
- true
+ return make_symbol_matrix_from_ast(ast_context, v^, ast_context.field_name), true
case ^Dynamic_Array_Type:
- return make_symbol_dynamic_array_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- ),
- true
+ return make_symbol_dynamic_array_from_ast(ast_context, v^, ast_context.field_name), true
case ^Multi_Pointer_Type:
- return make_symbol_multi_pointer_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- ),
- true
+ return make_symbol_multi_pointer_from_ast(ast_context, v^, ast_context.field_name), true
case ^Map_Type:
- return make_symbol_map_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- ),
- true
+ return make_symbol_map_from_ast(ast_context, v^, ast_context.field_name), true
case ^Proc_Type:
- return make_symbol_procedure_from_ast(
- ast_context,
- node,
- v^,
- ast_context.field_name,
- {},
- true,
- ),
- true
+ return make_symbol_procedure_from_ast(ast_context, node, v^, ast_context.field_name, {}, true), true
case ^Bit_Field_Type:
- return make_symbol_bit_field_from_ast(
- ast_context,
- v^,
- ast_context.field_name,
- true,
- ),
- true
+ return make_symbol_bit_field_from_ast(ast_context, v^, ast_context.field_name, true), true
case ^Basic_Directive:
return resolve_basic_directive(ast_context, v^)
case ^Binary_Expr:
@@ -1060,18 +854,12 @@ internal_resolve_type_expression :: proc(
case ^Type_Assertion:
if unary, ok := v.type.derived.(^ast.Unary_Expr); ok {
if unary.op.kind == .Question {
- if symbol, ok := internal_resolve_type_expression(
- ast_context,
- v.expr,
- ); ok {
+ if symbol, ok := internal_resolve_type_expression(ast_context, v.expr); ok {
if union_value, ok := symbol.value.(SymbolUnionValue); ok {
if len(union_value.types) != 1 {
return {}, false
}
- return internal_resolve_type_expression(
- ast_context,
- union_value.types[0],
- )
+ return internal_resolve_type_expression(ast_context, union_value.types[0])
}
}
}
@@ -1081,10 +869,7 @@ internal_resolve_type_expression :: proc(
case ^Proc_Lit:
if v.type.results != nil {
if len(v.type.results.list) == 1 {
- return internal_resolve_type_expression(
- ast_context,
- v.type.results.list[0].type,
- )
+ return internal_resolve_type_expression(ast_context, v.type.results.list[0].type)
}
}
case ^Pointer_Type:
@@ -1092,8 +877,7 @@ internal_resolve_type_expression :: proc(
symbol.pointers += 1
return symbol, ok
case ^Matrix_Index_Expr:
- if symbol, ok := internal_resolve_type_expression(ast_context, v.expr);
- ok {
+ if symbol, ok := internal_resolve_type_expression(ast_context, v.expr); ok {
if mat, ok := symbol.value.(SymbolMatrixValue); ok {
return internal_resolve_type_expression(ast_context, mat.expr)
}
@@ -1117,10 +901,7 @@ internal_resolve_type_expression :: proc(
case SymbolFixedArrayValue:
symbol, ok = internal_resolve_type_expression(ast_context, v2.expr)
case SymbolMapValue:
- symbol, ok = internal_resolve_type_expression(
- ast_context,
- v2.value,
- )
+ symbol, ok = internal_resolve_type_expression(ast_context, v2.value)
case SymbolMultiPointer:
symbol, ok = internal_resolve_type_expression(ast_context, v2.expr)
}
@@ -1147,10 +928,7 @@ internal_resolve_type_expression :: proc(
return internal_resolve_type_expression(ast_context, v.expr)
case ^Selector_Call_Expr:
- if selector, ok := internal_resolve_type_expression(
- ast_context,
- v.expr,
- ); ok {
+ if selector, ok := internal_resolve_type_expression(ast_context, v.expr); ok {
ast_context.use_locals = false
set_ast_package_from_symbol_scoped(ast_context, selector)
@@ -1158,20 +936,14 @@ internal_resolve_type_expression :: proc(
#partial switch s in selector.value {
case SymbolProcedureValue:
if len(s.return_types) == 1 {
- return internal_resolve_type_expression(
- ast_context,
- s.return_types[0].type,
- )
+ return internal_resolve_type_expression(ast_context, s.return_types[0].type)
}
}
return selector, true
}
case ^Selector_Expr:
- if selector, ok := internal_resolve_type_expression(
- ast_context,
- v.expr,
- ); ok {
+ if selector, ok := internal_resolve_type_expression(ast_context, v.expr); ok {
ast_context.use_locals = false
set_ast_package_from_symbol_scoped(ast_context, selector)
@@ -1180,14 +952,7 @@ internal_resolve_type_expression :: proc(
case SymbolFixedArrayValue:
components_count := 0
for c in v.field.name {
- if c == 'x' ||
- c == 'y' ||
- c == 'z' ||
- c == 'w' ||
- c == 'r' ||
- c == 'g' ||
- c == 'b' ||
- c == 'a' {
+ if c == 'x' || c == 'y' || c == 'z' || c == 'w' || c == 'r' || c == 'g' || c == 'b' || c == 'a' {
components_count += 1
}
}
@@ -1199,21 +964,13 @@ internal_resolve_type_expression :: proc(
if components_count == 1 {
set_ast_package_from_symbol_scoped(ast_context, selector)
- symbol, ok := internal_resolve_type_expression(
- ast_context,
- s.expr,
- )
+ symbol, ok := internal_resolve_type_expression(ast_context, s.expr)
symbol.type = .Variable
return symbol, ok
} else {
value := SymbolFixedArrayValue {
expr = s.expr,
- len = make_int_basic_value(
- ast_context,
- components_count,
- s.len.pos,
- s.len.end,
- ),
+ len = make_int_basic_value(ast_context, components_count, s.len.pos, s.len.end),
}
selector.value = value
selector.type = .Variable
@@ -1230,19 +987,13 @@ internal_resolve_type_expression :: proc(
selector_expr.expr = s.return_types[0].type
selector_expr.field = v.field
- return internal_resolve_type_expression(
- ast_context,
- selector_expr,
- )
+ return internal_resolve_type_expression(ast_context, selector_expr)
}
case SymbolStructValue:
for name, i in s.names {
if v.field != nil && name == v.field.name {
ast_context.field_name = v.field^
- symbol, ok := internal_resolve_type_expression(
- ast_context,
- s.types[i],
- )
+ symbol, ok := internal_resolve_type_expression(ast_context, s.types[i])
symbol.type = .Variable
return symbol, ok
}
@@ -1251,10 +1002,7 @@ internal_resolve_type_expression :: proc(
for name, i in s.names {
if v.field != nil && name == v.field.name {
ast_context.field_name = v.field^
- symbol, ok := internal_resolve_type_expression(
- ast_context,
- s.types[i],
- )
+ symbol, ok := internal_resolve_type_expression(ast_context, s.types[i])
symbol.type = .Variable
return symbol, ok
}
@@ -1263,10 +1011,7 @@ internal_resolve_type_expression :: proc(
try_build_package(ast_context.current_package)
if v.field != nil {
- return resolve_symbol_return(
- ast_context,
- lookup(v.field.name, selector.pkg),
- )
+ return resolve_symbol_return(ast_context, lookup(v.field.name, selector.pkg))
} else {
return Symbol{}, false
}
@@ -1321,31 +1066,19 @@ store_local :: proc(
}
add_local_group :: proc(ast_context: ^AstContext, id: int) {
- ast_context.locals[id] = make(
- map[string][dynamic]DocumentLocal,
- 100,
- ast_context.allocator,
- )
+ ast_context.locals[id] = make(map[string][dynamic]DocumentLocal, 100, ast_context.allocator)
}
clear_local_group :: proc(ast_context: ^AstContext, id: int) {
ast_context.locals[id] = {}
}
-get_local :: proc(
- ast_context: AstContext,
- ident: ast.Ident,
-) -> (
- DocumentLocal,
- bool,
-) {
+get_local :: proc(ast_context: AstContext, ident: ast.Ident) -> (DocumentLocal, bool) {
for _, locals in ast_context.locals {
local_stack := locals[ident.name] or_continue
#reverse for local in local_stack {
- if local.offset <= ident.pos.offset ||
- local.local_global ||
- local.lhs.pos.offset == ident.pos.offset {
+ if local.offset <= ident.pos.offset || local.local_global || local.lhs.pos.offset == ident.pos.offset {
// checking equal offsets is a hack to allow matching lhs ident in var decls
// because otherwise minimal offset begins after the decl
return local, true
@@ -1356,16 +1089,11 @@ get_local :: proc(
return {}, false
}
-get_local_offset :: proc(
- ast_context: ^AstContext,
- offset: int,
- name: string,
-) -> int {
+get_local_offset :: proc(ast_context: ^AstContext, offset: int, name: string) -> int {
for _, locals in &ast_context.locals {
if local_stack, ok := locals[name]; ok {
for i := len(local_stack) - 1; i >= 0; i -= 1 {
- if local_stack[i].offset <= offset ||
- local_stack[i].local_global {
+ if local_stack[i].offset <= offset || local_stack[i].local_global {
if i < 0 {
return -1
} else {
@@ -1379,23 +1107,11 @@ get_local_offset :: proc(
return -1
}
-resolve_type_identifier :: proc(
- ast_context: ^AstContext,
- node: ast.Ident,
-) -> (
- Symbol,
- bool,
-) {
+resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (Symbol, bool) {
return internal_resolve_type_identifier(ast_context, node)
}
-internal_resolve_type_identifier :: proc(
- ast_context: ^AstContext,
- node: ast.Ident,
-) -> (
- _symbol: Symbol,
- _ok: bool,
-) {
+internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (_symbol: Symbol, _ok: bool) {
using ast
if check_node_recursion(ast_context, node.derived.(^ast.Ident)) {
@@ -1451,8 +1167,7 @@ internal_resolve_type_identifier :: proc(
}
}
- if local, ok := get_local(ast_context^, node);
- ok && ast_context.use_locals {
+ if local, ok := get_local(ast_context^, node); ok && ast_context.use_locals {
is_distinct := false
if local.parameter {
@@ -1490,29 +1205,21 @@ internal_resolve_type_identifier :: proc(
#partial switch v in local.rhs.derived {
case ^Ident:
- return_symbol, ok = internal_resolve_type_identifier(
- ast_context,
- v^,
- )
+ return_symbol, ok = internal_resolve_type_identifier(ast_context, v^)
case ^Union_Type:
- return_symbol, ok =
- make_symbol_union_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_union_from_ast(ast_context, v^, node), true
return_symbol.name = node.name
case ^Enum_Type:
- return_symbol, ok =
- make_symbol_enum_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_enum_from_ast(ast_context, v^, node), true
return_symbol.name = node.name
case ^Struct_Type:
- return_symbol, ok =
- make_symbol_struct_from_ast(ast_context, v^, node, {}), true
+ return_symbol, ok = make_symbol_struct_from_ast(ast_context, v^, node, {}), true
return_symbol.name = node.name
case ^Bit_Set_Type:
- return_symbol, ok =
- make_symbol_bitset_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_bitset_from_ast(ast_context, v^, node), true
return_symbol.name = node.name
case ^Bit_Field_Type:
- return_symbol, ok =
- make_symbol_bit_field_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_bit_field_from_ast(ast_context, v^, node), true
return_symbol.name = node.name
case ^Proc_Lit:
if is_procedure_generic(v.type) {
@@ -1520,52 +1227,29 @@ internal_resolve_type_identifier :: proc(
if !ok && !ast_context.overloading {
return_symbol, ok =
- make_symbol_procedure_from_ast(
- ast_context,
- local.rhs,
- v.type^,
- node,
- {},
- false,
- ),
- true
+ make_symbol_procedure_from_ast(ast_context, local.rhs, v.type^, node, {}, false), true
}
} else {
return_symbol, ok =
- make_symbol_procedure_from_ast(
- ast_context,
- local.rhs,
- v.type^,
- node,
- {},
- false,
- ),
- true
+ make_symbol_procedure_from_ast(ast_context, local.rhs, v.type^, node, {}, false), true
}
case ^Proc_Group:
return_symbol, ok = resolve_function_overload(ast_context, v^)
case ^Array_Type:
- return_symbol, ok =
- make_symbol_array_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_array_from_ast(ast_context, v^, node), true
case ^Dynamic_Array_Type:
- return_symbol, ok =
- make_symbol_dynamic_array_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_dynamic_array_from_ast(ast_context, v^, node), true
case ^Matrix_Type:
- return_symbol, ok =
- make_symbol_matrix_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_matrix_from_ast(ast_context, v^, node), true
case ^Map_Type:
- return_symbol, ok =
- make_symbol_map_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_map_from_ast(ast_context, v^, node), true
case ^Basic_Lit:
return_symbol, ok = resolve_basic_lit(ast_context, v^)
return_symbol.name = node.name
return_symbol.type = local.variable ? .Variable : .Constant
case:
- return_symbol, ok = internal_resolve_type_expression(
- ast_context,
- local.rhs,
- )
+ return_symbol, ok = internal_resolve_type_expression(ast_context, local.rhs)
}
if is_distinct {
@@ -1598,10 +1282,7 @@ internal_resolve_type_identifier :: proc(
#partial switch v in global.expr.derived {
case ^Ident:
- return_symbol, ok = internal_resolve_type_identifier(
- ast_context,
- v^,
- )
+ return_symbol, ok = internal_resolve_type_identifier(ast_context, v^)
case ^ast.Call_Expr:
old_call := ast_context.call
ast_context.call = cast(^Call_Expr)global.expr
@@ -1610,45 +1291,27 @@ internal_resolve_type_identifier :: proc(
ast_context.call = old_call
}
- call_symbol := internal_resolve_type_expression(
- ast_context,
- v.expr,
- ) or_return
+ call_symbol := internal_resolve_type_expression(ast_context, v.expr) or_return
proc_value := call_symbol.value.(SymbolProcedureValue) or_return
- if len(proc_value.return_types) >= 1 &&
- proc_value.return_types[0].type != nil {
- return_symbol, ok = internal_resolve_type_expression(
- ast_context,
- proc_value.return_types[0].type,
- )
+ if len(proc_value.return_types) >= 1 && proc_value.return_types[0].type != nil {
+ return_symbol, ok = internal_resolve_type_expression(ast_context, proc_value.return_types[0].type)
}
case ^Struct_Type:
- return_symbol, ok =
- make_symbol_struct_from_ast(
- ast_context,
- v^,
- node,
- global.attributes,
- ),
- true
+ return_symbol, ok = make_symbol_struct_from_ast(ast_context, v^, node, global.attributes), true
return_symbol.name = node.name
case ^Bit_Set_Type:
- return_symbol, ok =
- make_symbol_bitset_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_bitset_from_ast(ast_context, v^, node), true
return_symbol.name = node.name
case ^Union_Type:
- return_symbol, ok =
- make_symbol_union_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_union_from_ast(ast_context, v^, node), true
return_symbol.name = node.name
case ^Enum_Type:
- return_symbol, ok =
- make_symbol_enum_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_enum_from_ast(ast_context, v^, node), true
return_symbol.name = node.name
case ^Bit_Field_Type:
- return_symbol, ok =
- make_symbol_bit_field_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_bit_field_from_ast(ast_context, v^, node), true
return_symbol.name = node.name
case ^Proc_Lit:
if is_procedure_generic(v.type) {
@@ -1669,39 +1332,25 @@ internal_resolve_type_identifier :: proc(
}
} else {
return_symbol, ok =
- make_symbol_procedure_from_ast(
- ast_context,
- global.expr,
- v.type^,
- node,
- global.attributes,
- false,
- ),
+ make_symbol_procedure_from_ast(ast_context, global.expr, v.type^, node, global.attributes, false),
true
}
case ^Proc_Group:
return_symbol, ok = resolve_function_overload(ast_context, v^)
case ^Array_Type:
- return_symbol, ok =
- make_symbol_array_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_array_from_ast(ast_context, v^, node), true
case ^Dynamic_Array_Type:
- return_symbol, ok =
- make_symbol_dynamic_array_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_dynamic_array_from_ast(ast_context, v^, node), true
case ^Matrix_Type:
- return_symbol, ok =
- make_symbol_matrix_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_matrix_from_ast(ast_context, v^, node), true
case ^Map_Type:
- return_symbol, ok =
- make_symbol_map_from_ast(ast_context, v^, node), true
+ return_symbol, ok = make_symbol_map_from_ast(ast_context, v^, node), true
case ^Basic_Lit:
return_symbol, ok = resolve_basic_lit(ast_context, v^)
return_symbol.name = node.name
return_symbol.type = global.mutable ? .Variable : .Constant
case:
- return_symbol, ok = internal_resolve_type_expression(
- ast_context,
- global.expr,
- )
+ return_symbol, ok = internal_resolve_type_expression(ast_context, global.expr)
}
if is_distinct {
@@ -1741,10 +1390,7 @@ internal_resolve_type_identifier :: proc(
return symbol, true
}
- is_runtime := strings.contains(
- ast_context.current_package,
- "base/runtime",
- )
+ is_runtime := strings.contains(ast_context.current_package, "base/runtime")
if is_runtime {
if symbol, ok := lookup(node.name, "$builtin"); ok {
@@ -1784,11 +1430,7 @@ internal_resolve_type_identifier :: proc(
return Symbol{}, false
}
-expand_struct_usings :: proc(
- ast_context: ^AstContext,
- symbol: Symbol,
- value: SymbolStructValue,
-) -> SymbolStructValue {
+expand_struct_usings :: proc(ast_context: ^AstContext, symbol: Symbol, value: SymbolStructValue) -> SymbolStructValue {
names := slice.to_dynamic(value.names, ast_context.allocator)
types := slice.to_dynamic(value.types, ast_context.allocator)
ranges := slice.to_dynamic(value.ranges, ast_context.allocator)
@@ -1832,12 +1474,7 @@ expand_struct_usings :: proc(
field := new_type(ast.Ident, {}, {}, context.temp_allocator)
field.name = function.physical_name
- selector := new_type(
- ast.Selector_Expr,
- {},
- {},
- context.temp_allocator,
- )
+ selector := new_type(ast.Selector_Expr, {}, {}, context.temp_allocator)
selector.field = field
selector.expr = base
@@ -1853,13 +1490,7 @@ expand_struct_usings :: proc(
return {names = names[:], types = types[:], ranges = ranges[:]}
}
-resolve_slice_expression :: proc(
- ast_context: ^AstContext,
- slice_expr: ^ast.Slice_Expr,
-) -> (
- symbol: Symbol,
- ok: bool,
-) {
+resolve_slice_expression :: proc(ast_context: ^AstContext, slice_expr: ^ast.Slice_Expr) -> (symbol: Symbol, ok: bool) {
symbol = resolve_type_expression(ast_context, slice_expr.expr) or_return
expr: ^ast.Expr
@@ -1890,22 +1521,12 @@ resolve_comp_literal :: proc(
ok: bool,
) {
if position_context.parent_comp_lit.type != nil {
- symbol = resolve_type_expression(
- ast_context,
- position_context.parent_comp_lit.type,
- ) or_return
+ symbol = resolve_type_expression(ast_context, position_context.parent_comp_lit.type) or_return
} else if position_context.call != nil {
- if call_expr, ok := position_context.call.derived.(^ast.Call_Expr);
- ok {
- arg_index := find_position_in_call_param(
- position_context,
- call_expr^,
- ) or_return
+ if call_expr, ok := position_context.call.derived.(^ast.Call_Expr); ok {
+ arg_index := find_position_in_call_param(position_context, call_expr^) or_return
- symbol = resolve_type_expression(
- ast_context,
- position_context.call,
- ) or_return
+ symbol = resolve_type_expression(ast_context, position_context.call) or_return
value := symbol.value.(SymbolProcedureValue) or_return
@@ -1917,10 +1538,7 @@ resolve_comp_literal :: proc(
return {}, false
}
- symbol = resolve_type_expression(
- ast_context,
- value.arg_types[arg_index].type,
- ) or_return
+ symbol = resolve_type_expression(ast_context, value.arg_types[arg_index].type) or_return
}
} else if position_context.returns != nil {
return_index: int
@@ -1975,23 +1593,15 @@ resolve_implicit_selector :: proc(
if position_context.call != nil {
if call, ok := position_context.call.derived.(^ast.Call_Expr); ok {
- parameter_index, parameter_ok := find_position_in_call_param(
- position_context,
- call^,
- )
- if symbol, ok := resolve_type_expression(ast_context, call.expr);
- ok && parameter_ok {
+ parameter_index, parameter_ok := find_position_in_call_param(position_context, call^)
+ if symbol, ok := resolve_type_expression(ast_context, call.expr); ok && parameter_ok {
if proc_value, ok := symbol.value.(SymbolProcedureValue); ok {
if len(proc_value.arg_types) <= parameter_index {
return {}, false
}
- return resolve_type_expression(
- ast_context,
- proc_value.arg_types[parameter_index].type,
- )
- } else if enum_value, ok := symbol.value.(SymbolEnumValue);
- ok {
+ return resolve_type_expression(ast_context, proc_value.arg_types[parameter_index].type)
+ } else if enum_value, ok := symbol.value.(SymbolEnumValue); ok {
return symbol, true
}
}
@@ -1999,42 +1609,23 @@ resolve_implicit_selector :: proc(
}
if position_context.switch_stmt != nil {
- return resolve_type_expression(
- ast_context,
- position_context.switch_stmt.cond,
- )
+ return resolve_type_expression(ast_context, position_context.switch_stmt.cond)
}
- if position_context.assign != nil &&
- len(position_context.assign.lhs) == len(position_context.assign.rhs) {
+ if position_context.assign != nil && len(position_context.assign.lhs) == len(position_context.assign.rhs) {
for _, i in position_context.assign.lhs {
- if position_in_node(
- position_context.assign.rhs[i],
- position_context.position,
- ) {
- return resolve_type_expression(
- ast_context,
- position_context.assign.lhs[i],
- )
+ if position_in_node(position_context.assign.rhs[i], position_context.position) {
+ return resolve_type_expression(ast_context, position_context.assign.lhs[i])
}
}
}
if position_context.binary != nil {
- if position_in_node(
- position_context.binary.left,
- position_context.position,
- ) {
- return resolve_type_expression(
- ast_context,
- position_context.binary.right,
- )
+ if position_in_node(position_context.binary.left, position_context.position) {
+ return resolve_type_expression(ast_context, position_context.binary.right)
} else {
- return resolve_type_expression(
- ast_context,
- position_context.binary.left,
- )
+ return resolve_type_expression(ast_context, position_context.binary.left)
}
}
@@ -2061,19 +1652,12 @@ resolve_implicit_selector :: proc(
}
if len(position_context.function.type.results.list) > return_index {
- return resolve_type_expression(
- ast_context,
- position_context.function.type.results.list[return_index].type,
- )
+ return resolve_type_expression(ast_context, position_context.function.type.results.list[return_index].type)
}
}
- if position_context.value_decl != nil &&
- position_context.value_decl.type != nil {
- return resolve_type_expression(
- ast_context,
- position_context.value_decl.type,
- )
+ if position_context.value_decl != nil && position_context.value_decl.type != nil {
+ return resolve_type_expression(ast_context, position_context.value_decl.type)
}
if position_context.comp_lit != nil {
@@ -2084,8 +1668,7 @@ resolve_implicit_selector :: proc(
field_name: string
if position_context.field_value != nil {
- if field, ok := position_context.field_value.field.derived.(^ast.Ident);
- ok {
+ if field, ok := position_context.field_value.field.derived.(^ast.Ident); ok {
field_name = field.name
} else {
return {}, false
@@ -2093,10 +1676,7 @@ resolve_implicit_selector :: proc(
}
- if symbol, ok := resolve_type_expression(
- ast_context,
- position_context.parent_comp_lit.type,
- ); ok {
+ if symbol, ok := resolve_type_expression(ast_context, position_context.parent_comp_lit.type); ok {
if comp_symbol, comp_lit, ok := resolve_type_comp_literal(
ast_context,
position_context,
@@ -2131,8 +1711,7 @@ resolve_implicit_selector :: proc(
}
return resolve_type_expression(ast_context, type)
- } else if s, ok := comp_symbol.value.(SymbolBitFieldValue);
- ok {
+ } else if s, ok := comp_symbol.value.(SymbolBitFieldValue); ok {
set_ast_package_set_scoped(ast_context, comp_symbol.pkg)
//We can either have the final
@@ -2169,14 +1748,7 @@ resolve_implicit_selector :: proc(
return {}, false
}
-resolve_symbol_return :: proc(
- ast_context: ^AstContext,
- symbol: Symbol,
- ok := true,
-) -> (
- Symbol,
- bool,
-) {
+resolve_symbol_return :: proc(ast_context: ^AstContext, symbol: Symbol, ok := true) -> (Symbol, bool) {
if !ok {
return symbol, ok
}
@@ -2191,21 +1763,14 @@ resolve_symbol_return :: proc(
#partial switch &v in symbol.value {
case SymbolProcedureGroupValue:
- if symbol, ok := resolve_function_overload(
- ast_context,
- v.group.derived.(^ast.Proc_Group)^,
- ); ok {
+ if symbol, ok := resolve_function_overload(ast_context, v.group.derived.(^ast.Proc_Group)^); ok {
return symbol, true
} else {
return symbol, false
}
case SymbolProcedureValue:
if v.generic {
- if resolved_symbol, ok := resolve_generic_function(
- ast_context,
- v.arg_types,
- v.return_types,
- ); ok {
+ if resolved_symbol, ok := resolve_generic_function(ast_context, v.arg_types, v.return_types); ok {
return resolved_symbol, ok
} else {
return symbol, true
@@ -2258,10 +1823,7 @@ resolve_symbol_return :: proc(
return symbol, true
}
-resolve_unresolved_symbol :: proc(
- ast_context: ^AstContext,
- symbol: ^Symbol,
-) -> bool {
+resolve_unresolved_symbol :: proc(ast_context: ^AstContext, symbol: ^Symbol) -> bool {
if symbol.type != .Unresolved {
return true
}
@@ -2295,13 +1857,7 @@ resolve_unresolved_symbol :: proc(
return true
}
-resolve_location_identifier :: proc(
- ast_context: ^AstContext,
- node: ast.Ident,
-) -> (
- Symbol,
- bool,
-) {
+resolve_location_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (Symbol, bool) {
symbol: Symbol
if local, ok := get_local(ast_context^, node); ok {
@@ -2312,10 +1868,7 @@ resolve_location_identifier :: proc(
symbol.flags |= {.Local}
return symbol, true
} else if global, ok := ast_context.globals[node.name]; ok {
- symbol.range = common.get_token_range(
- global.name_expr,
- ast_context.file.src,
- )
+ symbol.range = common.get_token_range(global.name_expr, ast_context.file.src)
uri := common.create_uri(global.expr.pos.file, ast_context.allocator)
symbol.pkg = ast_context.document_package
symbol.uri = uri.uri
@@ -2382,11 +1935,7 @@ resolve_location_implicit_selector :: proc(
set_ast_package_set_scoped(ast_context, ast_context.document_package)
- symbol = resolve_implicit_selector(
- ast_context,
- position_context,
- implicit_selector,
- ) or_return
+ symbol = resolve_implicit_selector(ast_context, position_context, implicit_selector) or_return
#partial switch v in symbol.value {
case SymbolEnumValue:
@@ -2409,13 +1958,7 @@ resolve_location_implicit_selector :: proc(
return symbol, ok
}
-resolve_location_selector :: proc(
- ast_context: ^AstContext,
- selector_expr: ^ast.Node,
-) -> (
- symbol: Symbol,
- ok: bool,
-) {
+resolve_location_selector :: proc(ast_context: ^AstContext, selector_expr: ^ast.Node) -> (symbol: Symbol, ok: bool) {
reset_ast_context(ast_context)
set_ast_package_set_scoped(ast_context, ast_context.document_package)
@@ -2475,10 +2018,8 @@ resolve_first_symbol_from_binary_expression :: proc(
return s, ok
}
} else if _, ok := binary.left.derived.(^ast.Binary_Expr); ok {
- if s, ok := resolve_first_symbol_from_binary_expression(
- ast_context,
- cast(^ast.Binary_Expr)binary.left,
- ); ok {
+ if s, ok := resolve_first_symbol_from_binary_expression(ast_context, cast(^ast.Binary_Expr)binary.left);
+ ok {
return s, ok
}
}
@@ -2490,10 +2031,8 @@ resolve_first_symbol_from_binary_expression :: proc(
return s, ok
}
} else if _, ok := binary.right.derived.(^ast.Binary_Expr); ok {
- if s, ok := resolve_first_symbol_from_binary_expression(
- ast_context,
- cast(^ast.Binary_Expr)binary.right,
- ); ok {
+ if s, ok := resolve_first_symbol_from_binary_expression(ast_context, cast(^ast.Binary_Expr)binary.right);
+ ok {
return s, ok
}
}
@@ -2502,13 +2041,7 @@ resolve_first_symbol_from_binary_expression :: proc(
return {}, false
}
-resolve_binary_expression :: proc(
- ast_context: ^AstContext,
- binary: ^ast.Binary_Expr,
-) -> (
- Symbol,
- bool,
-) {
+resolve_binary_expression :: proc(ast_context: ^AstContext, binary: ^ast.Binary_Expr) -> (Symbol, bool) {
if binary.left == nil || binary.right == nil {
return {}, false
}
@@ -2534,23 +2067,17 @@ resolve_binary_expression :: proc(
return {}, false
}
- if symbol, ok := symbol_a.value.(SymbolProcedureValue);
- ok && len(symbol.return_types) > 0 {
+ if symbol, ok := symbol_a.value.(SymbolProcedureValue); ok && len(symbol.return_types) > 0 {
symbol_a, ok_a = resolve_type_expression(
ast_context,
- symbol.return_types[0].type != nil \
- ? symbol.return_types[0].type \
- : symbol.return_types[0].default_value,
+ symbol.return_types[0].type != nil ? symbol.return_types[0].type : symbol.return_types[0].default_value,
)
}
- if symbol, ok := symbol_b.value.(SymbolProcedureValue);
- ok && len(symbol.return_types) > 0 {
+ if symbol, ok := symbol_b.value.(SymbolProcedureValue); ok && len(symbol.return_types) > 0 {
symbol_b, ok_b = resolve_type_expression(
ast_context,
- symbol.return_types[0].type != nil \
- ? symbol.return_types[0].type \
- : symbol.return_types[0].default_value,
+ symbol.return_types[0].type != nil ? symbol.return_types[0].type : symbol.return_types[0].default_value,
)
}
@@ -2586,25 +2113,13 @@ resolve_binary_expression :: proc(
len = matrix_value_b.x,
}
return symbol_a, true
- } else if is_vector_a &&
- !is_matrix_b &&
- !is_vector_b &&
- binary.op.kind == .Mul {
+ } else if is_vector_a && !is_matrix_b && !is_vector_b && binary.op.kind == .Mul {
return symbol_a, true
- } else if is_vector_b &&
- !is_matrix_a &&
- !is_vector_a &&
- binary.op.kind == .Mul {
+ } else if is_vector_b && !is_matrix_a && !is_vector_a && binary.op.kind == .Mul {
return symbol_b, true
- } else if is_matrix_a &&
- !is_matrix_b &&
- !is_vector_b &&
- binary.op.kind == .Mul {
+ } else if is_matrix_a && !is_matrix_b && !is_vector_b && binary.op.kind == .Mul {
return symbol_a, true
- } else if is_matrix_b &&
- !is_matrix_a &&
- !is_vector_a &&
- binary.op.kind == .Mul {
+ } else if is_matrix_b && !is_matrix_a && !is_vector_a && binary.op.kind == .Mul {
return symbol_b, true
}
@@ -2613,13 +2128,7 @@ resolve_binary_expression :: proc(
return symbol_a, ok_a
}
-find_position_in_call_param :: proc(
- position_context: ^DocumentPositionContext,
- call: ast.Call_Expr,
-) -> (
- int,
- bool,
-) {
+find_position_in_call_param :: proc(position_context: ^DocumentPositionContext, call: ast.Call_Expr) -> (int, bool) {
if call.args == nil {
return 0, false
}
@@ -2633,57 +2142,32 @@ find_position_in_call_param :: proc(
return len(call.args) - 1, true
}
-make_pointer_ast :: proc(
- ast_context: ^AstContext,
- elem: ^ast.Expr,
-) -> ^ast.Pointer_Type {
- pointer := new_type(
- ast.Pointer_Type,
- elem.pos,
- elem.end,
- ast_context.allocator,
- )
+make_pointer_ast :: proc(ast_context: ^AstContext, elem: ^ast.Expr) -> ^ast.Pointer_Type {
+ pointer := new_type(ast.Pointer_Type, elem.pos, elem.end, ast_context.allocator)
pointer.elem = elem
return pointer
}
-make_bool_ast :: proc(
- ast_context: ^AstContext,
- pos: tokenizer.Pos,
- end: tokenizer.Pos,
-) -> ^ast.Ident {
+make_bool_ast :: proc(ast_context: ^AstContext, pos: tokenizer.Pos, end: tokenizer.Pos) -> ^ast.Ident {
ident := new_type(ast.Ident, pos, end, ast_context.allocator)
ident.name = "bool"
return ident
}
-make_int_ast :: proc(
- ast_context: ^AstContext,
- pos: tokenizer.Pos,
- end: tokenizer.Pos,
-) -> ^ast.Ident {
+make_int_ast :: proc(ast_context: ^AstContext, pos: tokenizer.Pos, end: tokenizer.Pos) -> ^ast.Ident {
ident := new_type(ast.Ident, pos, end, ast_context.allocator)
ident.name = "int"
return ident
}
-make_rune_ast :: proc(
- ast_context: ^AstContext,
- pos: tokenizer.Pos,
- end: tokenizer.Pos,
-) -> ^ast.Ident {
+make_rune_ast :: proc(ast_context: ^AstContext, pos: tokenizer.Pos, end: tokenizer.Pos) -> ^ast.Ident {
ident := new_type(ast.Ident, pos, end, ast_context.allocator)
ident.name = "rune"
return ident
}
-make_ident_ast :: proc(
- ast_context: ^AstContext,
- pos: tokenizer.Pos,
- end: tokenizer.Pos,
- name: string,
-) -> ^ast.Ident {
+make_ident_ast :: proc(ast_context: ^AstContext, pos: tokenizer.Pos, end: tokenizer.Pos, name: string) -> ^ast.Ident {
ident := new_type(ast.Ident, pos, end, ast_context.allocator)
ident.name = name
return ident
@@ -2711,12 +2195,7 @@ wrap_pointer :: proc(expr: ^ast.Expr, times: int) -> ^ast.Expr {
expr := expr
for i in 0 ..< times {
- new_pointer := new_type(
- ast.Pointer_Type,
- expr.pos,
- expr.end,
- context.temp_allocator,
- )
+ new_pointer := new_type(ast.Pointer_Type, expr.pos, expr.end, context.temp_allocator)
new_pointer.elem = expr
@@ -2746,10 +2225,7 @@ get_using_packages :: proc(ast_context: ^AstContext) -> []string {
return usings
}
-get_symbol_pkg_name :: proc(
- ast_context: ^AstContext,
- symbol: Symbol,
-) -> string {
+get_symbol_pkg_name :: proc(ast_context: ^AstContext, symbol: Symbol) -> string {
name := path.base(symbol.pkg, false, context.temp_allocator)
@@ -2815,11 +2291,7 @@ make_symbol_procedure_from_ast :: proc(
return symbol
}
-make_symbol_array_from_ast :: proc(
- ast_context: ^AstContext,
- v: ast.Array_Type,
- name: ast.Ident,
-) -> Symbol {
+make_symbol_array_from_ast :: proc(ast_context: ^AstContext, v: ast.Array_Type, name: ast.Ident) -> Symbol {
symbol := Symbol {
range = common.get_token_range(v.node, ast_context.file.src),
type = .Type,
@@ -2870,11 +2342,7 @@ make_symbol_dynamic_array_from_ast :: proc(
return symbol
}
-make_symbol_matrix_from_ast :: proc(
- ast_context: ^AstContext,
- v: ast.Matrix_Type,
- name: ast.Ident,
-) -> Symbol {
+make_symbol_matrix_from_ast :: proc(ast_context: ^AstContext, v: ast.Matrix_Type, name: ast.Ident) -> Symbol {
symbol := Symbol {
range = common.get_token_range(v.node, ast_context.file.src),
type = .Type,
@@ -2911,11 +2379,7 @@ make_symbol_multi_pointer_from_ast :: proc(
return symbol
}
-make_symbol_map_from_ast :: proc(
- ast_context: ^AstContext,
- v: ast.Map_Type,
- name: ast.Ident,
-) -> Symbol {
+make_symbol_map_from_ast :: proc(ast_context: ^AstContext, v: ast.Map_Type, name: ast.Ident) -> Symbol {
symbol := Symbol {
range = common.get_token_range(v.node, ast_context.file.src),
type = .Type,
@@ -2931,10 +2395,7 @@ make_symbol_map_from_ast :: proc(
return symbol
}
-make_symbol_basic_type_from_ast :: proc(
- ast_context: ^AstContext,
- n: ^ast.Ident,
-) -> Symbol {
+make_symbol_basic_type_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Ident) -> Symbol {
symbol := Symbol {
range = common.get_token_range(n^, ast_context.file.src),
type = .Variable,
@@ -3017,8 +2478,7 @@ make_symbol_enum_from_ast :: proc(
} else if field, ok := n.derived.(^ast.Field_Value); ok {
if ident, ok := field.field.derived.(^ast.Ident); ok {
append(&names, ident.name)
- } else if binary, ok := field.field.derived.(^ast.Binary_Expr);
- ok {
+ } else if binary, ok := field.field.derived.(^ast.Binary_Expr); ok {
append(&names, binary.left.derived.(^ast.Ident).name)
}
}
@@ -3083,26 +2543,19 @@ make_symbol_struct_from_ast :: proc(
for field in v.fields.list {
for n in field.names {
- if identifier, ok := n.derived.(^ast.Ident);
- ok && field.type != nil {
+ if identifier, ok := n.derived.(^ast.Ident); ok && field.type != nil {
if .Using in field.flags {
usings[len(types)] = true
}
append(&names, identifier.name)
if v.poly_params != nil {
- append(
- &types,
- clone_type(field.type, ast_context.allocator, nil),
- )
+ append(&types, clone_type(field.type, ast_context.allocator, nil))
} else {
append(&types, field.type)
}
- append(
- &ranges,
- common.get_token_range(n, ast_context.file.src),
- )
+ append(&ranges, common.get_token_range(n, ast_context.file.src))
}
}
}
@@ -3128,11 +2581,7 @@ make_symbol_struct_from_ast :: proc(
//TODO change the expand to not double copy the array, but just pass the dynamic arrays
if len(usings) > 0 || .ObjC in symbol.flags {
- symbol.value = expand_struct_usings(
- ast_context,
- symbol,
- symbol.value.(SymbolStructValue),
- )
+ symbol.value = expand_struct_usings(ast_context, symbol, symbol.value.(SymbolStructValue))
}
return symbol
@@ -3161,14 +2610,10 @@ make_symbol_bit_field_from_ast :: proc(
ranges := make([dynamic]common.Range, 0, ast_context.allocator)
for field in v.fields {
- if identifier, ok := field.name.derived.(^ast.Ident);
- ok && field.type != nil {
+ if identifier, ok := field.name.derived.(^ast.Ident); ok && field.type != nil {
append(&names, identifier.name)
append(&types, field.type)
- append(
- &ranges,
- common.get_token_range(identifier, ast_context.file.src),
- )
+ append(&ranges, common.get_token_range(identifier, ast_context.file.src))
}
}
@@ -3251,8 +2696,7 @@ get_generic_assignment :: proc(
append(results, b)
case ^Type_Assertion:
if v.type != nil {
- if unary, ok := v.type.derived.(^ast.Unary_Expr);
- ok && unary.op.kind == .Question {
+ if unary, ok := v.type.derived.(^ast.Unary_Expr); ok && unary.op.kind == .Question {
append(results, cast(^ast.Expr)&v.node)
} else {
append(results, v.type)
@@ -3268,11 +2712,7 @@ get_generic_assignment :: proc(
}
}
-get_locals_value_decl :: proc(
- file: ast.File,
- value_decl: ast.Value_Decl,
- ast_context: ^AstContext,
-) {
+get_locals_value_decl :: proc(file: ast.File, value_decl: ast.Value_Decl, ast_context: ^AstContext) {
using ast
if len(value_decl.names) <= 0 {
@@ -3406,15 +2846,13 @@ get_locals_block_stmt :: proc(
ast_context: ^AstContext,
document_position: ^DocumentPositionContext,
) {
- if !(block.pos.offset <= document_position.position &&
- document_position.position <= block.end.offset) {
+ if !(block.pos.offset <= document_position.position && document_position.position <= block.end.offset) {
return
}
for stmt in block.stmts {
if ast_context.non_mutable_only {
- if value_decl, ok := stmt.derived.(^ast.Value_Decl);
- ok && !value_decl.is_mutable {
+ if value_decl, ok := stmt.derived.(^ast.Value_Decl); ok && !value_decl.is_mutable {
get_locals_stmt(file, stmt, ast_context, document_position)
}
} else {
@@ -3424,10 +2862,7 @@ get_locals_block_stmt :: proc(
}
get_locals_using :: proc(expr: ^ast.Expr, ast_context: ^AstContext) {
- if symbol, expr, ok := unwrap_procedure_until_struct_bit_field_or_package(
- ast_context,
- expr,
- ); ok {
+ if symbol, expr, ok := unwrap_procedure_until_struct_bit_field_or_package(ast_context, expr); ok {
#partial switch v in symbol.value {
case SymbolPackageValue:
if ident, ok := expr.derived.(^ast.Ident); ok {
@@ -3435,19 +2870,9 @@ get_locals_using :: proc(expr: ^ast.Expr, ast_context: ^AstContext) {
}
case SymbolStructValue:
for name, i in v.names {
- selector := new_type(
- ast.Selector_Expr,
- v.types[i].pos,
- v.types[i].end,
- ast_context.allocator,
- )
+ selector := new_type(ast.Selector_Expr, v.types[i].pos, v.types[i].end, ast_context.allocator)
selector.expr = expr
- selector.field = new_type(
- ast.Ident,
- v.types[i].pos,
- v.types[i].end,
- ast_context.allocator,
- )
+ selector.field = new_type(ast.Ident, v.types[i].pos, v.types[i].end, ast_context.allocator)
selector.field.name = name
store_local(
ast_context,
@@ -3465,19 +2890,9 @@ get_locals_using :: proc(expr: ^ast.Expr, ast_context: ^AstContext) {
}
case SymbolBitFieldValue:
for name, i in v.names {
- selector := new_type(
- ast.Selector_Expr,
- v.types[i].pos,
- v.types[i].end,
- ast_context.allocator,
- )
+ selector := new_type(ast.Selector_Expr, v.types[i].pos, v.types[i].end, ast_context.allocator)
selector.expr = expr
- selector.field = new_type(
- ast.Ident,
- v.types[i].pos,
- v.types[i].end,
- ast_context.allocator,
- )
+ selector.field = new_type(ast.Ident, v.types[i].pos, v.types[i].end, ast_context.allocator)
selector.field.name = name
store_local(
ast_context,
@@ -3503,11 +2918,7 @@ get_locals_using_stmt :: proc(stmt: ast.Using_Stmt, ast_context: ^AstContext) {
}
}
-get_locals_assign_stmt :: proc(
- file: ast.File,
- stmt: ast.Assign_Stmt,
- ast_context: ^AstContext,
-) {
+get_locals_assign_stmt :: proc(file: ast.File, stmt: ast.Assign_Stmt, ast_context: ^AstContext) {
using ast
if stmt.lhs == nil || stmt.rhs == nil {
@@ -3550,8 +2961,7 @@ get_locals_if_stmt :: proc(
ast_context: ^AstContext,
document_position: ^DocumentPositionContext,
) {
- if !(stmt.pos.offset <= document_position.position &&
- document_position.position <= stmt.end.offset) {
+ if !(stmt.pos.offset <= document_position.position && document_position.position <= stmt.end.offset) {
return
}
@@ -3568,8 +2978,7 @@ get_locals_for_range_stmt :: proc(
) {
using ast
- if !(stmt.pos.offset <= document_position.position &&
- document_position.position <= stmt.end.offset) {
+ if !(stmt.pos.offset <= document_position.position && document_position.position <= stmt.end.offset) {
return
}
@@ -3774,8 +3183,7 @@ get_locals_for_stmt :: proc(
ast_context: ^AstContext,
document_position: ^DocumentPositionContext,
) {
- if !(stmt.pos.offset <= document_position.position &&
- document_position.position <= stmt.end.offset) {
+ if !(stmt.pos.offset <= document_position.position && document_position.position <= stmt.end.offset) {
return
}
@@ -3789,8 +3197,7 @@ get_locals_switch_stmt :: proc(
ast_context: ^AstContext,
document_position: ^DocumentPositionContext,
) {
- if !(stmt.pos.offset <= document_position.position &&
- document_position.position <= stmt.end.offset) {
+ if !(stmt.pos.offset <= document_position.position && document_position.position <= stmt.end.offset) {
return
}
@@ -3805,8 +3212,7 @@ get_locals_type_switch_stmt :: proc(
) {
using ast
- if !(stmt.pos.offset <= document_position.position &&
- document_position.position <= stmt.end.offset) {
+ if !(stmt.pos.offset <= document_position.position && document_position.position <= stmt.end.offset) {
return
}
@@ -3817,9 +3223,7 @@ get_locals_type_switch_stmt :: proc(
if block, ok := stmt.body.derived.(^Block_Stmt); ok {
for block_stmt in block.stmts {
if cause, ok := block_stmt.derived.(^Case_Clause);
- ok &&
- cause.pos.offset <= document_position.position &&
- document_position.position <= cause.end.offset {
+ ok && cause.pos.offset <= document_position.position && document_position.position <= cause.end.offset {
tag := stmt.tag.derived.(^Assign_Stmt)
if len(tag.lhs) == 1 && len(cause.list) == 1 {
@@ -3880,11 +3284,7 @@ get_locals_proc_param_and_results :: proc(
if .Using in arg.flags {
using_stmt: ast.Using_Stmt
- using_stmt.list = make(
- []^ast.Expr,
- 1,
- context.temp_allocator,
- )
+ using_stmt.list = make([]^ast.Expr, 1, context.temp_allocator)
using_stmt.list[0] = arg.type
get_locals_using_stmt(using_stmt, ast_context)
}
@@ -3959,12 +3359,7 @@ get_locals :: proc(
return
}
- get_locals_proc_param_and_results(
- file,
- proc_lit^,
- ast_context,
- document_position,
- )
+ get_locals_proc_param_and_results(file, proc_lit^, ast_context, document_position)
block: ^ast.Block_Stmt
block, ok = proc_lit.body.derived.(^ast.Block_Stmt)
@@ -3999,11 +3394,7 @@ concatenate_symbol_information :: proc {
concatenate_raw_string_information,
}
-concatenate_raw_symbol_information :: proc(
- ast_context: ^AstContext,
- symbol: Symbol,
- is_completion: bool,
-) -> string {
+concatenate_raw_symbol_information :: proc(ast_context: ^AstContext, symbol: Symbol, is_completion: bool) -> string {
return concatenate_raw_string_information(
ast_context,
symbol.pkg,
@@ -4064,10 +3455,7 @@ unwrap_procedure_until_struct_bit_field_or_package :: proc(
return
}
- symbol, ok = resolve_type_expression(
- ast_context,
- v.return_types[0].type,
- )
+ symbol, ok = resolve_type_expression(ast_context, v.return_types[0].type)
if !ok {
return
@@ -4099,13 +3487,7 @@ unwrap_ident :: proc(node: ^ast.Expr) -> (^ast.Ident, bool) {
return {}, false
}
-unwrap_enum :: proc(
- ast_context: ^AstContext,
- node: ^ast.Expr,
-) -> (
- SymbolEnumValue,
- bool,
-) {
+unwrap_enum :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (SymbolEnumValue, bool) {
if node == nil {
return {}, false
}
@@ -4144,13 +3526,7 @@ unwrap_super_enum :: proc(
return ret_value, true
}
-unwrap_union :: proc(
- ast_context: ^AstContext,
- node: ^ast.Expr,
-) -> (
- SymbolUnionValue,
- bool,
-) {
+unwrap_union :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (SymbolUnionValue, bool) {
if union_symbol, ok := resolve_type_expression(ast_context, node); ok {
//TODO: This current package is sus, it probably shouldn't be there.
ast_context.current_package = union_symbol.pkg
@@ -4162,22 +3538,12 @@ unwrap_union :: proc(
return {}, false
}
-unwrap_bitset :: proc(
- ast_context: ^AstContext,
- bitset_symbol: Symbol,
-) -> (
- SymbolEnumValue,
- bool,
-) {
+unwrap_bitset :: proc(ast_context: ^AstContext, bitset_symbol: Symbol) -> (SymbolEnumValue, bool) {
if bitset_value, ok := bitset_symbol.value.(SymbolBitSetValue); ok {
- if enum_symbol, ok := resolve_type_expression(
- ast_context,
- bitset_value.expr,
- ); ok {
+ if enum_symbol, ok := resolve_type_expression(ast_context, bitset_value.expr); ok {
if enum_value, ok := enum_symbol.value.(SymbolEnumValue); ok {
return enum_value, true
- } else if union_value, ok := enum_symbol.value.(SymbolUnionValue);
- ok {
+ } else if union_value, ok := enum_symbol.value.(SymbolUnionValue); ok {
return unwrap_super_enum(ast_context, union_value)
}
}
@@ -4186,12 +3552,7 @@ unwrap_bitset :: proc(
return {}, false
}
-get_signature :: proc(
- ast_context: ^AstContext,
- ident: ast.Ident,
- symbol: Symbol,
- was_variable := false,
-) -> string {
+get_signature :: proc(ast_context: ^AstContext, ident: ast.Ident, symbol: Symbol, was_variable := false) -> string {
if symbol.type == .Function {
return symbol.signature
}
@@ -4203,27 +3564,15 @@ get_signature :: proc(
is_variable := symbol.type == .Variable
- pointer_prefix := common.repeat(
- "^",
- symbol.pointers,
- context.temp_allocator,
- )
+ pointer_prefix := common.repeat("^", symbol.pointers, context.temp_allocator)
#partial switch v in symbol.value {
case SymbolBasicValue:
- return strings.concatenate(
- {pointer_prefix, common.node_to_string(v.ident)},
- ast_context.allocator,
- )
+ return strings.concatenate({pointer_prefix, common.node_to_string(v.ident)}, ast_context.allocator)
case SymbolBitSetValue:
return strings.concatenate(
- a = {
- pointer_prefix,
- "bit_set[",
- common.node_to_string(v.expr),
- "]",
- },
+ a = {pointer_prefix, "bit_set[", common.node_to_string(v.expr), "]"},
allocator = ast_context.allocator,
)
case SymbolEnumValue:
@@ -4234,41 +3583,26 @@ get_signature :: proc(
}
case SymbolMapValue:
return strings.concatenate(
- a = {
- pointer_prefix,
- "map[",
- common.node_to_string(v.key),
- "]",
- common.node_to_string(v.value),
- },
+ a = {pointer_prefix, "map[", common.node_to_string(v.key), "]", common.node_to_string(v.value)},
allocator = ast_context.allocator,
)
case SymbolProcedureValue:
return "proc"
case SymbolStructValue:
if is_variable {
- return strings.concatenate(
- {pointer_prefix, symbol.name},
- ast_context.allocator,
- )
+ return strings.concatenate({pointer_prefix, symbol.name}, ast_context.allocator)
} else {
return "struct"
}
case SymbolUnionValue:
if is_variable {
- return strings.concatenate(
- {pointer_prefix, symbol.name},
- ast_context.allocator,
- )
+ return strings.concatenate({pointer_prefix, symbol.name}, ast_context.allocator)
} else {
return "union"
}
case SymbolBitFieldValue:
if is_variable {
- return strings.concatenate(
- {pointer_prefix, symbol.name},
- ast_context.allocator,
- )
+ return strings.concatenate({pointer_prefix, symbol.name}, ast_context.allocator)
} else {
return "bit_field"
}
@@ -4289,13 +3623,7 @@ get_signature :: proc(
)
case SymbolFixedArrayValue:
return strings.concatenate(
- a = {
- pointer_prefix,
- "[",
- common.node_to_string(v.len),
- "]",
- common.node_to_string(v.expr),
- },
+ a = {pointer_prefix, "[", common.node_to_string(v.len), "]", common.node_to_string(v.expr)},
allocator = ast_context.allocator,
)
case SymbolMatrixValue:
@@ -4330,9 +3658,7 @@ get_signature :: proc(
return ""
}
-position_in_proc_decl :: proc(
- position_context: ^DocumentPositionContext,
-) -> bool {
+position_in_proc_decl :: proc(position_context: ^DocumentPositionContext) -> bool {
if position_context.value_decl == nil {
return false
}
@@ -4341,15 +3667,12 @@ position_in_proc_decl :: proc(
return false
}
- if _, ok := position_context.value_decl.values[0].derived.(^ast.Proc_Type);
- ok {
+ if _, ok := position_context.value_decl.values[0].derived.(^ast.Proc_Type); ok {
return true
}
- if proc_lit, ok := position_context.value_decl.values[0].derived.(^ast.Proc_Lit);
- ok {
- if proc_lit.type != nil &&
- position_in_node(proc_lit.type, position_context.position) {
+ if proc_lit, ok := position_context.value_decl.values[0].derived.(^ast.Proc_Lit); ok {
+ if proc_lit.type != nil && position_in_node(proc_lit.type, position_context.position) {
return true
}
}
@@ -4383,10 +3706,7 @@ is_lhs_comp_lit :: proc(position_context: ^DocumentPositionContext) -> bool {
return true
}
-field_exists_in_comp_lit :: proc(
- comp_lit: ^ast.Comp_Lit,
- name: string,
-) -> bool {
+field_exists_in_comp_lit :: proc(comp_lit: ^ast.Comp_Lit, name: string) -> bool {
for elem in comp_lit.elems {
if field, ok := elem.derived.(^ast.Field_Value); ok {
if field.field != nil {
@@ -4405,10 +3725,7 @@ field_exists_in_comp_lit :: proc(
/*
Parser gives ranges of expression, but not actually where the commas are placed.
*/
-get_call_commas :: proc(
- position_context: ^DocumentPositionContext,
- document: ^Document,
-) {
+get_call_commas :: proc(position_context: ^DocumentPositionContext, document: ^Document) {
if position_context.call == nil {
return
}
@@ -4458,10 +3775,7 @@ type_to_string :: proc(ast_context: ^AstContext, expr: ^ast.Expr) -> string {
return common.node_to_string(expr)
}
-get_document_position_decls :: proc(
- decls: []^ast.Stmt,
- position_context: ^DocumentPositionContext,
-) -> bool {
+get_document_position_decls :: proc(decls: []^ast.Stmt, position_context: ^DocumentPositionContext) -> bool {
exists_in_decl := false
for decl in decls {
if position_in_node(decl, position_context.position) {
@@ -4494,15 +3808,9 @@ get_document_position_context :: proc(
position_context.file = document.ast
position_context.line = position.line
- position_context.functions = make(
- [dynamic]^ast.Proc_Lit,
- context.temp_allocator,
- )
+ position_context.functions = make([dynamic]^ast.Proc_Lit, context.temp_allocator)
- absolute_position, ok := common.get_absolute_position(
- position,
- document.text,
- )
+ absolute_position, ok := common.get_absolute_position(position, document.text)
if !ok {
log.error("failed to get absolute position")
@@ -4511,10 +3819,7 @@ get_document_position_context :: proc(
position_context.position = absolute_position
- exists_in_decl := get_document_position_decls(
- document.ast.decls[:],
- &position_context,
- )
+ exists_in_decl := get_document_position_decls(document.ast.decls[:], &position_context)
for import_stmt in document.ast.imports {
if position_in_node(import_stmt, position_context.position) {
@@ -4527,17 +3832,11 @@ get_document_position_context :: proc(
position_context.abort_completion = true
}
- if !position_in_node(
- position_context.comp_lit,
- position_context.position,
- ) {
+ if !position_in_node(position_context.comp_lit, position_context.position) {
position_context.comp_lit = nil
}
- if !position_in_node(
- position_context.parent_comp_lit,
- position_context.position,
- ) {
+ if !position_in_node(position_context.parent_comp_lit, position_context.position) {
position_context.parent_comp_lit = nil
}
@@ -4549,30 +3848,16 @@ get_document_position_context :: proc(
position_context.binary = nil
}
- if !position_in_node(
- position_context.parent_binary,
- position_context.position,
- ) {
+ if !position_in_node(position_context.parent_binary, position_context.position) {
position_context.parent_binary = nil
}
- if hint == .Completion &&
- position_context.selector == nil &&
- position_context.field == nil {
- fallback_position_context_completion(
- document,
- position,
- &position_context,
- )
+ if hint == .Completion && position_context.selector == nil && position_context.field == nil {
+ fallback_position_context_completion(document, position, &position_context)
}
- if (hint == .SignatureHelp || hint == .Completion) &&
- position_context.call == nil {
- fallback_position_context_signature(
- document,
- position,
- &position_context,
- )
+ if (hint == .SignatureHelp || hint == .Completion) && position_context.call == nil {
+ fallback_position_context_signature(document, position, &position_context)
}
if hint == .SignatureHelp {
@@ -4675,9 +3960,7 @@ fallback_position_context_completion :: proc(
if i >= 0 && position_context.file.src[end] == '.' {
empty_dot = true
end -= 1
- } else if i >= 0 &&
- position_context.file.src[max(0, end - 1)] == '-' &&
- position_context.file.src[end] == '>' {
+ } else if i >= 0 && position_context.file.src[max(0, end - 1)] == '-' && position_context.file.src[end] == '>' {
empty_arrow = true
end -= 2
position_context.arrow = true
@@ -4728,12 +4011,7 @@ fallback_position_context_completion :: proc(
file = &position_context.file,
}
- tokenizer.init(
- &p.tok,
- str,
- position_context.file.fullpath,
- common.parser_warning_handler,
- )
+ tokenizer.init(&p.tok, str, position_context.file.fullpath, common.parser_warning_handler)
p.tok.ch = ' '
p.tok.line_count = position.line + 1
@@ -4767,12 +4045,7 @@ fallback_position_context_completion :: proc(
//this is most likely because of use of 'in', 'context', etc.
//try to go back one dot.
- src_with_dot := string(
- position_context.file.src[0:min(
- len(position_context.file.src),
- end_offset + 1,
- )],
- )
+ src_with_dot := string(position_context.file.src[0:min(len(position_context.file.src), end_offset + 1)])
last_dot := strings.last_index(src_with_dot, ".")
if last_dot == -1 {
@@ -4870,12 +4143,7 @@ fallback_position_context_signature :: proc(
file = &position_context.file,
}
- tokenizer.init(
- &p.tok,
- str,
- position_context.file.fullpath,
- common.parser_warning_handler,
- )
+ tokenizer.init(&p.tok, str, position_context.file.fullpath, common.parser_warning_handler)
p.tok.ch = ' '
p.tok.line_count = position.line
@@ -4911,39 +4179,23 @@ get_document_position :: proc {
get_document_position_node,
}
-get_document_position_array :: proc(
- array: $A/[]^$T,
- position_context: ^DocumentPositionContext,
-) {
+get_document_position_array :: proc(array: $A/[]^$T, position_context: ^DocumentPositionContext) {
for elem, i in array {
get_document_position(elem, position_context)
}
}
-get_document_position_dynamic_array :: proc(
- array: $A/[dynamic]^$T,
- position_context: ^DocumentPositionContext,
-) {
+get_document_position_dynamic_array :: proc(array: $A/[dynamic]^$T, position_context: ^DocumentPositionContext) {
for elem, i in array {
get_document_position(elem, position_context)
}
}
-position_in_node :: proc(
- node: ^ast.Node,
- position: common.AbsolutePosition,
-) -> bool {
- return(
- node != nil &&
- node.pos.offset <= position &&
- position <= node.end.offset \
- )
+position_in_node :: proc(node: ^ast.Node, position: common.AbsolutePosition) -> bool {
+ return node != nil && node.pos.offset <= position && position <= node.end.offset
}
-get_document_position_label :: proc(
- label: ^ast.Expr,
- position_context: ^DocumentPositionContext,
-) {
+get_document_position_label :: proc(label: ^ast.Expr, position_context: ^DocumentPositionContext) {
if label == nil {
return
}
@@ -4953,10 +4205,7 @@ get_document_position_label :: proc(
}
}
-get_document_position_node :: proc(
- node: ^ast.Node,
- position_context: ^DocumentPositionContext,
-) {
+get_document_position_node :: proc(node: ^ast.Node, position_context: ^DocumentPositionContext) {
using ast
if node == nil {
@@ -5046,8 +4295,7 @@ get_document_position_node :: proc(
}
}
case ^Selector_Expr:
- if position_context.hint == .Definition ||
- position_context.hint == .Hover && n.field != nil {
+ 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 = node
@@ -5160,8 +4408,7 @@ get_document_position_node :: proc(
get_document_position(n.attributes, position_context)
for name in n.names {
- if position_in_node(name, position_context.position) &&
- n.end.line - 1 == position_context.line {
+ if position_in_node(name, position_context.position) && n.end.line - 1 == position_context.line {
position_context.abort_completion = true
break
}
diff --git a/src/server/build.odin b/src/server/build.odin
index cc3a1ef..a46a577 100644
--- a/src/server/build.odin
+++ b/src/server/build.odin
@@ -94,10 +94,7 @@ try_build_package :: proc(pkg_name: string) {
return
}
- matches, err := filepath.glob(
- fmt.tprintf("%v/*.odin", pkg_name),
- context.temp_allocator,
- )
+ matches, err := filepath.glob(fmt.tprintf("%v/*.odin", pkg_name), context.temp_allocator)
if err != .None {
log.errorf("Failed to glob %v for indexing package", pkg_name)
@@ -105,11 +102,7 @@ try_build_package :: proc(pkg_name: string) {
}
arena: runtime.Arena
- result := runtime.arena_init(
- &arena,
- mem.Megabyte * 40,
- runtime.default_allocator(),
- )
+ result := runtime.arena_init(&arena, mem.Megabyte * 40, runtime.default_allocator())
defer runtime.arena_destroy(&arena)
{
@@ -123,10 +116,7 @@ try_build_package :: proc(pkg_name: string) {
data, ok := os.read_entire_file(fullpath, context.allocator)
if !ok {
- log.errorf(
- "failed to read entire file for indexing %v",
- fullpath,
- )
+ log.errorf("failed to read entire file for indexing %v", fullpath)
continue
}
@@ -156,8 +146,7 @@ try_build_package :: proc(pkg_name: string) {
ok = parser.parse_file(&p, &file)
if !ok {
- if !strings.contains(fullpath, "builtin.odin") &&
- !strings.contains(fullpath, "intrinsics.odin") {
+ if !strings.contains(fullpath, "builtin.odin") && !strings.contains(fullpath, "intrinsics.odin") {
log.errorf("error in parse file for indexing %v", fullpath)
}
continue
@@ -171,22 +160,14 @@ try_build_package :: proc(pkg_name: string) {
}
}
- build_cache.loaded_pkgs[strings.clone(pkg_name, indexer.index.collection.allocator)] =
- PackageCacheInfo {
- timestamp = time.now(),
- }
+ build_cache.loaded_pkgs[strings.clone(pkg_name, indexer.index.collection.allocator)] = PackageCacheInfo {
+ timestamp = time.now(),
+ }
}
setup_index :: proc() {
- build_cache.loaded_pkgs = make(
- map[string]PackageCacheInfo,
- 50,
- context.allocator,
- )
- symbol_collection := make_symbol_collection(
- context.allocator,
- &common.config,
- )
+ build_cache.loaded_pkgs = make(map[string]PackageCacheInfo, 50, context.allocator)
+ symbol_collection := make_symbol_collection(context.allocator, &common.config)
indexer.index = make_memory_index(symbol_collection)
dir_exe := common.get_executable_path(context.temp_allocator)
diff --git a/src/server/caches.odin b/src/server/caches.odin
index a861cc6..73a7613 100644
--- a/src/server/caches.odin
+++ b/src/server/caches.odin
@@ -17,16 +17,10 @@ FileResolveCache :: struct {
file_resolve_cache: FileResolveCache
-resolve_entire_file_cached :: proc(
- document: ^Document,
-) -> map[uintptr]SymbolAndNode {
+resolve_entire_file_cached :: proc(document: ^Document) -> map[uintptr]SymbolAndNode {
if document.uri.uri not_in file_resolve_cache.files {
file_resolve_cache.files[document.uri.uri] = FileResolve {
- symbols = resolve_entire_file(
- document,
- .None,
- common.scratch_allocator(document.allocator),
- ),
+ symbols = resolve_entire_file(document, .None, common.scratch_allocator(document.allocator)),
}
}
diff --git a/src/server/check.odin b/src/server/check.odin
index a7663f1..72f8c5d 100644
--- a/src/server/check.odin
+++ b/src/server/check.odin
@@ -44,14 +44,7 @@ Json_Errors :: struct {
//If the user does not specify where to call odin check, it'll just find all directory with odin, and call them seperately.
fallback_find_odin_directories :: proc(config: ^common.Config) -> []string {
- walk_proc :: proc(
- info: os.File_Info,
- in_err: os.Errno,
- user_data: rawptr,
- ) -> (
- err: os.Errno,
- skip_dir: bool,
- ) {
+ walk_proc :: proc(info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> (err: os.Errno, skip_dir: bool) {
data := cast(^[dynamic]string)user_data
if !info.is_dir && filepath.ext(info.name) == ".odin" {
@@ -67,10 +60,7 @@ fallback_find_odin_directories :: proc(config: ^common.Config) -> []string {
data := make([dynamic]string, context.temp_allocator)
if len(config.workspace_folders) > 0 {
- if uri, ok := common.parse_uri(
- config.workspace_folders[0].uri,
- context.temp_allocator,
- ); ok {
+ if uri, ok := common.parse_uri(config.workspace_folders[0].uri, context.temp_allocator); ok {
filepath.walk(uri.path, walk_proc, &data)
}
}
@@ -78,12 +68,7 @@ fallback_find_odin_directories :: proc(config: ^common.Config) -> []string {
return data[:]
}
-check :: proc(
- paths: []string,
- uri: common.Uri,
- writer: ^Writer,
- config: ^common.Config,
-) {
+check :: proc(paths: []string, uri: common.Uri, writer: ^Writer, config: ^common.Config) {
paths := paths
if len(paths) == 0 {
@@ -107,10 +92,7 @@ check :: proc(
if k == "" || k == "core" || k == "vendor" || k == "base" {
continue
}
- strings.write_string(
- &collection_builder,
- fmt.aprintf("-collection:%v=\"%v\" ", k, v),
- )
+ strings.write_string(&collection_builder, fmt.aprintf("-collection:%v=\"%v\" ", k, v))
}
errors := make(map[string][dynamic]Diagnostic, 0, context.temp_allocator)
@@ -124,8 +106,7 @@ check :: proc(
command = "odin"
}
- entry_point_opt :=
- filepath.ext(path) == ".odin" ? "-file" : "-no-entry-point"
+ entry_point_opt := filepath.ext(path) == ".odin" ? "-file" : "-no-entry-point"
slice.zero(data)
@@ -142,11 +123,7 @@ check :: proc(
),
&data,
); !ok {
- log.errorf(
- "Odin check failed with code %v for file %v",
- code,
- path,
- )
+ log.errorf("Odin check failed with code %v for file %v", code, path)
return
}
@@ -156,17 +133,9 @@ check :: proc(
json_errors: Json_Errors
- if res := json.unmarshal(
- buffer,
- &json_errors,
- json.DEFAULT_SPECIFICATION,
- context.temp_allocator,
- ); res != nil {
- log.errorf(
- "Failed to unmarshal check results: %v, %v",
- res,
- string(buffer),
- )
+ if res := json.unmarshal(buffer, &json_errors, json.DEFAULT_SPECIFICATION, context.temp_allocator);
+ res != nil {
+ log.errorf("Failed to unmarshal check results: %v, %v", res, string(buffer))
}
for error in json_errors.errors {
@@ -176,18 +145,12 @@ check :: proc(
message := strings.join(error.msgs, " ", context.temp_allocator)
- if strings.contains(
- message,
- "Redeclaration of 'main' in this scope",
- ) {
+ if strings.contains(message, "Redeclaration of 'main' in this scope") {
continue
}
if error.pos.file not_in errors {
- errors[error.pos.file] = make(
- [dynamic]Diagnostic,
- context.temp_allocator,
- )
+ errors[error.pos.file] = make([dynamic]Diagnostic, context.temp_allocator)
}
append(
@@ -196,14 +159,8 @@ check :: proc(
code = "checker",
severity = .Error if error.type == "error" else .Warning,
range = {
- start = {
- character = error.pos.column - 1,
- line = error.pos.line - 1,
- },
- end = {
- character = error.pos.end_column - 1,
- line = error.pos.line - 1,
- },
+ start = {character = error.pos.column - 1, line = error.pos.line - 1},
+ end = {character = error.pos.end_column - 1, line = error.pos.line - 1},
},
message = message,
},
diff --git a/src/server/clone.odin b/src/server/clone.odin
index 507e753..0da78ae 100644
--- a/src/server/clone.odin
+++ b/src/server/clone.odin
@@ -12,11 +12,7 @@ import "core:strings"
_ :: intrinsics
-new_type :: proc(
- $T: typeid,
- pos, end: tokenizer.Pos,
- allocator: mem.Allocator,
-) -> ^T {
+new_type :: proc($T: typeid, pos, end: tokenizer.Pos, allocator: mem.Allocator) -> ^T {
n, _ := mem.new(T, allocator)
n.pos = pos
n.end = end
@@ -39,11 +35,7 @@ clone_type :: proc {
clone_dynamic_array,
}
-clone_array :: proc(
- array: $A/[]^$T,
- allocator: mem.Allocator,
- unique_strings: ^map[string]string,
-) -> A {
+clone_array :: proc(array: $A/[]^$T, allocator: mem.Allocator, unique_strings: ^map[string]string) -> A {
if len(array) == 0 {
return nil
}
@@ -69,19 +61,11 @@ clone_dynamic_array :: proc(
return res
}
-clone_expr :: proc(
- node: ^ast.Expr,
- allocator: mem.Allocator,
- unique_strings: ^map[string]string,
-) -> ^ast.Expr {
+clone_expr :: proc(node: ^ast.Expr, allocator: mem.Allocator, unique_strings: ^map[string]string) -> ^ast.Expr {
return cast(^ast.Expr)clone_node(node, allocator, unique_strings)
}
-clone_node :: proc(
- node: ^ast.Node,
- allocator: mem.Allocator,
- unique_strings: ^map[string]string,
-) -> ^ast.Node {
+clone_node :: proc(node: ^ast.Node, allocator: mem.Allocator, unique_strings: ^map[string]string) -> ^ast.Node {
using ast
if node == nil {
return nil
@@ -112,21 +96,13 @@ clone_node :: proc(
res_ptr_any.id = ti.id
if unique_strings != nil && node.pos.file != "" {
- res.pos.file = get_index_unique_string(
- unique_strings,
- allocator,
- node.pos.file,
- )
+ res.pos.file = get_index_unique_string(unique_strings, allocator, node.pos.file)
} else {
res.pos.file = node.pos.file
}
if unique_strings != nil && node.end.file != "" {
- res.end.file = get_index_unique_string(
- unique_strings,
- allocator,
- node.end.file,
- )
+ res.end.file = get_index_unique_string(unique_strings, allocator, node.end.file)
} else {
res.end.file = node.end.file
}
@@ -135,12 +111,10 @@ clone_node :: proc(
res_ptr := reflect.deref(res_ptr_any)
- if de := reflect.struct_field_value_by_name(res_ptr, "derived_expr", true);
- de != nil {
+ if de := reflect.struct_field_value_by_name(res_ptr, "derived_expr", true); de != nil {
reflect.set_union_value(de, res_ptr_any)
}
- if ds := reflect.struct_field_value_by_name(res_ptr, "derived_stmt", true);
- ds != nil {
+ if ds := reflect.struct_field_value_by_name(res_ptr, "derived_stmt", true); ds != nil {
reflect.set_union_value(ds, res_ptr_any)
}
diff --git a/src/server/collector.odin b/src/server/collector.odin
index 92b4137..26e4809 100644
--- a/src/server/collector.odin
+++ b/src/server/collector.odin
@@ -47,15 +47,8 @@ get_index_unique_string :: proc {
get_index_unique_string_collection_raw,
}
-get_index_unique_string_collection :: proc(
- collection: ^SymbolCollection,
- s: string,
-) -> string {
- return get_index_unique_string_collection_raw(
- &collection.unique_strings,
- collection.allocator,
- s,
- )
+get_index_unique_string_collection :: proc(collection: ^SymbolCollection, s: string) -> string {
+ return get_index_unique_string_collection_raw(&collection.unique_strings, collection.allocator, s)
}
get_index_unique_string_collection_raw :: proc(
@@ -71,10 +64,7 @@ get_index_unique_string_collection_raw :: proc(
return unique_strings[s]
}
-make_symbol_collection :: proc(
- allocator := context.allocator,
- config: ^common.Config,
-) -> SymbolCollection {
+make_symbol_collection :: proc(allocator := context.allocator, config: ^common.Config) -> SymbolCollection {
return SymbolCollection {
allocator = allocator,
config = config,
@@ -121,11 +111,7 @@ collect_procedure_fields :: proc(
if return_list != nil {
for ret in return_list.list {
- cloned := cast(^ast.Field)clone_type(
- ret,
- collection.allocator,
- &collection.unique_strings,
- )
+ cloned := cast(^ast.Field)clone_type(ret, collection.allocator, &collection.unique_strings)
replace_package_alias(cloned, package_map, collection)
append(&returns, cloned)
}
@@ -133,11 +119,7 @@ collect_procedure_fields :: proc(
if arg_list != nil {
for arg in arg_list.list {
- cloned := cast(^ast.Field)clone_type(
- arg,
- collection.allocator,
- &collection.unique_strings,
- )
+ cloned := cast(^ast.Field)clone_type(arg, collection.allocator, &collection.unique_strings)
replace_package_alias(cloned, package_map, collection)
append(&args, cloned)
}
@@ -168,11 +150,7 @@ collect_struct_fields :: proc(
if ident, ok := n.derived.(^ast.Ident); ok {
append(&names, get_index_unique_string(collection, ident.name))
- cloned := clone_type(
- field.type,
- collection.allocator,
- &collection.unique_strings,
- )
+ cloned := clone_type(field.type, collection.allocator, &collection.unique_strings)
replace_package_alias(cloned, package_map, collection)
append(&types, cloned)
@@ -210,11 +188,7 @@ collect_bit_field_fields :: proc(
if ident, ok := field.name.derived.(^ast.Ident); ok {
append(&names, get_index_unique_string(collection, ident.name))
- cloned := clone_type(
- field.type,
- collection.allocator,
- &collection.unique_strings,
- )
+ cloned := clone_type(field.type, collection.allocator, &collection.unique_strings)
replace_package_alias(cloned, package_map, collection)
append(&types, cloned)
@@ -248,15 +222,8 @@ collect_enum_fields :: proc(
} else if field, ok := n.derived.(^ast.Field_Value); ok {
if ident, ok := field.field.derived.(^ast.Ident); ok {
append(&names, get_index_unique_string(collection, ident.name))
- } else if binary, ok := field.field.derived.(^ast.Binary_Expr);
- ok {
- append(
- &names,
- get_index_unique_string(
- collection,
- binary.left.derived.(^ast.Ident).name,
- ),
- )
+ } else if binary, ok := field.field.derived.(^ast.Binary_Expr); ok {
+ append(&names, get_index_unique_string(collection, binary.left.derived.(^ast.Ident).name))
}
}
}
@@ -277,11 +244,7 @@ collect_union_fields :: proc(
types := make([dynamic]^ast.Expr, 0, collection.allocator)
for variant in union_type.variants {
- cloned := clone_type(
- variant,
- collection.allocator,
- &collection.unique_strings,
- )
+ cloned := clone_type(variant, collection.allocator, &collection.unique_strings)
replace_package_alias(cloned, package_map, collection)
append(&types, cloned)
}
@@ -299,11 +262,7 @@ collect_bitset_field :: proc(
bitset_type: ast.Bit_Set_Type,
package_map: map[string]string,
) -> SymbolBitSetValue {
- cloned := clone_type(
- bitset_type.elem,
- collection.allocator,
- &collection.unique_strings,
- )
+ cloned := clone_type(bitset_type.elem, collection.allocator, &collection.unique_strings)
replace_package_alias(cloned, package_map, collection)
return SymbolBitSetValue{expr = cloned}
@@ -314,11 +273,7 @@ collect_slice :: proc(
array: ast.Array_Type,
package_map: map[string]string,
) -> SymbolSliceValue {
- elem := clone_type(
- array.elem,
- collection.allocator,
- &collection.unique_strings,
- )
+ elem := clone_type(array.elem, collection.allocator, &collection.unique_strings)
replace_package_alias(elem, package_map, collection)
@@ -330,16 +285,8 @@ collect_array :: proc(
array: ast.Array_Type,
package_map: map[string]string,
) -> SymbolFixedArrayValue {
- elem := clone_type(
- array.elem,
- collection.allocator,
- &collection.unique_strings,
- )
- len := clone_type(
- array.len,
- collection.allocator,
- &collection.unique_strings,
- )
+ elem := clone_type(array.elem, collection.allocator, &collection.unique_strings)
+ len := clone_type(array.len, collection.allocator, &collection.unique_strings)
replace_package_alias(elem, package_map, collection)
replace_package_alias(len, package_map, collection)
@@ -347,17 +294,9 @@ collect_array :: proc(
return SymbolFixedArrayValue{expr = elem, len = len}
}
-collect_map :: proc(
- collection: ^SymbolCollection,
- m: ast.Map_Type,
- package_map: map[string]string,
-) -> SymbolMapValue {
+collect_map :: proc(collection: ^SymbolCollection, m: ast.Map_Type, package_map: map[string]string) -> SymbolMapValue {
key := clone_type(m.key, collection.allocator, &collection.unique_strings)
- value := clone_type(
- m.value,
- collection.allocator,
- &collection.unique_strings,
- )
+ value := clone_type(m.value, collection.allocator, &collection.unique_strings)
replace_package_alias(key, package_map, collection)
replace_package_alias(value, package_map, collection)
@@ -370,11 +309,7 @@ collect_dynamic_array :: proc(
array: ast.Dynamic_Array_Type,
package_map: map[string]string,
) -> SymbolDynamicArrayValue {
- elem := clone_type(
- array.elem,
- collection.allocator,
- &collection.unique_strings,
- )
+ elem := clone_type(array.elem, collection.allocator, &collection.unique_strings)
replace_package_alias(elem, package_map, collection)
@@ -386,23 +321,11 @@ collect_matrix :: proc(
mat: ast.Matrix_Type,
package_map: map[string]string,
) -> SymbolMatrixValue {
- elem := clone_type(
- mat.elem,
- collection.allocator,
- &collection.unique_strings,
- )
-
- y := clone_type(
- mat.column_count,
- collection.allocator,
- &collection.unique_strings,
- )
-
- x := clone_type(
- mat.row_count,
- collection.allocator,
- &collection.unique_strings,
- )
+ elem := clone_type(mat.elem, collection.allocator, &collection.unique_strings)
+
+ y := clone_type(mat.column_count, collection.allocator, &collection.unique_strings)
+
+ x := clone_type(mat.row_count, collection.allocator, &collection.unique_strings)
replace_package_alias(elem, package_map, collection)
replace_package_alias(x, package_map, collection)
@@ -416,11 +339,7 @@ collect_multi_pointer :: proc(
array: ast.Multi_Pointer_Type,
package_map: map[string]string,
) -> SymbolMultiPointer {
- elem := clone_type(
- array.elem,
- collection.allocator,
- &collection.unique_strings,
- )
+ elem := clone_type(array.elem, collection.allocator, &collection.unique_strings)
replace_package_alias(elem, package_map, collection)
@@ -438,13 +357,8 @@ collect_generic :: proc(
//In the c package code it uses a documentation package(builtin).
if selector, ok := expr.derived.(^ast.Selector_Expr); ok {
if ident, ok := selector.expr.derived.(^ast.Ident); ok {
- if ident.name == "builtin" &&
- strings.contains(uri, "Odin/core/c/c.odin") {
- cloned := clone_type(
- selector.field,
- collection.allocator,
- &collection.unique_strings,
- )
+ if ident.name == "builtin" && strings.contains(uri, "Odin/core/c/c.odin") {
+ cloned := clone_type(selector.field, collection.allocator, &collection.unique_strings)
replace_package_alias(cloned, package_map, collection)
value := SymbolGenericValue {
expr = cloned,
@@ -454,11 +368,7 @@ collect_generic :: proc(
}
}
- cloned := clone_type(
- expr,
- collection.allocator,
- &collection.unique_strings,
- )
+ cloned := clone_type(expr, collection.allocator, &collection.unique_strings)
replace_package_alias(cloned, package_map, collection)
value := SymbolGenericValue {
@@ -510,44 +420,24 @@ collect_method :: proc(collection: ^SymbolCollection, symbol: Symbol) {
}
}
-collect_objc :: proc(
- collection: ^SymbolCollection,
- attributes: []^ast.Attribute,
- symbol: Symbol,
-) {
+collect_objc :: proc(collection: ^SymbolCollection, attributes: []^ast.Attribute, symbol: Symbol) {
pkg := &collection.packages[symbol.pkg]
if value, ok := symbol.value.(SymbolProcedureValue); ok {
- objc_name, found_objc_name := common.get_attribute_objc_name(
- attributes,
- )
+ objc_name, found_objc_name := common.get_attribute_objc_name(attributes)
- if objc_type := common.get_attribute_objc_type(attributes);
- objc_type != nil && found_objc_name {
+ if objc_type := common.get_attribute_objc_type(attributes); objc_type != nil && found_objc_name {
if struct_ident, ok := objc_type.derived.(^ast.Ident); ok {
- struct_name := get_index_unique_string_collection(
- collection,
- struct_ident.name,
- )
+ struct_name := get_index_unique_string_collection(collection, struct_ident.name)
objc_struct := &pkg.objc_structs[struct_name]
if objc_struct == nil {
pkg.objc_structs[struct_name] = {}
objc_struct = &pkg.objc_structs[struct_name]
- objc_struct.functions = make(
- [dynamic]ObjcFunction,
- 0,
- 10,
- collection.allocator,
- )
- objc_struct.ranges = make(
- [dynamic]common.Range,
- 0,
- 10,
- collection.allocator,
- )
+ objc_struct.functions = make([dynamic]ObjcFunction, 0, 10, collection.allocator)
+ objc_struct.ranges = make([dynamic]common.Range, 0, 10, collection.allocator)
objc_struct.pkg = symbol.pkg
}
@@ -556,10 +446,7 @@ collect_objc :: proc(
append(
&objc_struct.functions,
ObjcFunction {
- logical_name = get_index_unique_string_collection(
- collection,
- objc_name,
- ),
+ logical_name = get_index_unique_string_collection(collection, objc_name),
physical_name = symbol.name,
},
)
@@ -572,11 +459,7 @@ collect_imports :: proc(collection: ^SymbolCollection, file: ast.File) {
}
-collect_symbols :: proc(
- collection: ^SymbolCollection,
- file: ast.File,
- uri: string,
-) -> common.Error {
+collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error {
forward, _ := filepath.to_slash(file.fullpath, context.temp_allocator)
directory := path.dir(forward, context.temp_allocator)
package_map := get_package_mapping(file, collection.config, directory)
@@ -627,8 +510,7 @@ collect_symbols :: proc(
)
}
- if _, is_objc := common.get_attribute_objc_name(expr.attributes);
- is_objc {
+ if _, is_objc := common.get_attribute_objc_name(expr.attributes); is_objc {
symbol.flags |= {.ObjC}
if common.get_attribute_objc_is_class_method(expr.attributes) {
symbol.flags |= {.ObjCIsClassMethod}
@@ -649,26 +531,15 @@ collect_symbols :: proc(
token = v^
token_type = .Function
symbol.value = SymbolProcedureGroupValue {
- group = clone_type(
- col_expr,
- collection.allocator,
- &collection.unique_strings,
- ),
+ group = clone_type(col_expr, collection.allocator, &collection.unique_strings),
}
case ^ast.Struct_Type:
token = v^
token_type = .Struct
- symbol.value = collect_struct_fields(
- collection,
- v^,
- package_map,
- file,
- )
+ symbol.value = collect_struct_fields(collection, v^, package_map, file)
symbol.signature = "struct"
- if _, is_objc := common.get_attribute_objc_class_name(
- expr.attributes,
- ); is_objc {
+ if _, is_objc := common.get_attribute_objc_class_name(expr.attributes); is_objc {
symbol.flags |= {.ObjC}
if common.get_attribute_objc_is_class_method(expr.attributes) {
symbol.flags |= {.ObjCIsClassMethod}
@@ -677,12 +548,7 @@ collect_symbols :: proc(
case ^ast.Enum_Type:
token = v^
token_type = .Enum
- symbol.value = collect_enum_fields(
- collection,
- v.fields,
- package_map,
- file,
- )
+ symbol.value = collect_enum_fields(collection, v.fields, package_map, file)
symbol.signature = "enum"
case ^ast.Union_Type:
token = v^
@@ -697,12 +563,7 @@ collect_symbols :: proc(
case ^ast.Bit_Field_Type:
token = v^
token_type = .Struct
- symbol.value = collect_bit_field_fields(
- collection,
- v.fields,
- package_map,
- file,
- )
+ symbol.value = collect_bit_field_fields(collection, v.fields, package_map, file)
symbol.signature = "bit_field"
case ^ast.Map_Type:
token = v^
@@ -735,20 +596,10 @@ collect_symbols :: proc(
symbol.value = collect_generic(collection, ident, package_map, uri)
case ^ast.Basic_Lit:
token = v^
- symbol.value = collect_generic(
- collection,
- col_expr,
- package_map,
- uri,
- )
+ symbol.value = collect_generic(collection, col_expr, package_map, uri)
case ^ast.Ident:
token = v^
- symbol.value = collect_generic(
- collection,
- col_expr,
- package_map,
- uri,
- )
+ symbol.value = collect_generic(collection, col_expr, package_map, uri)
if expr.mutable {
token_type = .Variable
@@ -757,12 +608,7 @@ collect_symbols :: proc(
}
case:
// default
- symbol.value = collect_generic(
- collection,
- col_expr,
- package_map,
- uri,
- )
+ symbol.value = collect_generic(collection, col_expr, package_map, uri)
if expr.mutable {
token_type = .Variable
@@ -815,16 +661,8 @@ collect_symbols :: proc(
collection.packages[symbol.pkg] = {}
pkg = &collection.packages[symbol.pkg]
pkg.symbols = make(map[string]Symbol, 100, collection.allocator)
- pkg.methods = make(
- map[Method][dynamic]Symbol,
- 100,
- collection.allocator,
- )
- pkg.objc_structs = make(
- map[string]ObjcStruct,
- 5,
- collection.allocator,
- )
+ pkg.methods = make(map[Method][dynamic]Symbol, 100, collection.allocator)
+ pkg.objc_structs = make(map[string]ObjcStruct, 5, collection.allocator)
}
if .ObjC in symbol.flags {
@@ -853,11 +691,7 @@ Reference :: struct {
/*
Gets the map from import alias to absolute package directory
*/
-get_package_mapping :: proc(
- file: ast.File,
- config: ^common.Config,
- directory: string,
-) -> map[string]string {
+get_package_mapping :: proc(file: ast.File, config: ^common.Config, directory: string) -> map[string]string {
package_map := make(map[string]string, 0, context.temp_allocator)
for imp, index in file.imports {
@@ -866,8 +700,7 @@ get_package_mapping :: proc(
continue
}
- if i := strings.index(imp.fullpath, ":");
- i != -1 && i != len(imp.fullpath) - 1 {
+ if i := strings.index(imp.fullpath, ":"); i != -1 && i != len(imp.fullpath) - 1 {
collection := imp.fullpath[1:i]
p := imp.fullpath[i + 1:len(imp.fullpath) - 1]
@@ -879,10 +712,7 @@ get_package_mapping :: proc(
name: string
- full := path.join(
- elems = {dir, p},
- allocator = context.temp_allocator,
- )
+ full := path.join(elems = {dir, p}, allocator = context.temp_allocator)
if imp.name.text != "" {
name = imp.name.text
@@ -925,11 +755,7 @@ replace_package_alias :: proc {
replace_package_alias_dynamic_array,
}
-replace_package_alias_array :: proc(
- array: $A/[]^$T,
- package_map: map[string]string,
- collection: ^SymbolCollection,
-) {
+replace_package_alias_array :: proc(array: $A/[]^$T, package_map: map[string]string, collection: ^SymbolCollection) {
for elem, i in array {
replace_package_alias(elem, package_map, collection)
}
@@ -945,19 +771,11 @@ replace_package_alias_dynamic_array :: proc(
}
}
-replace_package_alias_expr :: proc(
- node: ^ast.Expr,
- package_map: map[string]string,
- collection: ^SymbolCollection,
-) {
+replace_package_alias_expr :: proc(node: ^ast.Expr, package_map: map[string]string, collection: ^SymbolCollection) {
replace_package_alias_node(node, package_map, collection)
}
-replace_package_alias_node :: proc(
- node: ^ast.Node,
- package_map: map[string]string,
- collection: ^SymbolCollection,
-) {
+replace_package_alias_node :: proc(node: ^ast.Node, package_map: map[string]string, collection: ^SymbolCollection) {
using ast
if node == nil {
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 030a361..1b7249d 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -42,11 +42,7 @@ get_completion_list :: proc(
) {
list: CompletionList
- position_context, ok := get_document_position_context(
- document,
- position,
- .Completion,
- )
+ position_context, ok := get_document_position_context(document, position, .Completion)
if !ok || position_context.abort_completion {
return list, true
@@ -60,8 +56,7 @@ get_completion_list :: proc(
// Check only when the import fullpath length is > 1, to allow
// completion of modules when the initial '"' quote is entered.
if len(position_context.import_stmt.fullpath) > 1 &&
- position_context.position ==
- position_context.import_stmt.end.offset &&
+ position_context.position == position_context.import_stmt.end.offset &&
completion_context.triggerCharacter == "\"" {
// The completion was called for an import statement where the
// cursor is on the ending quote, so abort early to prevent
@@ -84,12 +79,7 @@ get_completion_list :: proc(
ast_context.value_decl = position_context.value_decl
if position_context.function != nil {
- get_locals(
- document.ast,
- position_context.function,
- &ast_context,
- &position_context,
- )
+ get_locals(document.ast, position_context.function, &ast_context, &position_context)
}
completion_type: Completion_Type = .Identifier
@@ -100,12 +90,8 @@ get_completion_list :: proc(
if position_context.selector != nil {
if position_context.selector_expr != nil {
- if selector_call, ok := position_context.selector_expr.derived.(^ast.Selector_Call_Expr);
- ok {
- if !position_in_node(
- selector_call.call,
- position_context.position,
- ) {
+ if selector_call, ok := position_context.selector_expr.derived.(^ast.Selector_Call_Expr); ok {
+ if !position_in_node(selector_call.call, position_context.position) {
completion_type = .Selector
}
}
@@ -126,12 +112,10 @@ get_completion_list :: proc(
completion_type = .Package
}
- done: if position_context.switch_type_stmt != nil &&
- position_context.case_clause != nil {
+ done: if position_context.switch_type_stmt != nil && position_context.case_clause != nil {
if position_context.switch_stmt != nil &&
- position_context.switch_type_stmt.pos.offset <=
- position_context.switch_stmt.pos.offset {
+ position_context.switch_type_stmt.pos.offset <= position_context.switch_stmt.pos.offset {
break done
}
@@ -139,10 +123,7 @@ get_completion_list :: proc(
ok && assign.rhs != nil && len(assign.rhs) == 1 {
ast_context.use_locals = true
- if symbol, ok := resolve_type_expression(
- &ast_context,
- assign.rhs[0],
- ); ok {
+ if symbol, ok := resolve_type_expression(&ast_context, assign.rhs[0]); ok {
if union_value, ok := symbol.value.(SymbolUnionValue); ok {
completion_type = .Switch_Type
}
@@ -249,13 +230,10 @@ DIRECTIVE_NAME_LIST :: []string {
completion_items_directives: []CompletionItem
-@init _init_completion_items_directives :: proc () {
- completion_items_directives = slice.mapper(DIRECTIVE_NAME_LIST, proc (name: string) -> CompletionItem {
- return {
- detail = strings.concatenate({"#", name}) or_else name,
- label = name,
- kind = .Constant,
- }
+@(init)
+_init_completion_items_directives :: proc() {
+ completion_items_directives = slice.mapper(DIRECTIVE_NAME_LIST, proc(name: string) -> CompletionItem {
+ return {detail = strings.concatenate({"#", name}) or_else name, label = name, kind = .Constant}
})
}
@@ -281,7 +259,6 @@ get_comp_lit_completion :: proc(
) {
items := make([dynamic]CompletionItem, context.temp_allocator)
-
if symbol, ok := resolve_comp_literal(ast_context, position_context); ok {
#partial switch v in symbol.value {
case SymbolStructValue:
@@ -292,26 +269,15 @@ get_comp_lit_completion :: proc(
set_ast_package_set_scoped(ast_context, symbol.pkg)
- if resolved, ok := resolve_type_expression(
- ast_context,
- v.types[i],
- ); ok {
- if field_exists_in_comp_lit(
- position_context.comp_lit,
- name,
- ) {
+ if resolved, ok := resolve_type_expression(ast_context, v.types[i]); ok {
+ if field_exists_in_comp_lit(position_context.comp_lit, name) {
continue
}
item := CompletionItem {
label = name,
kind = .Field,
- detail = fmt.tprintf(
- "%v.%v: %v",
- symbol.name,
- name,
- common.node_to_string(v.types[i]),
- ),
+ detail = fmt.tprintf("%v.%v: %v", symbol.name, name, common.node_to_string(v.types[i])),
documentation = resolved.doc,
}
@@ -326,26 +292,15 @@ get_comp_lit_completion :: proc(
set_ast_package_set_scoped(ast_context, symbol.pkg)
- if resolved, ok := resolve_type_expression(
- ast_context,
- v.types[i],
- ); ok {
- if field_exists_in_comp_lit(
- position_context.comp_lit,
- name,
- ) {
+ if resolved, ok := resolve_type_expression(ast_context, v.types[i]); ok {
+ if field_exists_in_comp_lit(position_context.comp_lit, name) {
continue
}
item := CompletionItem {
label = name,
kind = .Field,
- detail = fmt.tprintf(
- "%v.%v: %v",
- symbol.name,
- name,
- common.node_to_string(v.types[i]),
- ),
+ detail = fmt.tprintf("%v.%v: %v", symbol.name, name, common.node_to_string(v.types[i])),
documentation = resolved.doc,
}
@@ -372,10 +327,7 @@ get_selector_completion :: proc(
reset_ast_context(ast_context)
- selector, ok = resolve_type_expression(
- ast_context,
- position_context.selector,
- )
+ selector, ok = resolve_type_expression(ast_context, position_context.selector)
if !ok {
return
@@ -405,23 +357,14 @@ get_selector_completion :: proc(
if s, ok := selector.value.(SymbolProcedureValue); ok {
if len(s.return_types) == 1 {
- if selector, ok = resolve_type_expression(
- ast_context,
- s.return_types[0].type,
- ); !ok {
+ if selector, ok = resolve_type_expression(ast_context, s.return_types[0].type); !ok {
return
}
}
}
if common.config.enable_fake_method {
- append_method_completion(
- ast_context,
- selector,
- position_context,
- &items,
- receiver,
- )
+ append_method_completion(ast_context, selector, position_context, &items, receiver)
}
#partial switch v in selector.value {
@@ -464,12 +407,7 @@ get_selector_completion :: proc(
item := CompletionItem {
label = fmt.tprintf("%v%v", field, k),
kind = .Property,
- detail = fmt.tprintf(
- "%v%v: %v",
- field,
- k,
- common.node_to_string(v.expr),
- ),
+ detail = fmt.tprintf("%v%v: %v", field, k, common.node_to_string(v.expr)),
}
append(&items, item)
}
@@ -486,12 +424,7 @@ get_selector_completion :: proc(
item := CompletionItem {
label = fmt.tprintf("%v%v", field, k),
kind = .Property,
- detail = fmt.tprintf(
- "%v%v: %v",
- field,
- k,
- common.node_to_string(v.expr),
- ),
+ detail = fmt.tprintf("%v%v: %v", field, k, common.node_to_string(v.expr)),
}
append(&items, item)
}
@@ -508,13 +441,7 @@ get_selector_completion :: proc(
item := CompletionItem {
label = fmt.tprintf("%v%v", field, k),
kind = .Property,
- detail = fmt.tprintf(
- "%v%v: [%v]%v",
- field,
- k,
- containsColor,
- common.node_to_string(v.expr),
- ),
+ detail = fmt.tprintf("%v%v: [%v]%v", field, k, containsColor, common.node_to_string(v.expr)),
}
append(&items, item)
}
@@ -529,13 +456,7 @@ get_selector_completion :: proc(
item := CompletionItem {
label = fmt.tprintf("%v%v", field, k),
kind = .Property,
- detail = fmt.tprintf(
- "%v%v: [%v]%v",
- field,
- k,
- containsCoord,
- common.node_to_string(v.expr),
- ),
+ detail = fmt.tprintf("%v%v: [%v]%v", field, k, containsCoord, common.node_to_string(v.expr)),
}
append(&items, item)
}
@@ -564,21 +485,13 @@ get_selector_completion :: proc(
is_selector {
item.label = fmt.aprintf(
"(%v%v)",
- common.repeat(
- "^",
- symbol.pointers,
- context.temp_allocator,
- ),
+ common.repeat("^", symbol.pointers, context.temp_allocator),
common.node_to_string(type, true),
)
} else {
item.label = fmt.aprintf(
"(%v%v.%v)",
- common.repeat(
- "^",
- symbol.pointers,
- context.temp_allocator,
- ),
+ common.repeat("^", symbol.pointers, context.temp_allocator),
get_symbol_pkg_name(ast_context, symbol),
common.node_to_string(type, true),
)
@@ -644,18 +557,15 @@ get_selector_completion :: proc(
set_ast_package_from_symbol_scoped(ast_context, selector)
- if symbol, ok := resolve_type_expression(ast_context, v.types[i]);
- ok {
- if expr, ok := position_context.selector.derived.(^ast.Selector_Expr);
- ok {
+ if symbol, ok := resolve_type_expression(ast_context, v.types[i]); ok {
+ if expr, ok := position_context.selector.derived.(^ast.Selector_Expr); ok {
if expr.op.text == "->" && symbol.type != .Function {
continue
}
}
if position_context.arrow {
- if symbol.type != .Function &&
- symbol.type != .Type_Function {
+ if symbol.type != .Function && symbol.type != .Type_Function {
continue
}
if .ObjCIsClassMethod in symbol.flags {
@@ -686,11 +596,7 @@ get_selector_completion :: proc(
item := CompletionItem {
label = symbol.name,
kind = .Field,
- detail = fmt.tprintf(
- "%v: %v",
- name,
- common.node_to_string(v.types[i]),
- ),
+ detail = fmt.tprintf("%v: %v", name, common.node_to_string(v.types[i])),
documentation = symbol.doc,
}
@@ -708,8 +614,7 @@ get_selector_completion :: proc(
set_ast_package_from_symbol_scoped(ast_context, selector)
- if symbol, ok := resolve_type_expression(ast_context, v.types[i]);
- ok {
+ if symbol, ok := resolve_type_expression(ast_context, v.types[i]); ok {
item := CompletionItem {
label = name,
kind = .Field,
@@ -728,11 +633,7 @@ get_selector_completion :: proc(
item := CompletionItem {
label = symbol.name,
kind = .Field,
- detail = fmt.tprintf(
- "%v: %v",
- name,
- common.node_to_string(v.types[i]),
- ),
+ detail = fmt.tprintf("%v: %v", name, common.node_to_string(v.types[i])),
documentation = symbol.doc,
}
@@ -758,14 +659,8 @@ get_selector_completion :: proc(
item := CompletionItem {
label = symbol.name,
- kind = symbol_type_to_completion_kind(
- symbol.type,
- ),
- detail = concatenate_symbol_information(
- ast_context,
- symbol,
- true,
- ),
+ kind = symbol_type_to_completion_kind(symbol.type),
+ detail = concatenate_symbol_information(ast_context, symbol, true),
documentation = symbol.doc,
}
@@ -783,27 +678,15 @@ get_selector_completion :: proc(
append(&items, item)
}
} else {
- log.errorf(
- "Failed to fuzzy search, field: %v, package: %v",
- field,
- selector.pkg,
- )
+ log.errorf("Failed to fuzzy search, field: %v, package: %v", field, selector.pkg)
return
}
case SymbolDynamicArrayValue:
list.isIncomplete = false
- append_magic_dynamic_array_completion(
- position_context,
- selector,
- &items,
- )
+ append_magic_dynamic_array_completion(position_context, selector, &items)
case SymbolSliceValue:
list.isIncomplete = false
- append_magic_dynamic_array_completion(
- position_context,
- selector,
- &items,
- )
+ append_magic_dynamic_array_completion(position_context, selector, &items)
case SymbolMapValue:
list.isIncomplete = false
@@ -829,26 +712,16 @@ get_implicit_completion :: proc(
set_ast_package_from_symbol_scoped(ast_context, selector)
//value decl infer a : My_Enum = .*
- if position_context.value_decl != nil &&
- position_context.value_decl.type != nil {
+ if position_context.value_decl != nil && position_context.value_decl.type != nil {
enum_value: Maybe(SymbolEnumValue)
- if _enum_value, ok := unwrap_enum(
- ast_context,
- position_context.value_decl.type,
- ); ok {
+ if _enum_value, ok := unwrap_enum(ast_context, position_context.value_decl.type); ok {
enum_value = _enum_value
}
if position_context.comp_lit != nil {
- if bitset_symbol, ok := resolve_type_expression(
- ast_context,
- position_context.value_decl.type,
- ); ok {
- if _enum_value, ok := unwrap_bitset(
- ast_context,
- bitset_symbol,
- ); ok {
+ if bitset_symbol, ok := resolve_type_expression(ast_context, position_context.value_decl.type); ok {
+ if _enum_value, ok := unwrap_bitset(ast_context, bitset_symbol); ok {
enum_value = _enum_value
}
}
@@ -875,13 +748,11 @@ get_implicit_completion :: proc(
position_context.switch_stmt.cond != nil {
used_enums := make(map[string]bool, 5, context.temp_allocator)
- if block, ok := position_context.switch_stmt.body.derived.(^ast.Block_Stmt);
- ok {
+ if block, ok := position_context.switch_stmt.body.derived.(^ast.Block_Stmt); ok {
for stmt in block.stmts {
if case_clause, ok := stmt.derived.(^ast.Case_Clause); ok {
for name in case_clause.list {
- if implicit, ok := name.derived.(^ast.Implicit_Selector_Expr);
- ok {
+ if implicit, ok := name.derived.(^ast.Implicit_Selector_Expr); ok {
used_enums[implicit.field.name] = true
}
}
@@ -889,10 +760,7 @@ get_implicit_completion :: proc(
}
}
- if enum_value, ok := unwrap_enum(
- ast_context,
- position_context.switch_stmt.cond,
- ); ok {
+ if enum_value, ok := unwrap_enum(ast_context, position_context.switch_stmt.cond); ok {
for name in enum_value.names {
if name in used_enums {
continue
@@ -917,10 +785,7 @@ get_implicit_completion :: proc(
len(position_context.assign.lhs) == 1 &&
is_bitset_assignment_operator(position_context.assign.op.text) {
//bitsets
- if symbol, ok := resolve_type_expression(
- ast_context,
- position_context.assign.lhs[0],
- ); ok {
+ if symbol, ok := resolve_type_expression(ast_context, position_context.assign.lhs[0]); ok {
set_ast_package_set_scoped(ast_context, symbol.pkg)
if value, ok := unwrap_bitset(ast_context, symbol); ok {
for name in value.names {
@@ -946,10 +811,7 @@ get_implicit_completion :: proc(
position_context.parent_binary != nil &&
is_bitset_binary_operator(position_context.binary.op.text) {
//bitsets
- if symbol, ok := resolve_first_symbol_from_binary_expression(
- ast_context,
- position_context.parent_binary,
- ); ok {
+ if symbol, ok := resolve_first_symbol_from_binary_expression(ast_context, position_context.parent_binary); ok {
set_ast_package_set_scoped(ast_context, symbol.pkg)
if value, ok := unwrap_bitset(ast_context, symbol); ok {
for name in value.names {
@@ -976,18 +838,14 @@ get_implicit_completion :: proc(
field_name: string
if position_context.field_value != nil {
- if field, ok := position_context.field_value.field.derived.(^ast.Ident);
- ok {
+ if field, ok := position_context.field_value.field.derived.(^ast.Ident); ok {
field_name = field.name
} else {
return
}
}
- if symbol, ok := resolve_type_expression(
- ast_context,
- position_context.parent_comp_lit.type,
- ); ok {
+ if symbol, ok := resolve_type_expression(ast_context, position_context.parent_comp_lit.type); ok {
if comp_symbol, comp_lit, ok := resolve_type_comp_literal(
ast_context,
position_context,
@@ -995,19 +853,13 @@ get_implicit_completion :: proc(
position_context.parent_comp_lit,
); ok {
if s, ok := comp_symbol.value.(SymbolStructValue); ok {
- set_ast_package_set_scoped(
- ast_context,
- comp_symbol.pkg,
- )
+ set_ast_package_set_scoped(ast_context, comp_symbol.pkg)
//We can either have the final
elem_index := -1
for elem, i in comp_lit.elems {
- if position_in_node(
- elem,
- position_context.position,
- ) {
+ if position_in_node(elem, position_context.position) {
elem_index = i
}
}
@@ -1023,14 +875,11 @@ get_implicit_completion :: proc(
break
}
- if type == nil &&
- len(s.types) > elem_index &&
- elem_index != -1 {
+ if type == nil && len(s.types) > elem_index && elem_index != -1 {
type = s.types[elem_index]
}
- if enum_value, ok := unwrap_enum(ast_context, type);
- ok {
+ if enum_value, ok := unwrap_enum(ast_context, type); ok {
for enum_name in enum_value.names {
item := CompletionItem {
label = enum_name,
@@ -1043,19 +892,10 @@ get_implicit_completion :: proc(
list.items = items[:]
return
- } else if bitset_symbol, ok := resolve_type_expression(
- ast_context,
- type,
- ); ok {
- set_ast_package_set_scoped(
- ast_context,
- bitset_symbol.pkg,
- )
-
- if value, ok := unwrap_bitset(
- ast_context,
- bitset_symbol,
- ); ok {
+ } else if bitset_symbol, ok := resolve_type_expression(ast_context, type); ok {
+ set_ast_package_set_scoped(ast_context, bitset_symbol.pkg)
+
+ if value, ok := unwrap_bitset(ast_context, bitset_symbol); ok {
for name in value.names {
item := CompletionItem {
@@ -1070,8 +910,7 @@ get_implicit_completion :: proc(
return
}
}
- } else if s, ok := unwrap_bitset(ast_context, comp_symbol);
- ok {
+ } else if s, ok := unwrap_bitset(ast_context, comp_symbol); ok {
for enum_name in s.names {
item := CompletionItem {
label = enum_name,
@@ -1093,21 +932,14 @@ get_implicit_completion :: proc(
}
if position_context.binary != nil &&
- (position_context.binary.op.text == "==" ||
- position_context.binary.op.text == "!=") {
+ (position_context.binary.op.text == "==" || position_context.binary.op.text == "!=") {
context_node: ^ast.Expr
enum_node: ^ast.Expr
- if position_in_node(
- position_context.binary.right,
- position_context.position,
- ) {
+ if position_in_node(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,
- ) {
+ } else if position_in_node(position_context.binary.left, position_context.position) {
context_node = position_context.binary.left
enum_node = position_context.binary.right
}
@@ -1132,9 +964,7 @@ get_implicit_completion :: proc(
reset_ast_context(ast_context)
}
- if position_context.assign != nil &&
- position_context.assign.rhs != nil &&
- position_context.assign.lhs != nil {
+ if position_context.assign != nil && position_context.assign.rhs != nil && position_context.assign.lhs != nil {
rhs_index: int
for elem in position_context.assign.rhs {
@@ -1142,10 +972,8 @@ get_implicit_completion :: proc(
break
} else {
//procedures are the only types that can return more than one value
- if symbol, ok := resolve_type_expression(ast_context, elem);
- ok {
- if procedure, ok := symbol.value.(SymbolProcedureValue);
- ok {
+ if symbol, ok := resolve_type_expression(ast_context, elem); ok {
+ if procedure, ok := symbol.value.(SymbolProcedureValue); ok {
if procedure.return_types == nil {
return
}
@@ -1159,10 +987,7 @@ get_implicit_completion :: proc(
}
if len(position_context.assign.lhs) > rhs_index {
- if enum_value, ok := unwrap_enum(
- ast_context,
- position_context.assign.lhs[rhs_index],
- ); ok {
+ if enum_value, ok := unwrap_enum(ast_context, position_context.assign.lhs[rhs_index]); ok {
for name in enum_value.names {
item := CompletionItem {
label = name,
@@ -1228,18 +1053,13 @@ get_implicit_completion :: proc(
if position_context.call != nil {
if call, ok := position_context.call.derived.(^ast.Call_Expr); ok {
- parameter_index, parameter_ok := find_position_in_call_param(
- position_context,
- call^,
- )
- if symbol, ok := resolve_type_expression(ast_context, call.expr);
- ok && parameter_ok {
+ parameter_index, parameter_ok := find_position_in_call_param(position_context, call^)
+ if symbol, ok := resolve_type_expression(ast_context, call.expr); ok && parameter_ok {
set_ast_package_set_scoped(ast_context, symbol.pkg)
//Selector call expression always set the first argument to be the type of struct called, so increment it.
if position_context.selector_expr != nil {
- if selector_call, ok := position_context.selector_expr.derived.(^ast.Selector_Call_Expr);
- ok {
+ if selector_call, ok := position_context.selector_expr.derived.(^ast.Selector_Call_Expr); ok {
if selector_call.call == position_context.call {
parameter_index += 1
}
@@ -1251,10 +1071,7 @@ get_implicit_completion :: proc(
return
}
- if enum_value, ok := unwrap_enum(
- ast_context,
- proc_value.arg_types[parameter_index].type,
- ); ok {
+ if enum_value, ok := unwrap_enum(ast_context, proc_value.arg_types[parameter_index].type); ok {
for name in enum_value.names {
item := CompletionItem {
label = name,
@@ -1275,14 +1092,8 @@ get_implicit_completion :: proc(
ast_context,
proc_value.arg_types[parameter_index].type,
); ok {
- set_ast_package_set_scoped(
- ast_context,
- bitset_symbol.pkg,
- )
- if enum_value, ok := unwrap_bitset(
- ast_context,
- bitset_symbol,
- ); ok {
+ set_ast_package_set_scoped(ast_context, bitset_symbol.pkg)
+ if enum_value, ok := unwrap_bitset(ast_context, bitset_symbol); ok {
for name in enum_value.names {
item := CompletionItem {
label = name,
@@ -1299,8 +1110,7 @@ get_implicit_completion :: proc(
}
}
- } else if enum_value, ok := symbol.value.(SymbolEnumValue);
- ok {
+ } else if enum_value, ok := symbol.value.(SymbolEnumValue); ok {
for name in enum_value.names {
item := CompletionItem {
label = name,
@@ -1322,18 +1132,12 @@ get_implicit_completion :: proc(
symbol: Symbol
ok := false
if position_context.previous_index != nil {
- symbol, ok = resolve_type_expression(
- ast_context,
- position_context.previous_index,
- )
+ symbol, ok = resolve_type_expression(ast_context, position_context.previous_index)
if !ok {
return
}
} else {
- symbol, ok = resolve_type_expression(
- ast_context,
- position_context.index.expr,
- )
+ symbol, ok = resolve_type_expression(ast_context, position_context.index.expr)
}
if array, ok := symbol.value.(SymbolFixedArrayValue); ok {
@@ -1438,12 +1242,7 @@ get_identifier_completion :: proc(
ast_context.current_package = ast_context.document_package
- ident := new_type(
- ast.Ident,
- v.expr.pos,
- v.expr.end,
- context.temp_allocator,
- )
+ ident := new_type(ast.Ident, v.expr.pos, v.expr.end, context.temp_allocator)
ident.name = k
if symbol, ok := resolve_type_identifier(ast_context, ident^); ok {
@@ -1474,11 +1273,7 @@ get_identifier_completion :: proc(
break
}
- local_offset := get_local_offset(
- ast_context,
- position_context.position,
- k,
- )
+ local_offset := get_local_offset(ast_context, position_context.position, k)
if local_offset == -1 {
continue
@@ -1488,12 +1283,7 @@ get_identifier_completion :: proc(
ast_context.current_package = ast_context.document_package
- ident := new_type(
- ast.Ident,
- {offset = local_offset},
- {offset = local_offset},
- context.temp_allocator,
- )
+ ident := new_type(ast.Ident, {offset = local_offset}, {offset = local_offset}, context.temp_allocator)
ident.name = k
if symbol, ok := resolve_type_identifier(ast_context, ident^); ok {
@@ -1501,8 +1291,7 @@ get_identifier_completion :: proc(
build_procedure_symbol_signature(&symbol)
- if score, ok := common.fuzzy_match(matcher, ident.name);
- ok == 1 {
+ if score, ok := common.fuzzy_match(matcher, ident.name); ok == 1 {
append(
&combined,
CombinedResult {
@@ -1593,10 +1382,7 @@ get_identifier_completion :: proc(
if common.config.enable_snippets {
for k, v in snippets {
if score, ok := common.fuzzy_match(matcher, k); ok == 1 {
- append(
- &combined,
- CombinedResult{score = score * 1.1, snippet = v, name = k},
- )
+ append(&combined, CombinedResult{score = score * 1.1, snippet = v, name = k})
}
}
}
@@ -1630,10 +1416,7 @@ get_identifier_completion :: proc(
edits := make([dynamic]TextEdit, context.temp_allocator)
for pkg in result.snippet.packages {
- edit, ok := get_core_insert_package_if_non_existent(
- ast_context,
- pkg,
- )
+ edit, ok := get_core_insert_package_if_non_existent(ast_context, pkg)
if ok {
append(&edits, edit)
}
@@ -1650,9 +1433,7 @@ get_identifier_completion :: proc(
item.kind = symbol_type_to_completion_kind(result.type)
- if result.type == .Function &&
- common.config.enable_snippets &&
- common.config.enable_procedure_snippet {
+ if result.type == .Function && common.config.enable_snippets && common.config.enable_procedure_snippet {
item.insertText = fmt.tprintf("%v($0)", item.label)
item.insertTextFormat = .Snippet
item.deprecated = .Deprecated in result.flags
@@ -1694,8 +1475,7 @@ get_package_completion :: proc(
}
// Strip the closing quote, if one exists.
- if len(without_quotes) > 0 &&
- without_quotes[len(without_quotes) - 1] == '"' {
+ if len(without_quotes) > 0 && without_quotes[len(without_quotes) - 1] == '"' {
without_quotes = without_quotes[:len(without_quotes) - 1]
}
@@ -1709,10 +1489,7 @@ get_package_completion :: proc(
absolute_path = filepath.join(
elems = {
common.config.collections[c],
- filepath.dir(
- without_quotes[colon_index + 1:],
- context.temp_allocator,
- ),
+ filepath.dir(without_quotes[colon_index + 1:], context.temp_allocator),
},
allocator = context.temp_allocator,
)
@@ -1720,15 +1497,9 @@ get_package_completion :: proc(
absolute_path = common.config.collections[c]
}
} else {
- import_file_dir := filepath.dir(
- position_context.import_stmt.pos.file,
- context.temp_allocator,
- )
+ import_file_dir := filepath.dir(position_context.import_stmt.pos.file, context.temp_allocator)
import_dir := filepath.dir(without_quotes, context.temp_allocator)
- absolute_path = filepath.join(
- elems = {import_file_dir, import_dir},
- allocator = context.temp_allocator,
- )
+ absolute_path = filepath.join(elems = {import_file_dir, import_dir}, allocator = context.temp_allocator)
}
if !strings.contains(position_context.import_stmt.fullpath, "/") &&
@@ -1792,15 +1563,13 @@ get_type_switch_completion :: proc(
used_unions := make(map[string]bool, 5, context.temp_allocator)
- if block, ok := position_context.switch_type_stmt.body.derived.(^ast.Block_Stmt);
- ok {
+ if block, ok := position_context.switch_type_stmt.body.derived.(^ast.Block_Stmt); ok {
for stmt in block.stmts {
if case_clause, ok := stmt.derived.(^ast.Case_Clause); ok {
for name in case_clause.list {
if ident, ok := name.derived.(^ast.Ident); ok {
used_unions[ident.name] = true
- } else if selector, ok := name.derived.(^ast.Selector_Expr);
- ok {
+ } else if selector, ok := name.derived.(^ast.Selector_Expr); ok {
used_unions[selector.field.name] = true
}
}
@@ -1814,10 +1583,7 @@ get_type_switch_completion :: proc(
ok && assign.rhs != nil && len(assign.rhs) == 1 {
if union_value, ok := unwrap_union(ast_context, assign.rhs[0]); ok {
for type, i in union_value.types {
- if symbol, ok := resolve_type_expression(
- ast_context,
- union_value.types[i],
- ); ok {
+ if symbol, ok := resolve_type_expression(ast_context, union_value.types[i]); ok {
name := symbol.name
item := CompletionItem {
@@ -1827,21 +1593,13 @@ get_type_switch_completion :: proc(
if symbol.pkg == ast_context.document_package {
item.label = fmt.aprintf(
"%v%v",
- common.repeat(
- "^",
- symbol.pointers,
- context.temp_allocator,
- ),
+ common.repeat("^", symbol.pointers, context.temp_allocator),
name,
)
} else {
item.label = fmt.aprintf(
"%v%v.%v",
- common.repeat(
- "^",
- symbol.pointers,
- context.temp_allocator,
- ),
+ common.repeat("^", symbol.pointers, context.temp_allocator),
get_symbol_pkg_name(ast_context, symbol),
name,
)
@@ -1856,13 +1614,7 @@ get_type_switch_completion :: proc(
list.items = items[:]
}
-get_core_insert_package_if_non_existent :: proc(
- ast_context: ^AstContext,
- pkg: string,
-) -> (
- TextEdit,
- bool,
-) {
+get_core_insert_package_if_non_existent :: proc(ast_context: ^AstContext, pkg: string) -> (TextEdit, bool) {
builder := strings.builder_make(context.temp_allocator)
for imp in ast_context.imports {
@@ -1876,30 +1628,16 @@ get_core_insert_package_if_non_existent :: proc(
return {
newText = strings.to_string(builder),
range = {
- start = {
- line = ast_context.file.pkg_decl.end.line + 1,
- character = 0,
- },
- end = {
- line = ast_context.file.pkg_decl.end.line + 1,
- character = 0,
- },
+ start = {line = ast_context.file.pkg_decl.end.line + 1, character = 0},
+ end = {line = ast_context.file.pkg_decl.end.line + 1, character = 0},
},
},
true
}
-get_range_from_selection_start_to_dot :: proc(
- position_context: ^DocumentPositionContext,
-) -> (
- common.Range,
- bool,
-) {
+get_range_from_selection_start_to_dot :: proc(position_context: ^DocumentPositionContext) -> (common.Range, bool) {
if position_context.selector != nil {
- range := common.get_token_range(
- position_context.selector,
- position_context.file.src,
- )
+ range := common.get_token_range(position_context.selector, position_context.file.src)
range.end.character += 1
return range, true
}
@@ -1939,10 +1677,7 @@ append_magic_map_completion :: proc(
detail = "for",
additionalTextEdits = additionalTextEdits,
textEdit = TextEdit {
- newText = fmt.tprintf(
- "for ${{1:k}}, ${{2:v}} in %v {{\n\t$0 \n}}",
- symbol_str,
- ),
+ newText = fmt.tprintf("for ${{1:k}}, ${{2:v}} in %v {{\n\t$0 \n}}", symbol_str),
range = {start = range.end, end = range.end},
},
insertTextFormat = .Snippet,
@@ -1952,22 +1687,14 @@ append_magic_map_completion :: proc(
append(items, item)
}
}
-get_expression_string_from_position_context :: proc(
- position_context: ^DocumentPositionContext,
-) -> string {
+get_expression_string_from_position_context :: proc(position_context: ^DocumentPositionContext) -> string {
src := position_context.file.src
if position_context.call != nil {
- return(
- src[position_context.call.pos.offset:position_context.call.end.offset] \
- )
+ return src[position_context.call.pos.offset:position_context.call.end.offset]
} else if position_context.field != nil {
- return(
- src[position_context.field.pos.offset:position_context.field.end.offset] \
- )
+ return src[position_context.field.pos.offset:position_context.field.end.offset]
} else if position_context.selector != nil {
- return(
- src[position_context.selector.pos.offset:position_context.selector.end.offset] \
- )
+ return src[position_context.selector.pos.offset:position_context.selector.end.offset]
}
return ""
}
@@ -2005,10 +1732,7 @@ append_magic_dynamic_array_completion :: proc(
label = "len",
kind = .Function,
detail = "len",
- textEdit = TextEdit {
- newText = text,
- range = {start = range.end, end = range.end},
- },
+ textEdit = TextEdit{newText = text, range = {start = range.end, end = range.end}},
additionalTextEdits = additionalTextEdits,
}
@@ -2042,11 +1766,7 @@ append_magic_dynamic_array_completion :: proc(
suffix := ""
if symbol.pointers > 0 {
prefix = ""
- suffix = common.repeat(
- "^",
- symbol.pointers - 1,
- context.temp_allocator,
- )
+ suffix = common.repeat("^", symbol.pointers - 1, context.temp_allocator)
}
ptr_symbol_str := fmt.tprint(prefix, symbol_str, suffix, sep = "")
@@ -2127,10 +1847,7 @@ append_magic_union_completion :: proc(
detail = "switch",
additionalTextEdits = additionalTextEdits,
textEdit = TextEdit {
- newText = fmt.tprintf(
- "switch v in %v {{\n\t$0 \n}}",
- symbol.name,
- ),
+ newText = fmt.tprintf("switch v in %v {{\n\t$0 \n}}", symbol.name),
range = {start = range.end, end = range.end},
},
insertTextFormat = .Snippet,
@@ -2155,10 +1872,7 @@ format_to_label_details :: proc(list: ^CompletionList) {
// check if the function return somrthing
proc_return_index := strings.index(item.detail, "->")
if proc_return_index > 0 {
- proc_end_index := strings.index(
- item.detail[0:proc_return_index],
- ")",
- )
+ proc_end_index := strings.index(item.detail[0:proc_return_index], ")")
if proc_return_index + 2 >= len(item.detail) {
break
}
@@ -2201,14 +1915,8 @@ format_to_label_details :: proc(list: ^CompletionList) {
if common.config.client_name == "Sublime Text LSP" {
dt := &item.labelDetails.? or_else nil
if dt == nil do continue
- if strings.contains(dt.detail, "..") &&
- strings.contains(dt.detail, "#") {
- s, _ := strings.replace_all(
- dt.detail,
- "..",
- "ꓸꓸ",
- allocator = context.temp_allocator,
- )
+ if strings.contains(dt.detail, "..") && strings.contains(dt.detail, "#") {
+ s, _ := strings.replace_all(dt.detail, "..", "ꓸꓸ", allocator = context.temp_allocator)
dt.detail = s
}
}
@@ -2285,7 +1993,7 @@ language_keywords: []string = {
"or_return",
"or_else",
"or_continue",
- "or_break"
+ "or_break",
}
swizzle_color_map: map[u8]bool = {
diff --git a/src/server/definition.odin b/src/server/definition.odin
index 9d32faa..0a216cc 100644
--- a/src/server/definition.odin
+++ b/src/server/definition.odin
@@ -29,10 +29,7 @@ get_all_package_file_locations :: proc(
}
}
- matches, err := filepath.glob(
- fmt.tprintf("%v/*.odin", path),
- context.temp_allocator,
- )
+ matches, err := filepath.glob(fmt.tprintf("%v/*.odin", path), context.temp_allocator)
for match in matches {
uri := common.create_uri(match, context.temp_allocator)
@@ -45,13 +42,7 @@ get_all_package_file_locations :: proc(
return true
}
-get_definition_location :: proc(
- document: ^Document,
- position: common.Position,
-) -> (
- []common.Location,
- bool,
-) {
+get_definition_location :: proc(document: ^Document, position: common.Position) -> ([]common.Location, bool) {
locations := make([dynamic]common.Location, context.temp_allocator)
location: common.Location
@@ -66,11 +57,7 @@ get_definition_location :: proc(
uri: string
- position_context, ok := get_document_position_context(
- document,
- position,
- .Definition,
- )
+ position_context, ok := get_document_position_context(document, position, .Definition)
if !ok {
log.warn("Failed to get position context")
@@ -80,33 +67,20 @@ get_definition_location :: proc(
get_globals(document.ast, &ast_context)
if position_context.function != nil {
- get_locals(
- document.ast,
- position_context.function,
- &ast_context,
- &position_context,
- )
+ get_locals(document.ast, position_context.function, &ast_context, &position_context)
}
if position_context.import_stmt != nil {
- if get_all_package_file_locations(
- document,
- position_context.import_stmt,
- &locations,
- ) {
+ if get_all_package_file_locations(document, position_context.import_stmt, &locations) {
return locations[:], true
}
} else if position_context.selector_expr != nil {
//if the base selector is the client wants to go to.
- if base, ok := position_context.selector.derived.(^ast.Ident);
- ok && position_context.identifier != nil {
+ if base, ok := position_context.selector.derived.(^ast.Ident); ok && position_context.identifier != nil {
ident := position_context.identifier.derived.(^ast.Ident)
if position_in_node(base, position_context.position) {
- if resolved, ok := resolve_location_identifier(
- &ast_context,
- ident^,
- ); ok {
+ if resolved, ok := resolve_location_identifier(&ast_context, ident^); ok {
location.range = resolved.range
if resolved.uri == "" {
@@ -124,10 +98,7 @@ get_definition_location :: proc(
}
}
- if resolved, ok := resolve_location_selector(
- &ast_context,
- position_context.selector_expr,
- ); ok {
+ if resolved, ok := resolve_location_selector(&ast_context, position_context.selector_expr); ok {
location.range = resolved.range
uri = resolved.uri
} else {
@@ -136,14 +107,8 @@ get_definition_location :: proc(
} else if position_context.field_value != nil &&
position_context.comp_lit != nil &&
!common.is_expr_basic_lit(position_context.field_value.field) &&
- position_in_node(
- position_context.field_value.field,
- position_context.position,
- ) {
- if resolved, ok := resolve_location_comp_lit_field(
- &ast_context,
- &position_context,
- ); ok {
+ position_in_node(position_context.field_value.field, position_context.position) {
+ if resolved, ok := resolve_location_comp_lit_field(&ast_context, &position_context); ok {
location.range = resolved.range
uri = resolved.uri
} else {
diff --git a/src/server/document_links.odin b/src/server/document_links.odin
index 4b2acf5..5543dd2 100644
--- a/src/server/document_links.odin
+++ b/src/server/document_links.odin
@@ -25,11 +25,7 @@ get_document_links :: proc(document: ^Document) -> ([]DocumentLink, bool) {
continue
}
- e := strings.split(
- imp.relpath.text[1:len(imp.relpath.text) - 1],
- ":",
- context.temp_allocator,
- )
+ e := strings.split(imp.relpath.text[1:len(imp.relpath.text) - 1], ":", context.temp_allocator)
if len(e) != 2 {
continue
@@ -41,12 +37,12 @@ get_document_links :: proc(document: ^Document) -> ([]DocumentLink, bool) {
//Temporarly assuming non unicode
node := ast.Node {
- pos = {
+ pos = {
offset = imp.relpath.pos.offset + 1,
column = imp.relpath.pos.column + 1,
line = imp.relpath.pos.line,
},
- end = {
+ end = {
offset = imp.relpath.pos.offset + len(imp.relpath.text) - 1,
column = imp.relpath.pos.column + len(imp.relpath.text) - 1,
line = imp.relpath.pos.line,
@@ -57,11 +53,7 @@ get_document_links :: proc(document: ^Document) -> ([]DocumentLink, bool) {
link := DocumentLink {
range = range,
- target = fmt.tprintf(
- "https://pkg.odin-lang.org/%v/%v",
- e[0],
- e[1],
- ),
+ target = fmt.tprintf("https://pkg.odin-lang.org/%v/%v", e[0], e[1]),
tooltip = "Documentation",
}
diff --git a/src/server/document_symbols.odin b/src/server/document_symbols.odin
index 8a0cb2d..f5e8216 100644
--- a/src/server/document_symbols.odin
+++ b/src/server/document_symbols.odin
@@ -37,16 +37,10 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol {
}
package_symbol.kind = .Package
- package_symbol.name = path.base(
- document.package_name,
- false,
- context.temp_allocator,
- )
+ package_symbol.name = path.base(document.package_name, false, context.temp_allocator)
package_symbol.range = {
start = {line = document.ast.decls[0].pos.line},
- end = {
- line = document.ast.decls[len(document.ast.decls) - 1].end.line,
- },
+ end = {line = document.ast.decls[len(document.ast.decls) - 1].end.line},
}
package_symbol.selectionRange = package_symbol.range
@@ -54,10 +48,7 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol {
for k, global in ast_context.globals {
symbol: DocumentSymbol
- symbol.range = common.get_token_range(
- global.expr,
- ast_context.file.src,
- )
+ symbol.range = common.get_token_range(global.expr, ast_context.file.src)
symbol.selectionRange = symbol.range
symbol.name = k
diff --git a/src/server/documents.odin b/src/server/documents.odin
index b874082..f165936 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -113,12 +113,7 @@ document_release :: proc(document: ^Document) {
Client opens a document with transferred text
*/
-document_open :: proc(
- uri_string: string,
- text: string,
- config: ^common.Config,
- writer: ^Writer,
-) -> common.Error {
+document_open :: proc(uri_string: string, text: string, config: ^common.Config, writer: ^Writer) -> common.Error {
uri, parsed_ok := common.parse_uri(uri_string, context.allocator)
if !parsed_ok {
@@ -128,10 +123,7 @@ document_open :: proc(
if document := &document_storage.documents[uri.path]; document != nil {
if document.client_owned {
- log.errorf(
- "Client called open on an already open document: %v ",
- document.uri.path,
- )
+ log.errorf("Client called open on an already open document: %v ", document.uri.path)
return .InvalidRequest
}
@@ -173,10 +165,7 @@ document_setup :: proc(document: ^Document) {
//Right now not all clients return the case correct windows path, and that causes issues with indexing, so we ensure that it's case correct.
when ODIN_OS == .Windows {
package_name := path.dir(document.uri.path, context.temp_allocator)
- forward, _ := filepath.to_slash(
- common.get_case_sensitive_path(package_name),
- context.temp_allocator,
- )
+ forward, _ := filepath.to_slash(common.get_case_sensitive_path(package_name), context.temp_allocator)
if forward == "" {
document.package_name = package_name
} else {
@@ -221,20 +210,14 @@ document_apply_changes :: proc(
document.version = version
if !document.client_owned {
- log.errorf(
- "Client called change on an document not opened: %v ",
- document.uri.path,
- )
+ log.errorf("Client called change on an document not opened: %v ", document.uri.path)
return .InvalidRequest
}
for change in changes {
//for some reason sublime doesn't seem to care even if i tell it to do incremental sync
if range, ok := change.range.(common.Range); ok {
- absolute_range, ok := common.get_absolute_range(
- range,
- document.text[:document.used_text],
- )
+ absolute_range, ok := common.get_absolute_range(range, document.text[:document.used_text])
if !ok {
return .ParseError
@@ -299,10 +282,7 @@ document_close :: proc(uri_string: string) -> common.Error {
document := &document_storage.documents[uri.path]
if document == nil || !document.client_owned {
- log.errorf(
- "Client called close on a document that was never opened: %v ",
- document.uri.path,
- )
+ log.errorf("Client called close on a document that was never opened: %v ", document.uri.path)
return .InvalidRequest
}
@@ -325,11 +305,7 @@ document_close :: proc(uri_string: string) -> common.Error {
return .None
}
-document_refresh :: proc(
- document: ^Document,
- config: ^common.Config,
- writer: ^Writer,
-) -> common.Error {
+document_refresh :: proc(document: ^Document, config: ^common.Config, writer: ^Writer) -> common.Error {
errors, ok := parse_document(document, config)
if !ok {
@@ -341,20 +317,13 @@ document_refresh :: proc(
params := NotificationPublishDiagnosticsParams {
uri = document.uri.uri,
- diagnostics = make(
- []Diagnostic,
- len(errors),
- context.temp_allocator,
- ),
+ diagnostics = make([]Diagnostic, len(errors), context.temp_allocator),
}
for error, i in errors {
params.diagnostics[i] = Diagnostic {
range = common.Range {
- start = common.Position {
- line = error.line - 1,
- character = 0,
- },
+ start = common.Position{line = error.line - 1, character = 0},
end = common.Position{line = error.line, character = 0},
},
severity = DiagnosticSeverity.Error,
@@ -381,11 +350,7 @@ document_refresh :: proc(
method = "textDocument/publishDiagnostics",
params = NotificationPublishDiagnosticsParams {
uri = document.uri.uri,
- diagnostics = make(
- []Diagnostic,
- len(errors),
- context.temp_allocator,
- ),
+ diagnostics = make([]Diagnostic, len(errors), context.temp_allocator),
},
}
@@ -411,13 +376,7 @@ parser_error_handler :: proc(pos: tokenizer.Pos, msg: string, args: ..any) {
append(&current_errors, error)
}
-parse_document :: proc(
- document: ^Document,
- config: ^common.Config,
-) -> (
- []ParserError,
- bool,
-) {
+parse_document :: proc(document: ^Document, config: ^common.Config) -> ([]ParserError, bool) {
p := parser.Parser {
err = parser_error_handler,
warn = common.parser_warning_handler,
@@ -460,8 +419,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 {
+ if i := strings.index(imp.fullpath, ":"); i != -1 && i > 1 && i < len(imp.fullpath) - 1 {
if len(imp.fullpath) < 2 {
continue
}
@@ -477,12 +435,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) {
import_: Package
import_.original = imp.fullpath
- import_.name = strings.clone(
- path.join(
- elems = {dir, p},
- allocator = context.temp_allocator,
- ),
- )
+ import_.name = strings.clone(path.join(elems = {dir, p}, allocator = context.temp_allocator))
if imp.name.text != "" {
import_.base = imp.name.text
@@ -501,10 +454,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) {
import_: Package
import_.original = imp.fullpath
import_.name = path.join(
- elems = {
- document.package_name,
- imp.fullpath[1:len(imp.fullpath) - 1],
- },
+ elems = {document.package_name, imp.fullpath[1:len(imp.fullpath) - 1]},
allocator = context.temp_allocator,
)
import_.name = path.clean(import_.name)
diff --git a/src/server/file_resolve.odin b/src/server/file_resolve.odin
index a6b87e3..85e70f5 100644
--- a/src/server/file_resolve.odin
+++ b/src/server/file_resolve.odin
@@ -63,15 +63,7 @@ resolve_entire_file :: proc(
continue
}
- resolve_decl(
- &position_context,
- &ast_context,
- document,
- decl,
- &symbols,
- flag,
- allocator,
- )
+ resolve_decl(&position_context, &ast_context, document, decl, &symbols, flag, allocator)
clear(&ast_context.locals)
}
@@ -128,12 +120,7 @@ local_scope :: proc(data: ^FileResolveData, stmt: ^ast.Stmt) {
data.position_context.position = stmt.end.offset
- get_locals_stmt(
- data.ast_context.file,
- stmt,
- data.ast_context,
- data.position_context,
- )
+ get_locals_stmt(data.ast_context.file, stmt, data.ast_context, data.position_context)
}
@(private = "file")
@@ -151,16 +138,14 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) {
case ^Ident:
data.position_context.identifier = node
if data.flag != .None {
- if symbol, ok := resolve_location_identifier(data.ast_context, n^);
- ok {
+ if symbol, ok := resolve_location_identifier(data.ast_context, n^); ok {
data.symbols[cast(uintptr)node] = SymbolAndNode {
node = n,
symbol = symbol,
}
}
} else {
- if symbol, ok := resolve_type_identifier(data.ast_context, n^);
- ok {
+ if symbol, ok := resolve_type_identifier(data.ast_context, n^); ok {
data.symbols[cast(uintptr)node] = SymbolAndNode {
node = n,
symbol = symbol,
@@ -183,11 +168,7 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) {
data.position_context.implicit_selector_expr = n
if data.flag != .None {
data.position_context.position = n.pos.offset
- if symbol, ok := resolve_location_implicit_selector(
- data.ast_context,
- data.position_context,
- n,
- ); ok {
+ if symbol, ok := resolve_location_implicit_selector(data.ast_context, data.position_context, n); ok {
data.symbols[cast(uintptr)node] = SymbolAndNode {
node = n,
symbol = symbol,
@@ -201,8 +182,7 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) {
data.position_context.selector_expr = node
if data.flag != .None {
- if symbol, ok := resolve_location_selector(data.ast_context, n);
- ok {
+ if symbol, ok := resolve_location_selector(data.ast_context, n); ok {
if data.flag != .Base {
data.symbols[cast(uintptr)node] = SymbolAndNode {
node = n.field,
@@ -217,10 +197,7 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) {
}
} else {
- if symbol, ok := resolve_type_expression(
- data.ast_context,
- &n.node,
- ); ok {
+ if symbol, ok := resolve_type_expression(data.ast_context, &n.node); ok {
data.symbols[cast(uintptr)node] = SymbolAndNode {
node = n,
symbol = symbol,
@@ -236,10 +213,7 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) {
if data.flag != .None && data.position_context.comp_lit != nil {
data.position_context.position = n.pos.offset
- if symbol, ok := resolve_location_comp_lit_field(
- data.ast_context,
- data.position_context,
- ); ok {
+ if symbol, ok := resolve_location_comp_lit_field(data.ast_context, data.position_context); ok {
data.symbols[cast(uintptr)node] = SymbolAndNode {
node = n.field,
symbol = symbol,
@@ -254,21 +228,13 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) {
case ^Proc_Lit:
local_scope(data, n.body)
- get_locals_proc_param_and_results(
- data.ast_context.file,
- n^,
- data.ast_context,
- data.position_context,
- )
+ get_locals_proc_param_and_results(data.ast_context.file, n^, data.ast_context, data.position_context)
resolve_node(n.type, data)
data.position_context.function = cast(^Proc_Lit)node
- append(
- &data.position_context.functions,
- data.position_context.function,
- )
+ append(&data.position_context.functions, data.position_context.function)
resolve_node(n.body, data)
case ^ast.Inline_Range_Stmt:
@@ -471,12 +437,7 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) {
for name in field.names {
data.symbols[cast(uintptr)name] = SymbolAndNode {
node = name,
- symbol = Symbol {
- range = common.get_token_range(
- name,
- string(data.document.text),
- ),
- },
+ symbol = Symbol{range = common.get_token_range(name, string(data.document.text))},
}
}
}
@@ -495,12 +456,7 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) {
for field in n.fields {
data.symbols[cast(uintptr)field] = SymbolAndNode {
node = field,
- symbol = Symbol {
- range = common.get_token_range(
- field,
- string(data.document.text),
- ),
- },
+ symbol = Symbol{range = common.get_token_range(field, string(data.document.text))},
}
}
}
diff --git a/src/server/format.odin b/src/server/format.odin
index fbf9837..c518532 100644
--- a/src/server/format.odin
+++ b/src/server/format.odin
@@ -20,13 +20,7 @@ DocumentFormattingParams :: struct {
options: FormattingOptions,
}
-get_complete_format :: proc(
- document: ^Document,
- config: ^common.Config,
-) -> (
- []TextEdit,
- bool,
-) {
+get_complete_format :: proc(document: ^Document, config: ^common.Config) -> ([]TextEdit, bool) {
if document.ast.syntax_error_count > 0 {
return {}, true
}
@@ -39,18 +33,14 @@ get_complete_format :: proc(
fix_imports(document)
}
- style := format.find_config_file_or_default(
- filepath.dir(document.fullpath, context.temp_allocator),
- )
+ style := format.find_config_file_or_default(filepath.dir(document.fullpath, context.temp_allocator))
prnt := printer.make_printer(style, context.temp_allocator)
src := printer.print(&prnt, &document.ast)
edit := TextEdit {
newText = src,
- range = common.get_document_range(
- document.text[0:document.used_text],
- ),
+ range = common.get_document_range(document.text[0:document.used_text]),
}
edits := make([dynamic]TextEdit, context.temp_allocator)
diff --git a/src/server/generics.odin b/src/server/generics.odin
index 976dd6f..ba8c950 100644
--- a/src/server/generics.odin
+++ b/src/server/generics.odin
@@ -49,12 +49,7 @@ resolve_poly :: proc(
if ident, ok := unwrap_ident(type); ok {
save_poly_map(
ident,
- make_ident_ast(
- ast_context,
- call_node.pos,
- call_node.end,
- call_symbol.name,
- ),
+ make_ident_ast(ast_context, call_node.pos, call_node.end, call_symbol.name),
poly_map,
)
}
@@ -76,13 +71,7 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_matrix.row_count,
- call_symbol,
- p.row_count,
- poly_map,
- )
+ return resolve_poly(ast_context, call_matrix.row_count, call_symbol, p.row_count, poly_map)
}
found |= true
}
@@ -93,13 +82,7 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_matrix.column_count,
- call_symbol,
- p.column_count,
- poly_map,
- )
+ return resolve_poly(ast_context, call_matrix.column_count, call_symbol, p.column_count, poly_map)
}
found |= true
}
@@ -110,13 +93,7 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_matrix.elem,
- call_symbol,
- p.elem,
- poly_map,
- )
+ return resolve_poly(ast_context, call_matrix.elem, call_symbol, p.elem, poly_map)
}
found |= true
}
@@ -129,17 +106,11 @@ resolve_poly :: proc(
found := false
for arg in p.args {
if poly_type, ok := arg.derived.(^ast.Poly_Type); ok {
- if poly_type.type == nil ||
- struct_value.poly == nil ||
- len(struct_value.args) <= arg_index {
+ if poly_type.type == nil || struct_value.poly == nil || len(struct_value.args) <= arg_index {
return false
}
- save_poly_map(
- poly_type.type,
- struct_value.args[arg_index],
- poly_map,
- )
+ save_poly_map(poly_type.type, struct_value.args[arg_index], poly_map)
arg_index += 1
found |= true
@@ -151,8 +122,7 @@ resolve_poly :: proc(
case ^ast.Dynamic_Array_Type:
if call_array, ok := call_node.derived.(^ast.Dynamic_Array_Type); ok {
- if common.dynamic_array_is_soa(p^) !=
- common.dynamic_array_is_soa(call_array^) {
+ if common.dynamic_array_is_soa(p^) != common.dynamic_array_is_soa(call_array^) {
return false
}
@@ -161,10 +131,7 @@ resolve_poly :: proc(
a, ok1 := p.tag.derived.(^ast.Basic_Directive)
b, ok2 := call_array.tag.derived.(^ast.Basic_Directive)
- if ok1 &&
- ok2 &&
- (a.name == "soa" || b.name == "soa") &&
- a.name != b.name {
+ if ok1 && ok2 && (a.name == "soa" || b.name == "soa") && a.name != b.name {
return false
}
}
@@ -175,13 +142,7 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_array.elem,
- call_symbol,
- p.elem,
- poly_map,
- )
+ return resolve_poly(ast_context, call_array.elem, call_symbol, p.elem, poly_map)
}
return true
}
@@ -199,10 +160,7 @@ resolve_poly :: proc(
a, ok1 := p.tag.derived.(^ast.Basic_Directive)
b, ok2 := call_array.tag.derived.(^ast.Basic_Directive)
- if ok1 &&
- ok2 &&
- (a.name == "soa" || b.name == "soa") &&
- a.name != b.name {
+ if ok1 && ok2 && (a.name == "soa" || b.name == "soa") && a.name != b.name {
return false
}
}
@@ -213,13 +171,7 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_array.elem,
- call_symbol,
- p.elem,
- poly_map,
- )
+ return resolve_poly(ast_context, call_array.elem, call_symbol, p.elem, poly_map)
}
found |= true
}
@@ -230,13 +182,7 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_array.len,
- call_symbol,
- p.len,
- poly_map,
- )
+ return resolve_poly(ast_context, call_array.len, call_symbol, p.len, poly_map)
}
found |= true
}
@@ -253,13 +199,7 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_map.key,
- call_symbol,
- p.key,
- poly_map,
- )
+ return resolve_poly(ast_context, call_map.key, call_symbol, p.key, poly_map)
}
found |= true
}
@@ -270,34 +210,21 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_map.value,
- call_symbol,
- p.value,
- poly_map,
- )
+ return resolve_poly(ast_context, call_map.value, call_symbol, p.value, poly_map)
}
found |= true
}
return found
}
case ^ast.Multi_Pointer_Type:
- if call_pointer, ok := call_node.derived.(^ast.Multi_Pointer_Type);
- ok {
+ if call_pointer, ok := call_node.derived.(^ast.Multi_Pointer_Type); ok {
if poly_type, ok := p.elem.derived.(^ast.Poly_Type); ok {
if ident, ok := unwrap_ident(poly_type.type); ok {
save_poly_map(ident, call_pointer.elem, poly_map)
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_pointer.elem,
- call_symbol,
- p.elem,
- poly_map,
- )
+ return resolve_poly(ast_context, call_pointer.elem, call_symbol, p.elem, poly_map)
}
return true
}
@@ -310,13 +237,7 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- call_pointer.elem,
- call_symbol,
- p.elem,
- poly_map,
- )
+ return resolve_poly(ast_context, call_pointer.elem, call_symbol, p.elem, poly_map)
}
return true
}
@@ -329,13 +250,7 @@ resolve_poly :: proc(
}
if poly_type.specialization != nil {
- return resolve_poly(
- ast_context,
- comp_lit.type,
- call_symbol,
- p.type,
- poly_map,
- )
+ return resolve_poly(ast_context, comp_lit.type, call_symbol, p.type, poly_map)
}
return true
}
@@ -356,10 +271,7 @@ is_generic_type_recursive :: proc(expr: ^ast.Expr, name: string) -> bool {
exists: bool,
}
- visit_function :: proc(
- visitor: ^ast.Visitor,
- node: ^ast.Node,
- ) -> ^ast.Visitor {
+ visit_function :: proc(visitor: ^ast.Visitor, node: ^ast.Node) -> ^ast.Visitor {
if node == nil {
return nil
}
@@ -390,37 +302,25 @@ is_generic_type_recursive :: proc(expr: ^ast.Expr, name: string) -> bool {
return data.exists
}
-save_poly_map :: proc(
- ident: ^ast.Ident,
- expr: ^ast.Expr,
- poly_map: ^map[string]^ast.Expr,
-) {
+save_poly_map :: proc(ident: ^ast.Ident, expr: ^ast.Expr, poly_map: ^map[string]^ast.Expr) {
if ident == nil || expr == nil {
return
}
poly_map[ident.name] = expr
}
-get_poly_map :: proc(
- node: ^ast.Node,
- poly_map: ^map[string]^ast.Expr,
-) -> (
- ^ast.Expr,
- bool,
-) {
+get_poly_map :: proc(node: ^ast.Node, poly_map: ^map[string]^ast.Expr) -> (^ast.Expr, bool) {
if node == nil {
return {}, false
}
if ident, ok := node.derived.(^ast.Ident); ok {
- if v, ok := poly_map[ident.name];
- ok && !is_generic_type_recursive(v, ident.name) {
+ if v, ok := poly_map[ident.name]; ok && !is_generic_type_recursive(v, ident.name) {
return v, ok
}
}
if poly, ok := node.derived.(^ast.Poly_Type); ok && poly.type != nil {
- if v, ok := poly_map[poly.type.name];
- ok && !is_generic_type_recursive(v, poly.type.name) {
+ if v, ok := poly_map[poly.type.name]; ok && !is_generic_type_recursive(v, poly.type.name) {
return v, ok
}
}
@@ -428,14 +328,8 @@ get_poly_map :: proc(
return nil, false
}
-find_and_replace_poly_type :: proc(
- expr: ^ast.Expr,
- poly_map: ^map[string]^ast.Expr,
-) {
- visit_function :: proc(
- visitor: ^ast.Visitor,
- node: ^ast.Node,
- ) -> ^ast.Visitor {
+find_and_replace_poly_type :: proc(expr: ^ast.Expr, poly_map: ^map[string]^ast.Expr) {
+ visit_function :: proc(visitor: ^ast.Visitor, node: ^ast.Node) -> ^ast.Visitor {
if node == nil {
return nil
}
@@ -532,13 +426,7 @@ resolve_generic_function :: proc {
resolve_generic_function_symbol,
}
-resolve_generic_function_ast :: proc(
- ast_context: ^AstContext,
- proc_lit: ast.Proc_Lit,
-) -> (
- Symbol,
- bool,
-) {
+resolve_generic_function_ast :: proc(ast_context: ^AstContext, proc_lit: ast.Proc_Lit) -> (Symbol, bool) {
using ast
@@ -554,11 +442,7 @@ resolve_generic_function_ast :: proc(
return Symbol{}, false
}
- return resolve_generic_function_symbol(
- ast_context,
- proc_lit.type.params.list,
- proc_lit.type.results.list,
- )
+ return resolve_generic_function_symbol(ast_context, proc_lit.type.params.list, proc_lit.type.results.list)
}
@@ -607,44 +491,19 @@ resolve_generic_function_symbol :: proc(
ast_context.current_package = ast_context.document_package
- if symbol, ok := resolve_type_expression(
- ast_context,
- call_expr.args[i],
- ); ok {
- symbol_expr := symbol_to_expr(
- symbol,
- call_expr.args[i].pos.file,
- context.temp_allocator,
- )
+ if symbol, ok := resolve_type_expression(ast_context, call_expr.args[i]); ok {
+ symbol_expr := symbol_to_expr(symbol, call_expr.args[i].pos.file, context.temp_allocator)
if symbol_expr == nil {
return {}, false
}
- symbol_expr = clone_expr(
- symbol_expr,
- ast_context.allocator,
- nil,
- )
- param_type := clone_expr(
- param.type,
- ast_context.allocator,
- nil,
- )
+ symbol_expr = clone_expr(symbol_expr, ast_context.allocator, nil)
+ param_type := clone_expr(param.type, ast_context.allocator, nil)
- if resolve_poly(
- ast_context,
- symbol_expr,
- symbol,
- param_type,
- &poly_map,
- ) {
+ if resolve_poly(ast_context, symbol_expr, symbol, param_type, &poly_map) {
if poly, ok := name.derived.(^ast.Poly_Type); ok {
- poly_map[poly.type.name] = clone_expr(
- call_expr.args[i],
- ast_context.allocator,
- nil,
- )
+ poly_map[poly.type.name] = clone_expr(call_expr.args[i], ast_context.allocator, nil)
}
} else {
return {}, false
@@ -662,9 +521,7 @@ resolve_generic_function_symbol :: proc(
find_and_replace_poly_type(v, &poly_map)
}
- if count_required_params > len(call_expr.args) ||
- count_required_params == 0 ||
- len(call_expr.args) == 0 {
+ if count_required_params > len(call_expr.args) || count_required_params == 0 || len(call_expr.args) == 0 {
return {}, false
}
@@ -730,8 +587,7 @@ resolve_generic_function_symbol :: proc(
}
if len(param.names) > 0 {
- if poly_type, ok := param.names[0].derived.(^ast.Poly_Type);
- ok && param.type != nil {
+ if poly_type, ok := param.names[0].derived.(^ast.Poly_Type); ok && param.type != nil {
if m, ok := poly_map[poly_type.type.name]; ok {
field.type = m
}
@@ -769,11 +625,7 @@ is_procedure_generic :: proc(proc_type: ^ast.Proc_Type) -> bool {
}
-resolve_poly_struct :: proc(
- ast_context: ^AstContext,
- poly_params: ^ast.Field_List,
- symbol: ^Symbol,
-) {
+resolve_poly_struct :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_List, symbol: ^Symbol) {
if ast_context.call == nil {
return
}
@@ -873,11 +725,7 @@ resolve_poly_struct :: proc(
}
-resolve_poly_union :: proc(
- ast_context: ^AstContext,
- poly_params: ^ast.Field_List,
- symbol: ^Symbol,
-) {
+resolve_poly_union :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_List, symbol: ^Symbol) {
if ast_context.call == nil {
return
}
diff --git a/src/server/hover.odin b/src/server/hover.odin
index 1dbd8a6..5fdbff1 100644
--- a/src/server/hover.odin
+++ b/src/server/hover.odin
@@ -15,10 +15,7 @@ import "core:strings"
import "src:common"
-write_hover_content :: proc(
- ast_context: ^AstContext,
- symbol: Symbol,
-) -> MarkupContent {
+write_hover_content :: proc(ast_context: ^AstContext, symbol: Symbol) -> MarkupContent {
content: MarkupContent
symbol := symbol
@@ -59,14 +56,7 @@ builtin_identifier_hover: map[string]string = {
}
-get_hover_information :: proc(
- document: ^Document,
- position: common.Position,
-) -> (
- Hover,
- bool,
- bool,
-) {
+get_hover_information :: proc(document: ^Document, position: common.Position) -> (Hover, bool, bool) {
hover := Hover {
contents = {kind = "plaintext"},
}
@@ -79,21 +69,12 @@ get_hover_information :: proc(
document.fullpath,
)
- position_context, ok := get_document_position_context(
- document,
- position,
- .Hover,
- )
+ position_context, ok := get_document_position_context(document, position, .Hover)
get_globals(document.ast, &ast_context)
if position_context.function != nil {
- get_locals(
- document.ast,
- position_context.function,
- &ast_context,
- &position_context,
- )
+ get_locals(document.ast, position_context.function, &ast_context, &position_context)
}
if position_context.import_stmt != nil {
@@ -104,84 +85,51 @@ get_hover_information :: proc(
if ident, ok := position_context.identifier.derived.(^ast.Ident); ok {
if _, ok := common.keyword_map[ident.name]; ok {
hover.contents.kind = "plaintext"
- hover.range = common.get_token_range(
- position_context.identifier^,
- ast_context.file.src,
- )
+ hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src)
return hover, true, true
}
if str, ok := builtin_identifier_hover[ident.name]; ok {
hover.contents.kind = "markdown"
hover.contents.value = str
- hover.range = common.get_token_range(
- position_context.identifier^,
- ast_context.file.src,
- )
+ hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src)
return hover, true, true
}
}
}
if position_context.implicit_context != nil {
- if str, ok :=
- builtin_identifier_hover[position_context.implicit_context.tok.text];
- ok {
+ if str, ok := builtin_identifier_hover[position_context.implicit_context.tok.text]; ok {
hover.contents.kind = "markdown"
hover.contents.value = str
- hover.range = common.get_token_range(
- position_context.implicit_context^,
- ast_context.file.src,
- )
+ hover.range = common.get_token_range(position_context.implicit_context^, ast_context.file.src)
return hover, true, true
}
}
- if position_context.field_value != nil &&
- position_context.comp_lit != nil {
- if comp_symbol, ok := resolve_comp_literal(
- &ast_context,
- &position_context,
- ); ok {
- if field, ok := position_context.field_value.field.derived.(^ast.Ident);
- ok {
+ if position_context.field_value != nil && position_context.comp_lit != nil {
+ if comp_symbol, ok := resolve_comp_literal(&ast_context, &position_context); ok {
+ if field, ok := position_context.field_value.field.derived.(^ast.Ident); ok {
if v, ok := comp_symbol.value.(SymbolStructValue); ok {
for name, i in v.names {
if name == field.name {
- if symbol, ok := resolve_type_expression(
- &ast_context,
- v.types[i],
- ); ok {
+ if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok {
symbol.name = name
symbol.pkg = comp_symbol.name
- symbol.signature = common.node_to_string(
- v.types[i],
- )
- hover.contents = write_hover_content(
- &ast_context,
- symbol,
- )
+ symbol.signature = common.node_to_string(v.types[i])
+ hover.contents = write_hover_content(&ast_context, symbol)
return hover, true, true
}
}
}
- } else if v, ok := comp_symbol.value.(SymbolBitFieldValue);
- ok {
+ } else if v, ok := comp_symbol.value.(SymbolBitFieldValue); ok {
for name, i in v.names {
if name == field.name {
- if symbol, ok := resolve_type_expression(
- &ast_context,
- v.types[i],
- ); ok {
+ if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok {
symbol.name = name
symbol.pkg = comp_symbol.name
- symbol.signature = common.node_to_string(
- v.types[i],
- )
- hover.contents = write_hover_content(
- &ast_context,
- symbol,
- )
+ symbol.signature = common.node_to_string(v.types[i])
+ hover.contents = write_hover_content(&ast_context, symbol)
return hover, true, true
}
}
@@ -194,40 +142,26 @@ get_hover_information :: proc(
if position_context.selector != nil &&
position_context.identifier != nil &&
position_context.field == position_context.identifier {
- hover.range = common.get_token_range(
- position_context.identifier^,
- ast_context.file.src,
- )
+ hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src)
reset_ast_context(&ast_context)
ast_context.current_package = ast_context.document_package
//if the base selector is the client wants to go to.
- if base, ok := position_context.selector.derived.(^ast.Ident);
- ok && position_context.identifier != nil {
+ if base, ok := position_context.selector.derived.(^ast.Ident); ok && position_context.identifier != nil {
ident := position_context.identifier.derived.(^ast.Ident)^
if position_in_node(base, position_context.position) {
- if resolved, ok := resolve_type_identifier(
- &ast_context,
- ident,
- ); ok {
- resolved.signature = get_signature(
- &ast_context,
- ident,
- resolved,
- )
+ if resolved, ok := resolve_type_identifier(&ast_context, ident); ok {
+ resolved.signature = get_signature(&ast_context, ident, resolved)
resolved.name = ident.name
if resolved.type == .Variable {
resolved.pkg = ast_context.document_package
}
- hover.contents = write_hover_content(
- &ast_context,
- resolved,
- )
+ hover.contents = write_hover_content(&ast_context, resolved)
return hover, true, true
}
}
@@ -235,10 +169,7 @@ get_hover_information :: proc(
selector: Symbol
- selector, ok = resolve_type_expression(
- &ast_context,
- position_context.selector,
- )
+ selector, ok = resolve_type_expression(&ast_context, position_context.selector)
if !ok {
return hover, false, true
@@ -260,10 +191,7 @@ get_hover_information :: proc(
set_ast_package_set_scoped(&ast_context, selector.pkg)
- if selector, ok = resolve_type_expression(
- &ast_context,
- v.return_types[0].type,
- ); !ok {
+ if selector, ok = resolve_type_expression(&ast_context, v.return_types[0].type); !ok {
return {}, false, false
}
}
@@ -274,17 +202,11 @@ get_hover_information :: proc(
case SymbolStructValue:
for name, i in v.names {
if name == field {
- if symbol, ok := resolve_type_expression(
- &ast_context,
- v.types[i],
- ); ok {
+ if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok {
symbol.name = name
symbol.pkg = selector.name
symbol.signature = common.node_to_string(v.types[i])
- hover.contents = write_hover_content(
- &ast_context,
- symbol,
- )
+ hover.contents = write_hover_content(&ast_context, symbol)
return hover, true, true
}
}
@@ -292,33 +214,20 @@ get_hover_information :: proc(
case SymbolBitFieldValue:
for name, i in v.names {
if name == field {
- if symbol, ok := resolve_type_expression(
- &ast_context,
- v.types[i],
- ); ok {
+ if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok {
symbol.name = name
symbol.pkg = selector.name
symbol.signature = common.node_to_string(v.types[i])
- hover.contents = write_hover_content(
- &ast_context,
- symbol,
- )
+ hover.contents = write_hover_content(&ast_context, symbol)
return hover, true, true
}
}
}
case SymbolPackageValue:
if position_context.field != nil {
- if ident, ok := position_context.field.derived.(^ast.Ident);
- ok {
- if symbol, ok := resolve_type_identifier(
- &ast_context,
- ident^,
- ); ok {
- hover.contents = write_hover_content(
- &ast_context,
- symbol,
- )
+ if ident, ok := position_context.field.derived.(^ast.Ident); ok {
+ if symbol, ok := resolve_type_identifier(&ast_context, ident^); ok {
+ hover.contents = write_hover_content(&ast_context, symbol)
return hover, true, true
}
}
@@ -336,10 +245,7 @@ get_hover_information :: proc(
ident.end = position_context.value_decl.end
}
- hover.range = common.get_token_range(
- position_context.identifier^,
- document.ast.src,
- )
+ hover.range = common.get_token_range(position_context.identifier^, document.ast.src)
if resolved, ok := resolve_type_identifier(&ast_context, ident); ok {
resolved.signature = get_signature(&ast_context, ident, resolved)
diff --git a/src/server/inlay_hints.odin b/src/server/inlay_hints.odin
index 3f8d181..d36b3e9 100644
--- a/src/server/inlay_hints.odin
+++ b/src/server/inlay_hints.odin
@@ -71,14 +71,12 @@ get_inlay_hints :: proc(
}
}
- if selector, ok := call.expr.derived.(^ast.Selector_Expr);
- ok && selector.op.kind == .Arrow_Right {
+ if selector, ok := call.expr.derived.(^ast.Selector_Expr); ok && selector.op.kind == .Arrow_Right {
is_selector_call = true
}
if symbol_and_node, ok := symbols[cast(uintptr)call.expr]; ok {
- if symbol_call, ok := symbol_and_node.symbol.value.(SymbolProcedureValue);
- ok {
+ if symbol_call, ok := symbol_and_node.symbol.value.(SymbolProcedureValue); ok {
for arg, i in symbol_call.arg_types {
if i == 0 && is_selector_call {
continue
@@ -89,8 +87,7 @@ get_inlay_hints :: proc(
is_current_ellipsis := false
if arg.type != nil {
- if ellipsis, ok := arg.type.derived.(^ast.Ellipsis);
- ok {
+ if ellipsis, ok := arg.type.derived.(^ast.Ellipsis); ok {
is_current_ellipsis = true
}
}
@@ -119,10 +116,7 @@ get_inlay_hints :: proc(
value := common.node_to_string(arg.default_value)
- call_range := common.get_token_range(
- call,
- string(document.text),
- )
+ call_range := common.get_token_range(call, string(document.text))
position: common.Position
position = call_range.end
@@ -131,9 +125,7 @@ get_inlay_hints :: proc(
needs_leading_comma := i > 0
if !has_added_default && needs_leading_comma {
- till_end := string(
- document.text[:call.close.offset],
- )
+ till_end := string(document.text[:call.close.offset])
#reverse for ch in till_end {
switch ch {
case ' ', '\t', '\n':
@@ -147,12 +139,7 @@ get_inlay_hints :: proc(
hint := InlayHint {
kind = .Parameter,
- label = fmt.tprintf(
- "%s %v := %v",
- needs_leading_comma ? "," : "",
- label,
- value,
- ),
+ label = fmt.tprintf("%s %v := %v", needs_leading_comma ? "," : "", label, value),
position = position,
}
append(&hints, hint)
@@ -162,22 +149,17 @@ get_inlay_hints :: proc(
// if the arg name and param name are the same, don't add it.
same_name: bool
- #partial switch v in
- call.args[symbol_arg_count].derived_expr {
+ #partial switch v in call.args[symbol_arg_count].derived_expr {
case ^ast.Ident:
same_name = label == v.name
case ^ast.Poly_Type:
- if ident, ok := v.type.derived.(^ast.Ident);
- ok {
+ if ident, ok := v.type.derived.(^ast.Ident); ok {
same_name = label == ident.name
}
}
if !same_name {
- range := common.get_token_range(
- call.args[symbol_arg_count],
- string(document.text),
- )
+ range := common.get_token_range(call.args[symbol_arg_count], string(document.text))
hint := InlayHint {
kind = .Parameter,
label = fmt.tprintf("%v = ", label),
diff --git a/src/server/lens.odin b/src/server/lens.odin
index 3206d6d..964f6cf 100644
--- a/src/server/lens.odin
+++ b/src/server/lens.odin
@@ -20,13 +20,7 @@ CodeLens :: struct {
data: string,
}
-get_code_lenses :: proc(
- document: ^Document,
- position: common.Position,
-) -> (
- []CodeLens,
- bool,
-) {
+get_code_lenses :: proc(document: ^Document, position: common.Position) -> ([]CodeLens, bool) {
ast_context := make_ast_context(
document.ast,
document.imports,
diff --git a/src/server/log.odin b/src/server/log.odin
index 8660e88..169200f 100644
--- a/src/server/log.odin
+++ b/src/server/log.odin
@@ -1,14 +1,13 @@
package server
import "core:fmt"
-import "core:strings"
+import "core:log"
import "core:os"
+import "core:strings"
import "core:time"
-import "core:log"
Default_Console_Logger_Opts ::
- log.Options{.Level, .Terminal_Color, .Short_File_Path, .Line, .Procedure} |
- log.Full_Timestamp_Opts
+ log.Options{.Level, .Terminal_Color, .Short_File_Path, .Line, .Procedure} | log.Full_Timestamp_Opts
Lsp_Logger_Data :: struct {
writer: ^Writer,
@@ -55,10 +54,7 @@ lsp_logger_proc :: proc(
notification := Notification {
jsonrpc = "2.0",
method = "window/logMessage",
- params = NotificationLoggingParams{
- type = message_type,
- message = message,
- },
+ params = NotificationLoggingParams{type = message_type, message = message},
}
send_notification(notification, data.writer)
diff --git a/src/server/marshal.odin b/src/server/marshal.odin
index cb9d946..b9912a4 100644
--- a/src/server/marshal.odin
+++ b/src/server/marshal.odin
@@ -71,21 +71,11 @@ marshal :: proc(
return data, nil
}
-marshal_to_builder :: proc(
- b: ^strings.Builder,
- v: any,
- opt: ^Marshal_Options,
-) -> Marshal_Error {
+marshal_to_builder :: proc(b: ^strings.Builder, v: any, opt: ^Marshal_Options) -> Marshal_Error {
return marshal_to_writer(strings.to_writer(b), v, opt)
}
-marshal_to_writer :: proc(
- w: io.Writer,
- v: any,
- opt: ^Marshal_Options,
-) -> (
- err: Marshal_Error,
-) {
+marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: Marshal_Error) {
if v == nil {
io.write_string(w, "null") or_return
return
@@ -163,41 +153,16 @@ marshal_to_writer :: proc(
s: string
// allow uints to be printed as hex
- if opt.write_uint_as_hex &&
- (opt.spec == .JSON5 || opt.spec == .MJSON) {
+ if opt.write_uint_as_hex && (opt.spec == .JSON5 || opt.spec == .MJSON) {
switch i in a {
case u8, u16, u32, u64, u128:
- s = strconv.append_bits_128(
- buf[:],
- u,
- 16,
- info.signed,
- 8 * ti.size,
- "0123456789abcdef",
- {.Prefix},
- )
+ s = strconv.append_bits_128(buf[:], u, 16, info.signed, 8 * ti.size, "0123456789abcdef", {.Prefix})
case:
- s = strconv.append_bits_128(
- buf[:],
- u,
- 10,
- info.signed,
- 8 * ti.size,
- "0123456789",
- nil,
- )
+ s = strconv.append_bits_128(buf[:], u, 10, info.signed, 8 * ti.size, "0123456789", nil)
}
} else {
- s = strconv.append_bits_128(
- buf[:],
- u,
- 10,
- info.signed,
- 8 * ti.size,
- "0123456789",
- nil,
- )
+ s = strconv.append_bits_128(buf[:], u, 10, info.signed, 8 * ti.size, "0123456789", nil)
}
io.write_string(w, s) or_return
@@ -302,11 +267,7 @@ marshal_to_writer :: proc(
for i in 0 ..< info.count {
opt_write_iteration(w, opt, i) or_return
data := uintptr(v.data) + uintptr(i * info.elem_size)
- marshal_to_writer(
- w,
- any{rawptr(data), info.elem.id},
- opt,
- ) or_return
+ marshal_to_writer(w, any{rawptr(data), info.elem.id}, opt) or_return
}
opt_write_end(w, opt, ']') or_return
@@ -316,11 +277,7 @@ marshal_to_writer :: proc(
for i in 0 ..< info.count {
opt_write_iteration(w, opt, i) or_return
data := uintptr(v.data) + uintptr(i * info.elem_size)
- marshal_to_writer(
- w,
- any{rawptr(data), info.elem.id},
- opt,
- ) or_return
+ marshal_to_writer(w, any{rawptr(data), info.elem.id}, opt) or_return
}
opt_write_end(w, opt, ']') or_return
@@ -330,11 +287,7 @@ marshal_to_writer :: proc(
for i in 0 ..< array.len {
opt_write_iteration(w, opt, i) or_return
data := uintptr(array.data) + uintptr(i * info.elem_size)
- marshal_to_writer(
- w,
- any{rawptr(data), info.elem.id},
- opt,
- ) or_return
+ marshal_to_writer(w, any{rawptr(data), info.elem.id}, opt) or_return
}
opt_write_end(w, opt, ']') or_return
@@ -344,11 +297,7 @@ marshal_to_writer :: proc(
for i in 0 ..< slice.len {
opt_write_iteration(w, opt, i) or_return
data := uintptr(slice.data) + uintptr(i * info.elem_size)
- marshal_to_writer(
- w,
- any{rawptr(data), info.elem.id},
- opt,
- ) or_return
+ marshal_to_writer(w, any{rawptr(data), info.elem.id}, opt) or_return
}
opt_write_end(w, opt, ']') or_return
@@ -369,20 +318,8 @@ marshal_to_writer :: proc(
continue
}
- key := rawptr(
- runtime.map_cell_index_dynamic(
- ks,
- info.map_info.ks,
- bucket_index,
- ),
- )
- value := rawptr(
- runtime.map_cell_index_dynamic(
- vs,
- info.map_info.vs,
- bucket_index,
- ),
- )
+ key := rawptr(runtime.map_cell_index_dynamic(ks, info.map_info.ks, bucket_index))
+ value := rawptr(runtime.map_cell_index_dynamic(vs, info.map_info.vs, bucket_index))
opt_write_iteration(w, opt, i) or_return
i += 1
@@ -427,17 +364,13 @@ marshal_to_writer :: proc(
ti := runtime.type_info_base(type_info_of(id))
a := any{data, ti.id}
- if reflect.is_union(ti) &&
- reflect.is_nil(a) &&
- name != "result" {
+ if reflect.is_union(ti) && reflect.is_nil(a) && name != "result" {
continue
}
}
opt_write_iteration(w, opt, i) or_return
- if json_name := string(
- reflect.struct_tag_get(auto_cast info.tags[i], "json"),
- ); json_name != "" {
+ if json_name := string(reflect.struct_tag_get(auto_cast info.tags[i], "json")); json_name != "" {
opt_write_key(w, opt, json_name) or_return
} else {
opt_write_key(w, opt, name) or_return
@@ -485,9 +418,7 @@ marshal_to_writer :: proc(
return marshal_to_writer(w, any{v.data, info.base.id}, opt)
case runtime.Type_Info_Bit_Set:
- is_bit_set_different_endian_to_platform :: proc(
- ti: ^runtime.Type_Info,
- ) -> bool {
+ is_bit_set_different_endian_to_platform :: proc(ti: ^runtime.Type_Info) -> bool {
if ti == nil {
return false
}
@@ -509,9 +440,7 @@ marshal_to_writer :: proc(
bit_data: u64
bit_size := u64(8 * ti.size)
- do_byte_swap := is_bit_set_different_endian_to_platform(
- info.underlying,
- )
+ do_byte_swap := is_bit_set_different_endian_to_platform(info.underlying)
switch bit_size {
case 0:
@@ -550,13 +479,7 @@ marshal_to_writer :: proc(
// write key as quoted string or with optional quotes in mjson
-opt_write_key :: proc(
- w: io.Writer,
- opt: ^Marshal_Options,
- name: string,
-) -> (
- err: io.Error,
-) {
+opt_write_key :: proc(w: io.Writer, opt: ^Marshal_Options, name: string) -> (err: io.Error) {
switch opt.spec {
case .JSON, .JSON5:
io.write_quoted_string(w, name) or_return
@@ -580,13 +503,7 @@ opt_write_key :: proc(
}
// insert start byte and increase indentation on pretty
-opt_write_start :: proc(
- w: io.Writer,
- opt: ^Marshal_Options,
- c: byte,
-) -> (
- err: io.Error,
-) {
+opt_write_start :: proc(w: io.Writer, opt: ^Marshal_Options, c: byte) -> (err: io.Error) {
// skip mjson starting braces
if opt.spec == .MJSON && !opt.mjson_skipped_first_braces_start {
opt.mjson_skipped_first_braces_start = true
@@ -604,13 +521,7 @@ opt_write_start :: proc(
}
// insert comma separation and write indentations
-opt_write_iteration :: proc(
- w: io.Writer,
- opt: ^Marshal_Options,
- iteration: int,
-) -> (
- err: io.Error,
-) {
+opt_write_iteration :: proc(w: io.Writer, opt: ^Marshal_Options, iteration: int) -> (err: io.Error) {
switch opt.spec {
case .JSON, .JSON5:
if iteration > 0 {
@@ -641,16 +552,8 @@ opt_write_iteration :: proc(
}
// decrease indent, write spacing and insert end byte
-opt_write_end :: proc(
- w: io.Writer,
- opt: ^Marshal_Options,
- c: byte,
-) -> (
- err: io.Error,
-) {
- if opt.spec == .MJSON &&
- opt.mjson_skipped_first_braces_start &&
- !opt.mjson_skipped_first_braces_end {
+opt_write_end :: proc(w: io.Writer, opt: ^Marshal_Options, c: byte) -> (err: io.Error) {
+ if opt.spec == .MJSON && opt.mjson_skipped_first_braces_start && !opt.mjson_skipped_first_braces_end {
if opt.indentation == 0 {
opt.mjson_skipped_first_braces_end = true
return
@@ -669,12 +572,7 @@ opt_write_end :: proc(
}
// writes current indentation level based on options
-opt_write_indentation :: proc(
- w: io.Writer,
- opt: ^Marshal_Options,
-) -> (
- err: io.Error,
-) {
+opt_write_indentation :: proc(w: io.Writer, opt: ^Marshal_Options) -> (err: io.Error) {
if !opt.pretty {
return
}
diff --git a/src/server/memory_index.odin b/src/server/memory_index.odin
index ee151dc..f2b48f7 100644
--- a/src/server/memory_index.odin
+++ b/src/server/memory_index.odin
@@ -23,14 +23,7 @@ memory_index_clear_cache :: proc(index: ^MemoryIndex) {
index.last_package = nil
}
-memory_index_lookup :: proc(
- index: ^MemoryIndex,
- name: string,
- pkg: string,
-) -> (
- Symbol,
- bool,
-) {
+memory_index_lookup :: proc(index: ^MemoryIndex, name: string, pkg: string) -> (Symbol, bool) {
if index.last_package_name == pkg && index.last_package != nil {
return index.last_package[name]
}
@@ -47,14 +40,7 @@ memory_index_lookup :: proc(
return {}, false
}
-memory_index_fuzzy_search :: proc(
- index: ^MemoryIndex,
- name: string,
- pkgs: []string,
-) -> (
- []FuzzyResult,
- bool,
-) {
+memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, pkgs: []string) -> ([]FuzzyResult, bool) {
symbols := make([dynamic]FuzzyResult, 0, context.temp_allocator)
fuzzy_matcher := common.make_fuzzy_matcher(name)
@@ -64,8 +50,7 @@ memory_index_fuzzy_search :: proc(
for pkg in pkgs {
if pkg, ok := index.collection.packages[pkg]; ok {
for _, symbol in pkg.symbols {
- if score, ok := common.fuzzy_match(fuzzy_matcher, symbol.name);
- ok == 1 {
+ if score, ok := common.fuzzy_match(fuzzy_matcher, symbol.name); ok == 1 {
result := FuzzyResult {
symbol = symbol,
score = score,
diff --git a/src/server/methods.odin b/src/server/methods.odin
index 4b8efa8..1dae9a0 100644
--- a/src/server/methods.odin
+++ b/src/server/methods.odin
@@ -19,12 +19,7 @@ import "src:common"
@(private)
-create_remove_edit :: proc(
- position_context: ^DocumentPositionContext,
-) -> (
- []TextEdit,
- bool,
-) {
+create_remove_edit :: proc(position_context: ^DocumentPositionContext) -> ([]TextEdit, bool) {
range, ok := get_range_from_selection_start_to_dot(position_context)
if !ok {
@@ -74,9 +69,7 @@ append_method_completion :: proc(
resolve_unresolved_symbol(ast_context, &symbol)
build_procedure_symbol_signature(&symbol)
- range, ok := get_range_from_selection_start_to_dot(
- position_context,
- )
+ range, ok := get_range_from_selection_start_to_dot(position_context)
if !ok {
return
@@ -89,23 +82,18 @@ append_method_completion :: proc(
continue
}
- if len(value.arg_types) == 0 ||
- value.arg_types[0].type == nil {
+ if len(value.arg_types) == 0 || value.arg_types[0].type == nil {
continue
}
first_arg: Symbol
- first_arg, ok = resolve_type_expression(
- ast_context,
- value.arg_types[0].type,
- )
+ first_arg, ok = resolve_type_expression(ast_context, value.arg_types[0].type)
if !ok {
continue
}
- pointers_to_add :=
- first_arg.pointers - selector_symbol.pointers
+ pointers_to_add := first_arg.pointers - selector_symbol.pointers
references := ""
dereferences := ""
@@ -125,11 +113,7 @@ append_method_completion :: proc(
if symbol.pkg != ast_context.document_package {
new_text = fmt.tprintf(
"%v.%v",
- path.base(
- get_symbol_pkg_name(ast_context, symbol),
- false,
- ast_context.allocator,
- ),
+ path.base(get_symbol_pkg_name(ast_context, symbol), false, ast_context.allocator),
symbol.name,
)
} else {
@@ -137,36 +121,17 @@ append_method_completion :: proc(
}
if len(symbol.value.(SymbolProcedureValue).arg_types) > 1 {
- new_text = fmt.tprintf(
- "%v(%v%v%v$0)",
- new_text,
- references,
- receiver,
- dereferences,
- )
+ new_text = fmt.tprintf("%v(%v%v%v$0)", new_text, references, receiver, dereferences)
} else {
- new_text = fmt.tprintf(
- "%v(%v%v%v)$0",
- new_text,
- references,
- receiver,
- dereferences,
- )
+ new_text = fmt.tprintf("%v(%v%v%v)$0", new_text, references, receiver, dereferences)
}
item := CompletionItem {
label = symbol.name,
kind = symbol_type_to_completion_kind(symbol.type),
- detail = concatenate_symbol_information(
- ast_context,
- symbol,
- true,
- ),
+ detail = concatenate_symbol_information(ast_context, symbol, true),
additionalTextEdits = remove_edit,
- textEdit = TextEdit {
- newText = new_text,
- range = {start = range.end, end = range.end},
- },
+ textEdit = TextEdit{newText = new_text, range = {start = range.end, end = range.end}},
insertTextFormat = .Snippet,
InsertTextMode = .adjustIndentation,
documentation = symbol.doc,
diff --git a/src/server/reader.odin b/src/server/reader.odin
index 1a32b6f..a67fd28 100644
--- a/src/server/reader.odin
+++ b/src/server/reader.odin
@@ -1,7 +1,7 @@
package server
-import "core:os"
import "core:mem"
+import "core:os"
import "core:strings"
ReaderFn :: proc(_: rawptr, _: []byte) -> (int, int)
@@ -27,11 +27,7 @@ read_u8 :: proc(reader: ^Reader) -> (u8, bool) {
return value[0], true
}
-read_until_delimiter :: proc(
- reader: ^Reader,
- delimiter: u8,
- builder: ^strings.Builder,
-) -> bool {
+read_until_delimiter :: proc(reader: ^Reader, delimiter: u8, builder: ^strings.Builder) -> bool {
for true {
value, success := read_u8(reader)
diff --git a/src/server/references.odin b/src/server/references.odin
index a80164d..944a337 100644
--- a/src/server/references.odin
+++ b/src/server/references.odin
@@ -17,14 +17,7 @@ import "src:common"
fullpaths: [dynamic]string
-walk_directories :: proc(
- info: os.File_Info,
- in_err: os.Errno,
- user_data: rawptr,
-) -> (
- err: os.Error,
- skip_dir: bool,
-) {
+walk_directories :: proc(info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> (err: os.Error, skip_dir: bool) {
document := cast(^Document)user_data
if info.is_dir {
@@ -36,15 +29,9 @@ walk_directories :: proc(
}
if strings.contains(info.name, ".odin") {
- slash_path, _ := filepath.to_slash(
- info.fullpath,
- context.temp_allocator,
- )
+ slash_path, _ := filepath.to_slash(info.fullpath, context.temp_allocator)
if slash_path != document.fullpath {
- append(
- &fullpaths,
- strings.clone(info.fullpath, context.temp_allocator),
- )
+ append(&fullpaths, strings.clone(info.fullpath, context.temp_allocator))
}
}
@@ -72,10 +59,7 @@ prepare_references :: proc(
for name in field.names {
if position_in_node(name, position_context.position) {
symbol = Symbol {
- range = common.get_token_range(
- name,
- string(document.text),
- ),
+ range = common.get_token_range(name, string(document.text)),
}
found = true
resolve_flag = .Field
@@ -115,10 +99,7 @@ prepare_references :: proc(
for variant in position_context.union_type.variants {
if position_in_node(variant, position_context.position) {
if ident, ok := variant.derived.(^ast.Ident); ok {
- symbol, ok = resolve_location_identifier(
- ast_context,
- ident^,
- )
+ symbol, ok = resolve_location_identifier(ast_context, ident^)
reference = ident.name
resolve_flag = .Identifier
@@ -141,14 +122,8 @@ prepare_references :: proc(
} else if position_context.field_value != nil &&
position_context.comp_lit != nil &&
!common.is_expr_basic_lit(position_context.field_value.field) &&
- position_in_node(
- position_context.field_value.field,
- position_context.position,
- ) {
- symbol, ok = resolve_location_comp_lit_field(
- ast_context,
- position_context,
- )
+ position_in_node(position_context.field_value.field, position_context.position) {
+ symbol, ok = resolve_location_comp_lit_field(ast_context, position_context)
if !ok {
return
@@ -166,9 +141,7 @@ prepare_references :: proc(
base: ^ast.Ident
base, ok = position_context.selector.derived.(^ast.Ident)
- if position_in_node(base, position_context.position) &&
- position_context.identifier != nil &&
- ok {
+ if position_in_node(base, position_context.position) && position_context.identifier != nil && ok {
ident := position_context.identifier.derived.(^ast.Ident)
@@ -180,10 +153,7 @@ prepare_references :: proc(
resolve_flag = .Base
} else {
- symbol, ok = resolve_location_selector(
- ast_context,
- position_context.selector_expr,
- )
+ symbol, ok = resolve_location_selector(ast_context, position_context.selector_expr)
resolve_flag = .Field
}
@@ -228,11 +198,7 @@ resolve_references :: proc(
locations := make([dynamic]common.Location, 0, ast_context.allocator)
fullpaths = make([dynamic]string, 0, ast_context.allocator)
- symbol, resolve_flag, ok := prepare_references(
- document,
- ast_context,
- position_context,
- )
+ symbol, resolve_flag, ok := prepare_references(document, ast_context, position_context)
if !ok {
return {}, true
@@ -250,11 +216,7 @@ resolve_references :: proc(
arena: runtime.Arena
- _ = runtime.arena_init(
- &arena,
- mem.Megabyte * 40,
- runtime.default_allocator(),
- )
+ _ = runtime.arena_init(&arena, mem.Megabyte * 40, runtime.default_allocator())
defer runtime.arena_destroy(&arena)
@@ -271,10 +233,7 @@ resolve_references :: proc(
data, ok := os.read_entire_file(fullpath, context.allocator)
if !ok {
- log.errorf(
- "failed to read entire file for indexing %v",
- fullpath,
- )
+ log.errorf("failed to read entire file for indexing %v", fullpath)
continue
}
@@ -303,8 +262,7 @@ resolve_references :: proc(
ok = parser.parse_file(&p, &file)
if !ok {
- if !strings.contains(fullpath, "builtin.odin") &&
- !strings.contains(fullpath, "intrinsics.odin") {
+ if !strings.contains(fullpath, "builtin.odin") && !strings.contains(fullpath, "intrinsics.odin") {
log.errorf("error in parse file for indexing %v", fullpath)
}
continue
@@ -334,29 +292,15 @@ resolve_references :: proc(
}
if in_pkg || symbol.pkg == document.package_name {
- symbols_and_nodes := resolve_entire_file(
- &document,
- resolve_flag,
- context.allocator,
- )
+ symbols_and_nodes := resolve_entire_file(&document, resolve_flag, context.allocator)
for k, v in symbols_and_nodes {
- if v.symbol.uri == symbol.uri &&
- v.symbol.range == symbol.range {
- node_uri := common.create_uri(
- v.node.pos.file,
- ast_context.allocator,
- )
+ if v.symbol.uri == symbol.uri && v.symbol.range == symbol.range {
+ node_uri := common.create_uri(v.node.pos.file, ast_context.allocator)
location := common.Location {
- range = common.get_token_range(
- v.node^,
- string(document.text),
- ),
- uri = strings.clone(
- node_uri.uri,
- ast_context.allocator,
- ),
+ range = common.get_token_range(v.node^, string(document.text)),
+ uri = strings.clone(node_uri.uri, ast_context.allocator),
}
append(&locations, location)
}
@@ -367,18 +311,11 @@ resolve_references :: proc(
}
}
- symbols_and_nodes := resolve_entire_file(
- document,
- resolve_flag,
- context.allocator,
- )
+ symbols_and_nodes := resolve_entire_file(document, resolve_flag, context.allocator)
for k, v in symbols_and_nodes {
if v.symbol.uri == symbol.uri && v.symbol.range == symbol.range {
- node_uri := common.create_uri(
- v.node.pos.file,
- ast_context.allocator,
- )
+ node_uri := common.create_uri(v.node.pos.file, ast_context.allocator)
range := common.get_token_range(v.node^, string(document.text))
@@ -399,13 +336,7 @@ resolve_references :: proc(
return locations[:], true
}
-get_references :: proc(
- document: ^Document,
- position: common.Position,
-) -> (
- []common.Location,
- bool,
-) {
+get_references :: proc(document: ^Document, position: common.Position) -> ([]common.Location, bool) {
ast_context := make_ast_context(
document.ast,
document.imports,
@@ -415,30 +346,17 @@ get_references :: proc(
context.temp_allocator,
)
- position_context, ok := get_document_position_context(
- document,
- position,
- .Hover,
- )
+ position_context, ok := get_document_position_context(document, position, .Hover)
get_globals(document.ast, &ast_context)
ast_context.current_package = ast_context.document_package
if position_context.function != nil {
- get_locals(
- document.ast,
- position_context.function,
- &ast_context,
- &position_context,
- )
+ get_locals(document.ast, position_context.function, &ast_context, &position_context)
}
- locations, ok2 := resolve_references(
- document,
- &ast_context,
- &position_context,
- )
+ locations, ok2 := resolve_references(document, &ast_context, &position_context)
temp_locations := make([dynamic]common.Location, 0, context.temp_allocator)
diff --git a/src/server/rename.odin b/src/server/rename.odin
index 6041641..5e02af6 100644
--- a/src/server/rename.odin
+++ b/src/server/rename.odin
@@ -9,14 +9,7 @@ import "core:strings"
import "src:common"
-get_rename :: proc(
- document: ^Document,
- new_text: string,
- position: common.Position,
-) -> (
- WorkspaceEdit,
- bool,
-) {
+get_rename :: proc(document: ^Document, new_text: string, position: common.Position) -> (WorkspaceEdit, bool) {
ast_context := make_ast_context(
document.ast,
document.imports,
@@ -26,30 +19,17 @@ get_rename :: proc(
context.temp_allocator,
)
- position_context, ok := get_document_position_context(
- document,
- position,
- .Hover,
- )
+ position_context, ok := get_document_position_context(document, position, .Hover)
get_globals(document.ast, &ast_context)
ast_context.current_package = ast_context.document_package
if position_context.function != nil {
- get_locals(
- document.ast,
- position_context.function,
- &ast_context,
- &position_context,
- )
+ get_locals(document.ast, position_context.function, &ast_context, &position_context)
}
- locations, ok2 := resolve_references(
- document,
- &ast_context,
- &position_context,
- )
+ locations, ok2 := resolve_references(document, &ast_context, &position_context)
changes := make(map[string][dynamic]TextEdit, 0, context.temp_allocator)
@@ -57,8 +37,10 @@ get_rename :: proc(
edits: ^[dynamic]TextEdit
if edits = &changes[location.uri]; edits == nil {
- changes[strings.clone(location.uri, context.temp_allocator)] =
- make([dynamic]TextEdit, context.temp_allocator)
+ changes[strings.clone(location.uri, context.temp_allocator)] = make(
+ [dynamic]TextEdit,
+ context.temp_allocator,
+ )
edits = &changes[location.uri]
}
@@ -67,11 +49,7 @@ get_rename :: proc(
workspace: WorkspaceEdit
- workspace.changes = make(
- map[string][]TextEdit,
- len(changes),
- context.temp_allocator,
- )
+ workspace.changes = make(map[string][]TextEdit, len(changes), context.temp_allocator)
for k, v in changes {
workspace.changes[k] = v[:]
@@ -81,13 +59,7 @@ get_rename :: proc(
}
-get_prepare_rename :: proc(
- document: ^Document,
- position: common.Position,
-) -> (
- common.Range,
- bool,
-) {
+get_prepare_rename :: proc(document: ^Document, position: common.Position) -> (common.Range, bool) {
ast_context := make_ast_context(
document.ast,
document.imports,
@@ -97,30 +69,17 @@ get_prepare_rename :: proc(
context.temp_allocator,
)
- position_context, ok := get_document_position_context(
- document,
- position,
- .Hover,
- )
+ position_context, ok := get_document_position_context(document, position, .Hover)
get_globals(document.ast, &ast_context)
ast_context.current_package = ast_context.document_package
if position_context.function != nil {
- get_locals(
- document.ast,
- position_context.function,
- &ast_context,
- &position_context,
- )
+ get_locals(document.ast, position_context.function, &ast_context, &position_context)
}
- symbol, _, ok2 := prepare_references(
- document,
- &ast_context,
- &position_context,
- )
+ symbol, _, ok2 := prepare_references(document, &ast_context, &position_context)
return symbol.range, ok2
diff --git a/src/server/requests.odin b/src/server/requests.odin
index 04505b3..a4dd4ad 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -58,17 +58,11 @@ RequestInfo :: struct {
}
-make_response_message :: proc(
- id: RequestId,
- params: ResponseParams,
-) -> ResponseMessage {
+make_response_message :: proc(id: RequestId, params: ResponseParams) -> ResponseMessage {
return ResponseMessage{jsonrpc = "2.0", id = id, result = params}
}
-make_response_message_error :: proc(
- id: RequestId,
- error: ResponseError,
-) -> ResponseMessageError {
+make_response_message_error :: proc(id: RequestId, error: ResponseError) -> ResponseMessageError {
return ResponseMessageError{jsonrpc = "2.0", id = id, error = error}
}
@@ -218,13 +212,7 @@ read_and_parse_header :: proc(reader: ^Reader) -> (Header, bool) {
return header, found_content_length
}
-read_and_parse_body :: proc(
- reader: ^Reader,
- header: Header,
-) -> (
- json.Value,
- bool,
-) {
+read_and_parse_body :: proc(reader: ^Reader, header: Header) -> (json.Value, bool) {
value: json.Value
data := make([]u8, header.content_length, context.temp_allocator)
@@ -236,11 +224,7 @@ read_and_parse_body :: proc(
err: json.Error
- value, err = json.parse(
- data = data,
- allocator = context.allocator,
- parse_integers = true,
- )
+ value, err = json.parse(data = data, allocator = context.allocator, parse_integers = true)
if (err != json.Error.None) {
log.error("Failed to parse body")
@@ -250,12 +234,7 @@ read_and_parse_body :: proc(
return value, true
}
-call_map: map[string]proc(
- _: json.Value,
- _: RequestId,
- _: ^common.Config,
- _: ^Writer,
-) -> common.Error = {
+call_map: map[string]proc(_: json.Value, _: RequestId, _: ^common.Config, _: ^Writer) -> common.Error = {
"initialize" = request_initialize,
"initialized" = request_initialized,
"shutdown" = request_shutdown,
@@ -306,12 +285,7 @@ consume_requests :: proc(config: ^common.Config, writer: ^Writer) -> bool {
}
}
if delete_index != -1 {
- cancel(
- requests[delete_index].value,
- requests[delete_index].id,
- writer,
- config,
- )
+ cancel(requests[delete_index].value, requests[delete_index].id, writer, config)
ordered_remove(&requests, delete_index)
}
}
@@ -352,12 +326,7 @@ consume_requests :: proc(config: ^common.Config, writer: ^Writer) -> bool {
}
-cancel :: proc(
- value: json.Value,
- id: RequestId,
- writer: ^Writer,
- config: ^common.Config,
-) {
+cancel :: proc(value: json.Value, id: RequestId, writer: ^Writer, config: ^common.Config) {
response := make_response_message(id = id, params = ResponseParams{})
json.destroy_value(value)
@@ -365,12 +334,7 @@ cancel :: proc(
send_response(response, writer)
}
-call :: proc(
- value: json.Value,
- id: RequestId,
- writer: ^Writer,
- config: ^common.Config,
-) {
+call :: proc(value: json.Value, id: RequestId, writer: ^Writer, config: ^common.Config) {
root := value.(json.Object)
method := root["method"].(json.String)
@@ -387,10 +351,7 @@ call :: proc(
} else {
err := fn(root["params"], id, config, writer)
if err != .None {
- response := make_response_message_error(
- id = id,
- error = ResponseError{code = err, message = ""},
- )
+ response := make_response_message_error(id = id, error = ResponseError{code = err, message = ""})
send_error(response, writer)
}
}
@@ -399,33 +360,20 @@ call :: proc(
//log.errorf("time duration %v for %v", time.duration_milliseconds(diff), method)
}
-read_ols_initialize_options :: proc(
- config: ^common.Config,
- ols_config: OlsConfig,
- uri: common.Uri,
-) {
- config.disable_parser_errors =
- ols_config.disable_parser_errors.(bool) or_else config.disable_parser_errors
- config.thread_count =
- ols_config.thread_pool_count.(int) or_else config.thread_count
- config.enable_document_symbols =
- ols_config.enable_document_symbols.(bool) or_else config.enable_document_symbols
- config.enable_format =
- ols_config.enable_format.(bool) or_else config.enable_format
- config.enable_hover =
- ols_config.enable_hover.(bool) or_else config.enable_hover
- config.enable_semantic_tokens =
- ols_config.enable_semantic_tokens.(bool) or_else config.enable_semantic_tokens
+read_ols_initialize_options :: proc(config: ^common.Config, ols_config: OlsConfig, uri: common.Uri) {
+ config.disable_parser_errors = ols_config.disable_parser_errors.(bool) or_else config.disable_parser_errors
+ config.thread_count = ols_config.thread_pool_count.(int) or_else config.thread_count
+ config.enable_document_symbols = ols_config.enable_document_symbols.(bool) or_else config.enable_document_symbols
+ config.enable_format = ols_config.enable_format.(bool) or_else config.enable_format
+ config.enable_hover = ols_config.enable_hover.(bool) or_else config.enable_hover
+ config.enable_semantic_tokens = ols_config.enable_semantic_tokens.(bool) or_else config.enable_semantic_tokens
config.enable_procedure_context =
ols_config.enable_procedure_context.(bool) or_else config.enable_procedure_context
- config.enable_snippets =
- ols_config.enable_snippets.(bool) or_else config.enable_snippets
- config.enable_references =
- ols_config.enable_references.(bool) or_else config.enable_references
+ config.enable_snippets = ols_config.enable_snippets.(bool) or_else config.enable_snippets
+ config.enable_references = ols_config.enable_references.(bool) or_else config.enable_references
config.verbose = ols_config.verbose.(bool) or_else config.verbose
config.file_log = ols_config.file_log.(bool) or_else config.file_log
- config.enable_rename =
- ols_config.enable_references.(bool) or_else config.enable_rename
+ config.enable_rename = ols_config.enable_references.(bool) or_else config.enable_rename
config.enable_procedure_snippet =
ols_config.enable_procedure_snippet.(bool) or_else config.enable_procedure_snippet
@@ -434,48 +382,30 @@ read_ols_initialize_options :: proc(
ols_config.enable_checker_only_saved.(bool) or_else config.enable_checker_only_saved
if ols_config.odin_command != "" {
- config.odin_command = strings.clone(
- ols_config.odin_command,
- context.temp_allocator,
- )
+ config.odin_command = strings.clone(ols_config.odin_command, context.temp_allocator)
allocated: bool
- config.odin_command, allocated = common.resolve_home_dir(
- config.odin_command,
- )
+ config.odin_command, allocated = common.resolve_home_dir(config.odin_command)
if !allocated {
- config.odin_command = strings.clone(
- config.odin_command,
- context.allocator,
- )
+ config.odin_command = strings.clone(config.odin_command, context.allocator)
}
}
if ols_config.checker_args != "" {
- config.checker_args = strings.clone(
- ols_config.checker_args,
- context.allocator,
- )
+ config.checker_args = strings.clone(ols_config.checker_args, context.allocator)
}
for profile in ols_config.profiles {
if ols_config.profile == profile.name {
- config.profile.checker_path = make(
- [dynamic]string,
- len(profile.checker_path),
- )
+ config.profile.checker_path = make([dynamic]string, len(profile.checker_path))
if filepath.is_abs(ols_config.profile) {
for checker_path, i in profile.checker_path {
- config.profile.checker_path[i] = strings.clone(
- checker_path,
- )
+ config.profile.checker_path[i] = strings.clone(checker_path)
}
} else {
for checker_path, i in profile.checker_path {
- config.profile.checker_path[i] = path.join(
- elems = {uri.path, checker_path},
- )
+ config.profile.checker_path[i] = path.join(elems = {uri.path, checker_path})
}
}
@@ -489,20 +419,15 @@ read_ols_initialize_options :: proc(
config.profile.os = os_enum_to_string[ODIN_OS]
}
- config.checker_targets = slice.clone(
- ols_config.checker_targets,
- context.allocator,
- )
+ config.checker_targets = slice.clone(ols_config.checker_targets, context.allocator)
- config.enable_inlay_hints =
- ols_config.enable_inlay_hints.(bool) or_else config.enable_inlay_hints
+ config.enable_inlay_hints = ols_config.enable_inlay_hints.(bool) or_else config.enable_inlay_hints
config.enable_inlay_hints_params =
ols_config.enable_inlay_hints_params.(bool) or_else config.enable_inlay_hints_params
config.enable_inlay_hints_default_params =
ols_config.enable_inlay_hints_default_params.(bool) or_else config.enable_inlay_hints_default_params
- config.enable_fake_method =
- ols_config.enable_fake_methods.(bool) or_else config.enable_fake_method
+ config.enable_fake_method = ols_config.enable_fake_methods.(bool) or_else config.enable_fake_method
for it in ols_config.collections {
@@ -513,29 +438,20 @@ read_ols_initialize_options :: proc(
forward_path, _ := filepath.to_slash(it.path, context.temp_allocator)
- forward_path = common.resolve_home_dir(
- forward_path,
- context.temp_allocator,
- )
+ forward_path = common.resolve_home_dir(forward_path, context.temp_allocator)
final_path := ""
when ODIN_OS == .Windows {
if filepath.is_abs(it.path) {
final_path, _ = filepath.to_slash(
- common.get_case_sensitive_path(
- forward_path,
- context.temp_allocator,
- ),
+ common.get_case_sensitive_path(forward_path, context.temp_allocator),
context.temp_allocator,
)
} else {
final_path, _ = filepath.to_slash(
common.get_case_sensitive_path(
- path.join(
- elems = {uri.path, forward_path},
- allocator = context.temp_allocator,
- ),
+ path.join(elems = {uri.path, forward_path}, allocator = context.temp_allocator),
context.temp_allocator,
),
context.temp_allocator,
@@ -545,35 +461,19 @@ read_ols_initialize_options :: proc(
final_path = strings.clone(final_path, context.temp_allocator)
} else {
if filepath.is_abs(it.path) {
- final_path = strings.clone(
- forward_path,
- context.temp_allocator,
- )
+ final_path = strings.clone(forward_path, context.temp_allocator)
} else {
- final_path = path.join(
- {uri.path, forward_path},
- context.temp_allocator,
- )
+ final_path = path.join({uri.path, forward_path}, context.temp_allocator)
}
}
if abs_final_path, ok := filepath.abs(final_path); ok {
- slashed_path, _ := filepath.to_slash(
- abs_final_path,
- context.temp_allocator,
- )
+ slashed_path, _ := filepath.to_slash(abs_final_path, context.temp_allocator)
- config.collections[strings.clone(it.name)] = strings.clone(
- slashed_path,
- )
+ config.collections[strings.clone(it.name)] = strings.clone(slashed_path)
} else {
- log.errorf(
- "Failed to find absolute address of collection: %v",
- final_path,
- )
- config.collections[strings.clone(it.name)] = strings.clone(
- final_path,
- )
+ log.errorf("Failed to find absolute address of collection: %v", final_path)
+ config.collections[strings.clone(it.name)] = strings.clone(final_path)
}
}
@@ -586,10 +486,7 @@ read_ols_initialize_options :: proc(
root_buf: [1024]byte
root_slice := root_buf[:]
- root_command := strings.concatenate(
- {odin_bin, " root"},
- context.temp_allocator,
- )
+ root_command := strings.concatenate({odin_bin, " root"}, context.temp_allocator)
code, ok, out := common.run_executable(root_command, &root_slice)
if ok && !strings.contains(string(out), "Usage") {
odin_core_env = string(out)
@@ -607,10 +504,7 @@ read_ols_initialize_options :: proc(
}
}
- if abs_core_env, ok := filepath.abs(
- odin_core_env,
- context.temp_allocator,
- ); ok {
+ if abs_core_env, ok := filepath.abs(odin_core_env, context.temp_allocator); ok {
odin_core_env = abs_core_env
}
}
@@ -618,10 +512,7 @@ read_ols_initialize_options :: proc(
log.infof("resolved odin root to: %q", odin_core_env)
if "core" not_in config.collections && odin_core_env != "" {
- forward_path, _ := filepath.to_slash(
- odin_core_env,
- context.temp_allocator,
- )
+ forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator)
config.collections[strings.clone("core")] = path.join(
elems = {forward_path, "core"},
allocator = context.allocator,
@@ -629,10 +520,7 @@ read_ols_initialize_options :: proc(
}
if "vendor" not_in config.collections && odin_core_env != "" {
- forward_path, _ := filepath.to_slash(
- odin_core_env,
- context.temp_allocator,
- )
+ forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator)
config.collections[strings.clone("vendor")] = path.join(
elems = {forward_path, "vendor"},
allocator = context.allocator,
@@ -640,10 +528,7 @@ read_ols_initialize_options :: proc(
}
if "base" not_in config.collections && odin_core_env != "" {
- forward_path, _ := filepath.to_slash(
- odin_core_env,
- context.temp_allocator,
- )
+ forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator)
config.collections[strings.clone("base")] = path.join(
elems = {forward_path, "base"},
allocator = context.allocator,
@@ -651,10 +536,7 @@ read_ols_initialize_options :: proc(
}
if "shared" not_in config.collections && odin_core_env != "" {
- forward_path, _ := filepath.to_slash(
- odin_core_env,
- context.temp_allocator,
- )
+ forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator)
config.collections[strings.clone("shared")] = path.join(
elems = {forward_path, "shared"},
allocator = context.allocator,
@@ -716,21 +598,13 @@ request_initialize :: proc(
config.enable_procedure_snippet = true
config.enable_checker_only_saved = true
- read_ols_config :: proc(
- file: string,
- config: ^common.Config,
- uri: common.Uri,
- ) {
+ read_ols_config :: proc(file: string, config: ^common.Config, uri: common.Uri) {
if data, ok := os.read_entire_file(file, context.temp_allocator); ok {
- if value, err := json.parse(
- data = data,
- allocator = context.temp_allocator,
- parse_integers = true,
- ); err == .None {
+ if value, err := json.parse(data = data, allocator = context.temp_allocator, parse_integers = true);
+ err == .None {
ols_config: OlsConfig
- if unmarshal(value, ols_config, context.temp_allocator) ==
- nil {
+ if unmarshal(value, ols_config, context.temp_allocator) == nil {
read_ols_initialize_options(config, ols_config, uri)
} else {
log.warnf("Failed to unmarshal %v", file)
@@ -753,27 +627,17 @@ request_initialize :: proc(
if uri, ok := common.parse_uri(project_uri, context.temp_allocator); ok {
global_ols_config_path := path.join(
- elems = {
- filepath.dir(os.args[0], context.temp_allocator),
- "ols.json",
- },
+ elems = {filepath.dir(os.args[0], context.temp_allocator), "ols.json"},
allocator = context.temp_allocator,
)
read_ols_config(global_ols_config_path, config, uri)
- ols_config_path := path.join(
- elems = {uri.path, "ols.json"},
- allocator = context.temp_allocator,
- )
+ ols_config_path := path.join(elems = {uri.path, "ols.json"}, allocator = context.temp_allocator)
read_ols_config(ols_config_path, config, uri)
- read_ols_initialize_options(
- config,
- initialize_params.initializationOptions,
- uri,
- )
+ read_ols_initialize_options(config, initialize_params.initializationOptions, uri)
}
@@ -792,8 +656,7 @@ request_initialize :: proc(
config.enable_label_details =
initialize_params.capabilities.textDocument.completion.completionItem.labelDetailsSupport
- config.enable_snippets &=
- initialize_params.capabilities.textDocument.completion.completionItem.snippetSupport
+ config.enable_snippets &= initialize_params.capabilities.textDocument.completion.completionItem.snippetSupport
config.signature_offset_support =
initialize_params.capabilities.textDocument.signatureHelp.signatureInformation.parameterInformation.labelOffsetSupport
@@ -805,11 +668,7 @@ request_initialize :: proc(
response := make_response_message(
params = ResponseInitializeParams {
capabilities = ServerCapabilities {
- textDocumentSync = TextDocumentSyncOptions {
- openClose = true,
- change = 2,
- save = {includeText = true},
- },
+ textDocumentSync = TextDocumentSyncOptions{openClose = true, change = 2, save = {includeText = true}},
renameProvider = RenameOptions{prepareProvider = true},
workspaceSymbolProvider = true,
referencesProvider = config.enable_references,
@@ -871,12 +730,7 @@ request_initialized :: proc(
return .None
}
-request_shutdown :: proc(
- params: json.Value,
- id: RequestId,
- config: ^common.Config,
- writer: ^Writer,
-) -> common.Error {
+request_shutdown :: proc(params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
response := make_response_message(params = nil, id = id)
send_response(response, writer)
@@ -908,10 +762,7 @@ request_definition :: proc(
return .InternalError
}
- locations, ok2 := get_definition_location(
- document,
- definition_params.position,
- )
+ locations, ok2 := get_definition_location(document, definition_params.position)
if !ok2 {
log.warn("Failed to get definition location")
@@ -954,11 +805,7 @@ request_completion :: proc(
}
list: CompletionList
- list, ok = get_completion_list(
- document,
- completition_params.position,
- completition_params.context_,
- )
+ list, ok = get_completion_list(document, completition_params.position, completition_params.context_)
if !ok {
return .InternalError
@@ -1052,12 +899,7 @@ request_format_document :: proc(
return .None
}
-notification_exit :: proc(
- params: json.Value,
- id: RequestId,
- config: ^common.Config,
- writer: ^Writer,
-) -> common.Error {
+notification_exit :: proc(params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
config.running = false
return .None
}
@@ -1082,12 +924,7 @@ notification_did_open :: proc(
return .ParseError
}
- if n := document_open(
- open_params.textDocument.uri,
- open_params.textDocument.text,
- config,
- writer,
- ); n != .None {
+ if n := document_open(open_params.textDocument.uri, open_params.textDocument.text, config, writer); n != .None {
return .InternalError
}
@@ -1168,10 +1005,7 @@ notification_did_save :: proc(
uri: common.Uri
- if uri, ok = common.parse_uri(
- save_params.textDocument.uri,
- context.temp_allocator,
- ); !ok {
+ if uri, ok = common.parse_uri(save_params.textDocument.uri, context.temp_allocator); !ok {
return .ParseError
}
@@ -1184,10 +1018,7 @@ notification_did_save :: proc(
}
when ODIN_OS == .Windows {
- correct := common.get_case_sensitive_path(
- fullpath,
- context.temp_allocator,
- )
+ correct := common.get_case_sensitive_path(fullpath, context.temp_allocator)
fullpath, _ = filepath.to_slash(correct, context.temp_allocator)
}
@@ -1211,8 +1042,7 @@ notification_did_save :: proc(
ok = parser.parse_file(&p, &file)
if !ok {
- if !strings.contains(fullpath, "builtin.odin") &&
- !strings.contains(fullpath, "intrinsics.odin") {
+ if !strings.contains(fullpath, "builtin.odin") && !strings.contains(fullpath, "intrinsics.odin") {
log.errorf("error in parse file for indexing %v", fullpath)
}
}
@@ -1238,11 +1068,7 @@ notification_did_save :: proc(
}
}
- if ret := collect_symbols(
- &indexer.index.collection,
- file,
- corrected_uri.uri,
- ); ret != .None {
+ if ret := collect_symbols(&indexer.index.collection, file, corrected_uri.uri); ret != .None {
log.errorf("failed to collect symbols on save %v", ret)
}
@@ -1328,11 +1154,7 @@ request_semantic_token_range :: proc(
resolve_entire_file_cached(document)
if file, ok := file_resolve_cache.files[document.uri.uri]; ok {
- tokens := get_semantic_tokens(
- document,
- semantic_params.range,
- file.symbols,
- )
+ tokens := get_semantic_tokens(document, semantic_params.range, file.symbols)
tokens_params = semantic_tokens_to_response_params(tokens)
}
}
@@ -1377,12 +1199,7 @@ request_document_symbols :: proc(
return .None
}
-request_hover :: proc(
- params: json.Value,
- id: RequestId,
- config: ^common.Config,
- writer: ^Writer,
-) -> common.Error {
+request_hover :: proc(params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
params_object, ok := params.(json.Object)
if !ok {
@@ -1536,12 +1353,7 @@ request_prepare_rename :: proc(
return .None
}
-request_rename :: proc(
- params: json.Value,
- id: RequestId,
- config: ^common.Config,
- writer: ^Writer,
-) -> common.Error {
+request_rename :: proc(params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
params_object, ok := params.(json.Object)
if !ok {
@@ -1561,11 +1373,7 @@ request_rename :: proc(
}
workspace_edit: WorkspaceEdit
- workspace_edit, ok = get_rename(
- document,
- rename_param.newName,
- rename_param.position,
- )
+ workspace_edit, ok = get_rename(document, rename_param.newName, rename_param.position)
if !ok {
return .InternalError
@@ -1630,17 +1438,13 @@ notification_workspace_did_change_configuration :: proc(
workspace_config_params: DidChangeConfigurationParams
- if unmarshal(params, workspace_config_params, context.temp_allocator) !=
- nil {
+ if unmarshal(params, workspace_config_params, context.temp_allocator) != nil {
return .ParseError
}
ols_config := workspace_config_params.settings
- if uri, ok := common.parse_uri(
- config.workspace_folders[0].uri,
- context.temp_allocator,
- ); ok {
+ if uri, ok := common.parse_uri(config.workspace_folders[0].uri, context.temp_allocator); ok {
read_ols_initialize_options(config, ols_config, uri)
}
@@ -1661,8 +1465,7 @@ request_workspace_symbols :: proc(
workspace_symbol_params: WorkspaceSymbolParams
- if unmarshal(params, workspace_symbol_params, context.temp_allocator) !=
- nil {
+ if unmarshal(params, workspace_symbol_params, context.temp_allocator) != nil {
return .ParseError
}
@@ -1680,11 +1483,6 @@ request_workspace_symbols :: proc(
return .None
}
-request_noop :: proc(
- params: json.Value,
- id: RequestId,
- config: ^common.Config,
- writer: ^Writer,
-) -> common.Error {
+request_noop :: proc(params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
return .None
}
diff --git a/src/server/response.odin b/src/server/response.odin
index 916f1b1..1019eb6 100644
--- a/src/server/response.odin
+++ b/src/server/response.odin
@@ -1,12 +1,9 @@
package server
-import "core:fmt"
import "core:encoding/json"
+import "core:fmt"
-send_notification :: proc(
- notification: Notification,
- writer: ^Writer,
-) -> bool {
+send_notification :: proc(notification: Notification, writer: ^Writer) -> bool {
data, error := marshal(notification, {}, context.temp_allocator)
header := fmt.tprintf("Content-Length: %v\r\n\r\n", len(data))
diff --git a/src/server/semantic_tokens.odin b/src/server/semantic_tokens.odin
index 8b97946..5d53a24 100644
--- a/src/server/semantic_tokens.odin
+++ b/src/server/semantic_tokens.odin
@@ -62,12 +62,7 @@ SemanticTokenModifier :: enum u8 {
ReadOnly,
}
// Need to be in the same order as SemanticTokenModifier
-semantic_token_modifier_names: []string = {
- "declaration",
- "definition",
- "deprecated",
- "readonly",
-}
+semantic_token_modifier_names: []string = {"declaration", "definition", "deprecated", "readonly"}
SemanticTokenModifiers :: bit_set[SemanticTokenModifier;u32]
SemanticTokensClientCapabilities :: struct {
@@ -124,9 +119,7 @@ SemanticTokenBuilder :: struct {
src: string,
}
-semantic_tokens_to_response_params :: proc(
- tokens: []SemanticToken,
-) -> SemanticTokensResponseParams {
+semantic_tokens_to_response_params :: proc(tokens: []SemanticToken) -> SemanticTokensResponseParams {
return {data = (cast([^]u32)raw_data(tokens))[:len(tokens) * 5]}
}
@@ -145,19 +138,13 @@ get_semantic_tokens :: proc(
ast_context.current_package = ast_context.document_package
builder: SemanticTokenBuilder = {
- tokens = make(
- [dynamic]SemanticToken,
- 0,
- 2000,
- context.temp_allocator,
- ),
+ tokens = make([dynamic]SemanticToken, 0, 2000, context.temp_allocator),
symbols = symbols,
src = ast_context.file.src,
}
for decl in document.ast.decls {
- if range.start.line <= decl.pos.line &&
- decl.end.line <= range.end.line {
+ if range.start.line <= decl.pos.line && decl.end.line <= range.end.line {
visit_node(decl, &builder)
}
}
@@ -172,11 +159,7 @@ write_semantic_at_pos :: proc(
type: SemanticTokenTypes,
modifiers: SemanticTokenModifiers = {},
) {
- position := common.get_relative_token_position(
- pos,
- transmute([]u8)builder.src,
- builder.current_start,
- )
+ position := common.get_relative_token_position(pos, transmute([]u8)builder.src, builder.current_start)
append(
&builder.tokens,
SemanticToken {
@@ -212,13 +195,7 @@ write_semantic_token :: proc(
type: SemanticTokenTypes,
modifiers: SemanticTokenModifiers = {},
) {
- write_semantic_at_pos(
- builder,
- token.pos.offset,
- len(token.text),
- type,
- modifiers,
- )
+ write_semantic_at_pos(builder, token.pos.offset, len(token.text), type, modifiers)
}
visit_nodes :: proc(array: []$T/^ast.Node, builder: ^SemanticTokenBuilder) {
@@ -411,14 +388,10 @@ visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder) {
}
}
-visit_value_decl :: proc(
- value_decl: ast.Value_Decl,
- builder: ^SemanticTokenBuilder,
-) {
+visit_value_decl :: proc(value_decl: ast.Value_Decl, builder: ^SemanticTokenBuilder) {
using ast
- modifiers: SemanticTokenModifiers =
- value_decl.is_mutable ? {} : {.ReadOnly}
+ modifiers: SemanticTokenModifiers = value_decl.is_mutable ? {} : {.ReadOnly}
for name in value_decl.names {
ident := name.derived.(^Ident) or_continue
@@ -459,10 +432,7 @@ visit_proc_type :: proc(node: ^ast.Proc_Type, builder: ^SemanticTokenBuilder) {
}
}
-visit_enum_fields :: proc(
- node: ast.Enum_Type,
- builder: ^SemanticTokenBuilder,
-) {
+visit_enum_fields :: proc(node: ast.Enum_Type, builder: ^SemanticTokenBuilder) {
using ast
if node.fields == nil {
@@ -481,10 +451,7 @@ visit_enum_fields :: proc(
}
}
-visit_struct_fields :: proc(
- node: ast.Struct_Type,
- builder: ^SemanticTokenBuilder,
-) {
+visit_struct_fields :: proc(node: ast.Struct_Type, builder: ^SemanticTokenBuilder) {
if node.fields == nil {
return
}
@@ -500,10 +467,7 @@ visit_struct_fields :: proc(
}
}
-visit_bit_field_fields :: proc(
- node: ast.Bit_Field_Type,
- builder: ^SemanticTokenBuilder,
-) {
+visit_bit_field_fields :: proc(node: ast.Bit_Field_Type, builder: ^SemanticTokenBuilder) {
if node.fields == nil {
return
}
@@ -518,10 +482,7 @@ visit_bit_field_fields :: proc(
}
}
-visit_import_decl :: proc(
- decl: ^ast.Import_Decl,
- builder: ^SemanticTokenBuilder,
-) {
+visit_import_decl :: proc(decl: ^ast.Import_Decl, builder: ^SemanticTokenBuilder) {
/*
hightlight the namespace in the import declaration
@@ -544,9 +505,7 @@ visit_import_decl :: proc(
for {
if pos > 1 {
- ch, w := utf8.decode_last_rune_in_string(
- decl.relpath.text[:pos],
- )
+ ch, w := utf8.decode_last_rune_in_string(decl.relpath.text[:pos])
switch ch {
case ':', '/': // break
@@ -559,12 +518,7 @@ visit_import_decl :: proc(
break
}
- write_semantic_at_pos(
- builder,
- decl.relpath.pos.offset + pos,
- end - pos,
- .Namespace,
- )
+ write_semantic_at_pos(builder, decl.relpath.pos.offset + pos, end - pos, .Namespace)
}
}
@@ -593,9 +547,7 @@ visit_ident :: proc(
#partial switch symbol.type {
case .Variable, .Constant, .Function:
#partial switch _ in symbol.value {
- case SymbolProcedureValue,
- SymbolProcedureGroupValue,
- SymbolAggregateValue:
+ case SymbolProcedureValue, SymbolProcedureGroupValue, SymbolAggregateValue:
write_semantic_node(builder, ident, .Function, modifiers)
case:
write_semantic_node(builder, ident, .Variable, modifiers)
diff --git a/src/server/signature.odin b/src/server/signature.odin
index fe1c784..6034b4d 100644
--- a/src/server/signature.odin
+++ b/src/server/signature.odin
@@ -98,12 +98,7 @@ seperate_proc_field_arguments :: proc(procedure: ^Symbol) {
}
for name in arg.names {
- field: ^ast.Field = new_type(
- ast.Field,
- arg.pos,
- arg.end,
- context.temp_allocator,
- )
+ field: ^ast.Field = new_type(ast.Field, arg.pos, arg.end, context.temp_allocator)
field.names = make([]^ast.Expr, 1, context.temp_allocator)
field.names[0] = name
field.type = arg.type
@@ -115,13 +110,7 @@ seperate_proc_field_arguments :: proc(procedure: ^Symbol) {
}
}
-get_signature_information :: proc(
- document: ^Document,
- position: common.Position,
-) -> (
- SignatureHelp,
- bool,
-) {
+get_signature_information :: proc(document: ^Document, position: common.Position) -> (SignatureHelp, bool) {
signature_help: SignatureHelp
ast_context := make_ast_context(
@@ -132,11 +121,7 @@ get_signature_information :: proc(
document.fullpath,
)
- position_context, ok := get_document_position_context(
- document,
- position,
- .SignatureHelp,
- )
+ position_context, ok := get_document_position_context(document, position, .SignatureHelp)
if !ok {
return signature_help, true
@@ -150,12 +135,7 @@ get_signature_information :: proc(
get_globals(document.ast, &ast_context)
if position_context.function != nil {
- get_locals(
- document.ast,
- position_context.function,
- &ast_context,
- &position_context,
- )
+ get_locals(document.ast, position_context.function, &ast_context, &position_context)
}
for comma, i in position_context.call_commas {
@@ -179,26 +159,15 @@ get_signature_information :: proc(
seperate_proc_field_arguments(&call)
- signature_information := make(
- [dynamic]SignatureInformation,
- context.temp_allocator,
- )
+ signature_information := make([dynamic]SignatureInformation, context.temp_allocator)
if value, ok := call.value.(SymbolProcedureValue); ok {
- parameters := make(
- []ParameterInformation,
- len(value.arg_types),
- context.temp_allocator,
- )
+ parameters := make([]ParameterInformation, len(value.arg_types), context.temp_allocator)
for arg, i in value.arg_types {
if arg.type != nil {
- if _, is_ellipsis := arg.type.derived.(^ast.Ellipsis);
- is_ellipsis {
- signature_help.activeParameter = min(
- i,
- signature_help.activeParameter,
- )
+ if _, is_ellipsis := arg.type.derived.(^ast.Ellipsis); is_ellipsis {
+ signature_help.activeParameter = min(i, signature_help.activeParameter)
}
}
@@ -208,11 +177,7 @@ get_signature_information :: proc(
build_procedure_symbol_signature(&call)
info := SignatureInformation {
- label = concatenate_symbol_information(
- &ast_context,
- call,
- false,
- ),
+ label = concatenate_symbol_information(&ast_context, call, false),
documentation = call.doc,
parameters = parameters,
}
@@ -223,20 +188,12 @@ get_signature_information :: proc(
symbol := symbol
if value, ok := symbol.value.(SymbolProcedureValue); ok {
- parameters := make(
- []ParameterInformation,
- len(value.arg_types),
- context.temp_allocator,
- )
+ parameters := make([]ParameterInformation, len(value.arg_types), context.temp_allocator)
for arg, i in value.arg_types {
if arg.type != nil {
- if _, is_ellipsis := arg.type.derived.(^ast.Ellipsis);
- is_ellipsis {
- signature_help.activeParameter = min(
- i,
- signature_help.activeParameter,
- )
+ if _, is_ellipsis := arg.type.derived.(^ast.Ellipsis); is_ellipsis {
+ signature_help.activeParameter = min(i, signature_help.activeParameter)
}
}
@@ -246,11 +203,7 @@ get_signature_information :: proc(
build_procedure_symbol_signature(&symbol)
info := SignatureInformation {
- label = concatenate_symbol_information(
- &ast_context,
- symbol,
- false,
- ),
+ label = concatenate_symbol_information(&ast_context, symbol, false),
documentation = symbol.doc,
}
diff --git a/src/server/snippets.odin b/src/server/snippets.odin
index cd790a9..1ab01a1 100644
--- a/src/server/snippets.odin
+++ b/src/server/snippets.odin
@@ -7,41 +7,13 @@ Snippet_Info :: struct {
}
snippets: map[string]Snippet_Info = {
- "ff" = {
- insert = "fmt.printf(\"${1:text}\", ${0:args})",
- packages = []string{"fmt"},
- detail = "printf",
- },
- "fl" = {
- insert = "fmt.println(\"${1:text}\")",
- packages = []string{"fmt"},
- detail = "println",
- },
- "if" = {
- insert = "if ${1} {\n\t${0}\n}",
- packages = {},
- detail = "if statement",
- },
- "forr" = {
- insert = "for ${2:elem} in ${1:range} {\n\t${0}\n}",
- packages = {},
- detail = "for range",
- },
- "fori" = {
- insert = "for ${1} := ${2}; ${1} < ${3}; ${1}+=1 {\n\t${0}\n}",
- packages = {},
- detail = "for index",
- },
- "main" = {
- insert = "main :: proc() {\n\t${0}\n}",
- packages = {},
- detail = "main entrypoint",
- },
- "proc" = {
- insert = "${1:name} :: proc(${2:params}) {\n\t${0}\n}",
- packages = {},
- detail = "procedure declaration",
- },
+ "ff" = {insert = "fmt.printf(\"${1:text}\", ${0:args})", packages = []string{"fmt"}, detail = "printf"},
+ "fl" = {insert = "fmt.println(\"${1:text}\")", packages = []string{"fmt"}, detail = "println"},
+ "if" = {insert = "if ${1} {\n\t${0}\n}", packages = {}, detail = "if statement"},
+ "forr" = {insert = "for ${2:elem} in ${1:range} {\n\t${0}\n}", packages = {}, detail = "for range"},
+ "fori" = {insert = "for ${1} := ${2}; ${1} < ${3}; ${1}+=1 {\n\t${0}\n}", packages = {}, detail = "for index"},
+ "main" = {insert = "main :: proc() {\n\t${0}\n}", packages = {}, detail = "main entrypoint"},
+ "proc" = {insert = "${1:name} :: proc(${2:params}) {\n\t${0}\n}", packages = {}, detail = "procedure declaration"},
"st" = {
insert = "${1:name} :: struct {\n\t${2:field_name}: ${3:field_type},${0}\n}",
packages = {},
diff --git a/src/server/symbol.odin b/src/server/symbol.odin
index f34e4b6..0e67b33 100644
--- a/src/server/symbol.odin
+++ b/src/server/symbol.odin
@@ -180,10 +180,7 @@ SymbolType :: enum {
Unresolved = 1, //Use text if not being able to resolve it.
}
-new_clone_symbol :: proc(
- data: Symbol,
- allocator := context.allocator,
-) -> ^Symbol {
+new_clone_symbol :: proc(data: Symbol, allocator := context.allocator) -> ^Symbol {
new_symbol := new(Symbol, allocator)
new_symbol^ = data
new_symbol.value = data.value
@@ -255,9 +252,7 @@ free_symbol :: proc(symbol: Symbol, allocator: mem.Allocator) {
}
}
-symbol_type_to_completion_kind :: proc(
- type: SymbolType,
-) -> CompletionItemKind {
+symbol_type_to_completion_kind :: proc(type: SymbolType) -> CompletionItemKind {
switch type {
case .Function:
return .Function
@@ -311,11 +306,7 @@ symbol_kind_to_type :: proc(type: SymbolType) -> SymbolKind {
}
}
-symbol_to_expr :: proc(
- symbol: Symbol,
- file: string,
- allocator := context.temp_allocator,
-) -> ^ast.Expr {
+symbol_to_expr :: proc(symbol: Symbol, file: string, allocator := context.temp_allocator) -> ^ast.Expr {
pos := tokenizer.Pos {
file = file,
diff --git a/src/server/unmarshal.odin b/src/server/unmarshal.odin
index dea7d15..d7efe63 100644
--- a/src/server/unmarshal.odin
+++ b/src/server/unmarshal.odin
@@ -11,11 +11,7 @@ import "core:strings"
Right now union handling is type specific so you can only have one struct type, int type, etc.
*/
-unmarshal :: proc(
- json_value: json.Value,
- v: any,
- allocator: mem.Allocator,
-) -> json.Marshal_Error {
+unmarshal :: proc(json_value: json.Value, v: any, allocator: mem.Allocator) -> json.Marshal_Error {
using runtime
@@ -34,18 +30,11 @@ unmarshal :: proc(
#partial switch variant in type_info.variant {
case Type_Info_Struct:
for field, i in variant.names[0:variant.field_count] {
- a := any {
- rawptr(uintptr(v.data) + uintptr(variant.offsets[i])),
- variant.types[i].id,
- }
+ a := any{rawptr(uintptr(v.data) + uintptr(variant.offsets[i])), variant.types[i].id}
//TEMP most likely have to rewrite the entire unmarshal using tags instead, because i sometimes have to support names like 'context', which can't be written like that
if field[len(field) - 1] == '_' {
- if ret := unmarshal(
- j[field[:len(field) - 1]],
- a,
- allocator,
- ); ret != nil {
+ if ret := unmarshal(j[field[:len(field) - 1]], a, allocator); ret != nil {
return ret
}
} else {
@@ -63,11 +52,7 @@ unmarshal :: proc(
not_optional := 1
- mem.copy(
- cast(rawptr)tag_ptr,
- &not_optional,
- size_of(variant.tag_type),
- )
+ mem.copy(cast(rawptr)tag_ptr, &not_optional, size_of(variant.tag_type))
id := variant.variants[0].id
@@ -78,12 +63,7 @@ unmarshal :: proc(
case Type_Info_Dynamic_Array:
array := (^mem.Raw_Dynamic_Array)(v.data)
if array.data == nil {
- array.data =
- mem.alloc(
- len(j) * variant.elem_size,
- variant.elem.align,
- allocator,
- ) or_else panic("OOM")
+ array.data = mem.alloc(len(j) * variant.elem_size, variant.elem.align, allocator) or_else panic("OOM")
array.len = len(j)
array.cap = len(j)
array.allocator = allocator
@@ -92,12 +72,7 @@ unmarshal :: proc(
}
for i in 0 ..< array.len {
- a := any {
- rawptr(
- uintptr(array.data) + uintptr(variant.elem_size * i),
- ),
- variant.elem.id,
- }
+ a := any{rawptr(uintptr(array.data) + uintptr(variant.elem_size * i)), variant.elem.id}
if ret := unmarshal(j[i], a, allocator); ret != nil {
return ret
@@ -177,11 +152,7 @@ unmarshal :: proc(
not_optional := 1
- mem.copy(
- cast(rawptr)tag_ptr,
- &not_optional,
- size_of(variant.tag_type),
- )
+ mem.copy(cast(rawptr)tag_ptr, &not_optional, size_of(variant.tag_type))
id := variant.variants[0].id