diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-04-09 22:19:08 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-04-09 22:19:08 +0200 |
| commit | 144d2b3e36d3dca77b8531dc0136ba084b530d54 (patch) | |
| tree | a06cfd4d76baa4cd64f77379e7ee9920e93371ae | |
| parent | 4d0d079b4b79ce5730d8c2ee8694652a3f73049f (diff) | |
Merge packages
| -rw-r--r-- | src/main.odin | 3 | ||||
| -rw-r--r-- | src/server/analysis.odin (renamed from src/analysis/analysis.odin) | 367 | ||||
| -rw-r--r-- | src/server/build.odin (renamed from src/index/build.odin) | 2 | ||||
| -rw-r--r-- | src/server/caches.odin | 8 | ||||
| -rw-r--r-- | src/server/clone.odin (renamed from src/index/clone.odin) | 2 | ||||
| -rw-r--r-- | src/server/collector.odin (renamed from src/index/collector.odin) | 6 | ||||
| -rw-r--r-- | src/server/completion.odin | 89 | ||||
| -rw-r--r-- | src/server/definition.odin | 15 | ||||
| -rw-r--r-- | src/server/document_links.odin | 4 | ||||
| -rw-r--r-- | src/server/document_symbols.odin | 5 | ||||
| -rw-r--r-- | src/server/hover.odin | 16 | ||||
| -rw-r--r-- | src/server/indexer.odin (renamed from src/index/indexer.odin) | 2 | ||||
| -rw-r--r-- | src/server/inlay_hints.odin | 8 | ||||
| -rw-r--r-- | src/server/lens.odin | 5 | ||||
| -rw-r--r-- | src/server/memory_index.odin (renamed from src/index/memory_index.odin) | 2 | ||||
| -rw-r--r-- | src/server/references.odin (renamed from src/index/references.odin) | 12 | ||||
| -rw-r--r-- | src/server/rename.odin | 3 | ||||
| -rw-r--r-- | src/server/requests.odin | 27 | ||||
| -rw-r--r-- | src/server/semantic_tokens.odin | 61 | ||||
| -rw-r--r-- | src/server/signature.odin | 24 | ||||
| -rw-r--r-- | src/server/symbol.odin (renamed from src/index/symbol.odin) | 2 |
21 files changed, 303 insertions, 360 deletions
diff --git a/src/main.odin b/src/main.odin index 567fb9c..5bfb880 100644 --- a/src/main.odin +++ b/src/main.odin @@ -14,7 +14,6 @@ import "core:sync" import "core:intrinsics" -import "shared:index" import "shared:server" import "shared:common" @@ -81,7 +80,7 @@ run :: proc(reader: ^server.Reader, writer: ^server.Writer) { server.document_storage_shutdown() - index.free_static_index() + server.free_static_index() } end :: proc() { diff --git a/src/analysis/analysis.odin b/src/server/analysis.odin index 6f0a288..3ef9733 100644 --- a/src/analysis/analysis.odin +++ b/src/server/analysis.odin @@ -1,4 +1,4 @@ -package analysis +package server import "core:odin/parser" import "core:odin/ast" @@ -16,7 +16,6 @@ import "core:unicode/utf8" import "core:reflect" import "shared:common" -import "shared:index" DocumentPositionContextHint :: enum { Completion, @@ -284,7 +283,7 @@ resolve_poly_spec_node :: proc(ast_context: ^AstContext, call_node: ^ast.Node, s } } -resolve_type_comp_literal :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, current_symbol: index.Symbol, current_comp_lit: ^ast.Comp_Lit) -> (index.Symbol, ^ast.Comp_Lit, bool) { +resolve_type_comp_literal :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, current_symbol: Symbol, current_comp_lit: ^ast.Comp_Lit) -> (Symbol, ^ast.Comp_Lit, bool) { if position_context.comp_lit == current_comp_lit { return current_symbol, current_comp_lit, true } else if current_comp_lit == nil { @@ -311,12 +310,12 @@ resolve_type_comp_literal :: proc(ast_context: ^AstContext, position_context: ^D if field_value, ok := elem.derived.(^ast.Field_Value); ok { //named if comp_lit, ok := field_value.value.derived.(^ast.Comp_Lit); ok { - if s, ok := current_symbol.value.(index.SymbolStructValue); 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 { //Stop at bitset, because we don't want to enter a comp_lit of a bitset - if _, ok := symbol.value.(index.SymbolBitSetValue); ok { + if _, ok := symbol.value.(SymbolBitSetValue); ok { return current_symbol, current_comp_lit, true } return resolve_type_comp_literal(ast_context, position_context, symbol, cast(^ast.Comp_Lit)field_value.value) @@ -326,7 +325,7 @@ resolve_type_comp_literal :: proc(ast_context: ^AstContext, position_context: ^D } } } else { //indexed - if s, ok := current_symbol.value.(index.SymbolStructValue); ok { + if s, ok := current_symbol.value.(SymbolStructValue); ok { if len(s.types) <= element_index { return {}, {}, false @@ -334,7 +333,7 @@ resolve_type_comp_literal :: proc(ast_context: ^AstContext, position_context: ^D 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.(index.SymbolBitSetValue); ok { + if _, ok := symbol.value.(SymbolBitSetValue); ok { return current_symbol, current_comp_lit, true } return resolve_type_comp_literal(ast_context, position_context, symbol, cast(^ast.Comp_Lit)field_value.value) @@ -351,9 +350,7 @@ resolve_generic_function :: proc { resolve_generic_function_symbol, } -resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast.Field, results: []^ast.Field) -> (index.Symbol, bool) { - using ast - +resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast.Field, results: []^ast.Field) -> (Symbol, bool) { if params == nil { return {}, false } @@ -367,7 +364,7 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast } call_expr := ast_context.call - poly_map := make(map[string]^Expr, 0, context.temp_allocator) + poly_map := make(map[string]^ast.Expr, 0, context.temp_allocator) i := 0 count_required_params := 0 @@ -381,7 +378,7 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast break } - if poly, ok := name.derived.(^Poly_Type); ok { + if poly, ok := name.derived.(^ast.Poly_Type); ok { poly_map[poly.type.name] = call_expr.args[i] } @@ -389,7 +386,7 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast continue } - if type_id, ok := param.type.derived.(^Typeid_Type); ok { + if type_id, ok := param.type.derived.(^ast.Typeid_Type); ok { if type_id.specialization != nil && !common.node_equal(call_expr.args[i], type_id.specialization) { return {}, false } @@ -408,17 +405,17 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast function_name := "" function_range: common.Range - if ident, ok := call_expr.expr.derived.(^Ident); ok { + if ident, ok := call_expr.expr.derived.(^ast.Ident); ok { function_name = ident.name function_range = common.get_token_range(ident, ast_context.file.src) - } else if selector, ok := call_expr.expr.derived.(^Selector_Expr); ok { + } else if selector, ok := call_expr.expr.derived.(^ast.Selector_Expr); ok { function_name = selector.field.name function_range = common.get_token_range(selector, ast_context.file.src) } else { return {}, false } - symbol := index.Symbol { + symbol := Symbol { range = function_range, type = .Function, name = function_name, @@ -436,7 +433,7 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast if ok { if m, ok := poly_map[ident.name]; ok { - field := cast(^Field)index.clone_node(result, ast_context.allocator, nil) + field := cast(^ast.Field)clone_node(result, ast_context.allocator, nil) field.type = m append(&return_types, field) } else { @@ -455,7 +452,7 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast //check the name for poly 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 := cast(^Field)index.clone_node(param, ast_context.allocator, nil) + field := cast(^ast.Field)clone_node(param, ast_context.allocator, nil) field.type = m append(&argument_types, field) } @@ -464,7 +461,7 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast } } - symbol.value = index.SymbolProcedureValue { + symbol.value = SymbolProcedureValue { return_types = return_types[:], arg_types = argument_types[:], } @@ -472,29 +469,29 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast return symbol, true } -resolve_generic_function_ast :: proc(ast_context: ^AstContext, proc_lit: ast.Proc_Lit) -> (index.Symbol, bool) { +resolve_generic_function_ast :: proc(ast_context: ^AstContext, proc_lit: ast.Proc_Lit) -> (Symbol, bool) { using ast if proc_lit.type.params == nil { - return index.Symbol {}, false + return Symbol {}, false } if proc_lit.type.results == nil { - return index.Symbol {}, false + return Symbol {}, false } if ast_context.call == nil { - return index.Symbol {}, false + return Symbol {}, false } return resolve_generic_function_symbol(ast_context, proc_lit.type.params.list, proc_lit.type.results.list) } -is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.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.(index.SymbolUntypedValue); ok { - if basic, ok := b.value.(index.SymbolBasicValue); ok { + if untyped, ok := a.value.(SymbolUntypedValue); ok { + if basic, ok := b.value.(SymbolBasicValue); ok { switch untyped.type { case .Integer: switch basic.ident.name { @@ -543,7 +540,7 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol, flags } #partial switch b_value in b.value { - case index.SymbolBasicValue: + case SymbolBasicValue: if .Auto_Cast in flags { return true } else if .Any_Int in flags { @@ -556,15 +553,15 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol, flags } #partial switch a_value in a.value { - case index.SymbolBasicValue: + case SymbolBasicValue: return a.name == b.name && a.pkg == b.pkg - case index.SymbolStructValue, index.SymbolEnumValue, index.SymbolUnionValue, index.SymbolBitSetValue: + case SymbolStructValue, SymbolEnumValue, SymbolUnionValue, SymbolBitSetValue: return a.name == b.name && a.pkg == b.pkg - case index.SymbolSliceValue: - b_value := b.value.(index.SymbolSliceValue) + case SymbolSliceValue: + b_value := b.value.(SymbolSliceValue) - a_symbol: index.Symbol - b_symbol: index.Symbol + a_symbol: Symbol + b_symbol: Symbol ok: bool a_symbol, ok = resolve_type_expression(ast_context, a_value.expr) @@ -580,11 +577,11 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol, flags } return is_symbol_same_typed(ast_context, a_symbol, b_symbol) - case index.SymbolFixedArrayValue: - b_value := b.value.(index.SymbolFixedArrayValue) + case SymbolFixedArrayValue: + b_value := b.value.(SymbolFixedArrayValue) - a_symbol: index.Symbol - b_symbol: index.Symbol + a_symbol: Symbol + b_symbol: Symbol ok: bool a_symbol, ok = resolve_type_expression(ast_context, a_value.expr) @@ -600,11 +597,11 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol, flags } return is_symbol_same_typed(ast_context, a_symbol, b_symbol) - case index.SymbolDynamicArrayValue: - b_value := b.value.(index.SymbolDynamicArrayValue) + case SymbolDynamicArrayValue: + b_value := b.value.(SymbolDynamicArrayValue) - a_symbol: index.Symbol - b_symbol: index.Symbol + a_symbol: Symbol + b_symbol: Symbol ok: bool a_symbol, ok = resolve_type_expression(ast_context, a_value.expr) @@ -620,13 +617,13 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol, flags } return is_symbol_same_typed(ast_context, a_symbol, b_symbol) - case index.SymbolMapValue: - b_value := b.value.(index.SymbolMapValue) + case SymbolMapValue: + b_value := b.value.(SymbolMapValue) - a_key_symbol: index.Symbol - b_key_symbol: index.Symbol - a_value_symbol: index.Symbol - b_value_symbol: index.Symbol + a_key_symbol: Symbol + b_key_symbol: Symbol + a_value_symbol: Symbol + b_value_symbol: Symbol ok: bool a_key_symbol, ok = resolve_type_expression(ast_context, a_value.key) @@ -676,12 +673,12 @@ get_field_list_name_index :: proc(name: string, field_list: []^ast.Field) -> (in /* 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) -> (index.Symbol, bool) { +resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Group) -> (Symbol, bool) { using ast call_expr := ast_context.call - candidates := make([dynamic]index.Symbol, context.temp_allocator) + candidates := make([dynamic]Symbol, context.temp_allocator) for arg_expr in group.args { @@ -692,7 +689,7 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou break next_fn } - if procedure, ok := f.value.(index.SymbolProcedureValue); ok { + if procedure, ok := f.value.(SymbolProcedureValue); ok { count_required_params := 0 @@ -710,8 +707,8 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou ast_context.use_locals = true - call_symbol: index.Symbol - arg_symbol: index.Symbol + call_symbol: Symbol + arg_symbol: Symbol ok: bool i := i @@ -739,7 +736,7 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou break next_fn } - if p, ok := call_symbol.value.(index.SymbolProcedureValue); ok { + if p, ok := call_symbol.value.(SymbolProcedureValue); ok { if len(p.return_types) != 1 { break next_fn } @@ -769,11 +766,11 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou } if len(candidates) > 1 { - return index.Symbol { + return Symbol { type = candidates[0].type, name = candidates[0].name, pkg = candidates[0].pkg, - value = index.SymbolAggregateValue { + value = SymbolAggregateValue { symbols = candidates[:], }, }, true @@ -781,15 +778,15 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou return candidates[0], true } - return index.Symbol {}, false + return Symbol {}, false } -resolve_basic_lit :: proc(ast_context: ^AstContext, basic_lit: ast.Basic_Lit) -> (index.Symbol, bool) { - symbol := index.Symbol { +resolve_basic_lit :: proc(ast_context: ^AstContext, basic_lit: ast.Basic_Lit) -> (Symbol, bool) { + symbol := Symbol { type = .Constant, } - value: index.SymbolUntypedValue + value: SymbolUntypedValue if v, ok := strconv.parse_int(basic_lit.tok.text); ok { value.type = .Integer @@ -807,10 +804,10 @@ resolve_basic_lit :: proc(ast_context: ^AstContext, basic_lit: ast.Basic_Lit) -> return symbol, true } -resolve_basic_directive :: proc(ast_context: ^AstContext, directive: ast.Basic_Directive, a := #caller_location) -> (index.Symbol, bool) { +resolve_basic_directive :: proc(ast_context: ^AstContext, directive: ast.Basic_Directive, a := #caller_location) -> (Symbol, bool) { switch directive.name { case "caller_location": - ident := index.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" ast_context.current_package = ast_context.document_package return resolve_type_identifier(ast_context, ident^) @@ -820,7 +817,7 @@ resolve_basic_directive :: proc(ast_context: ^AstContext, directive: ast.Basic_D } -resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (index.Symbol, bool) { +resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (Symbol, bool) { if node == nil { return {}, false } @@ -898,14 +895,14 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i case ^Ellipsis: return resolve_type_expression(ast_context, v.expr) case ^Implicit: - ident := index.new_type(Ident, v.node.pos, v.node.end, context.temp_allocator) + ident := new_type(Ident, v.node.pos, v.node.end, context.temp_allocator) ident.name = v.tok.text return resolve_type_identifier(ast_context, ident^) case ^Type_Assertion: if unary, ok := v.type.derived.(^ast.Unary_Expr); ok { if unary.op.kind == .Question { if symbol, ok := resolve_type_expression(ast_context, v.expr); ok { - if union_value, ok := symbol.value.(index.SymbolUnionValue); ok { + if union_value, ok := symbol.value.(SymbolUnionValue); ok { if len(union_value.types) != 1 { return {}, false } @@ -937,16 +934,16 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i return {}, false } - symbol: index.Symbol + symbol: Symbol #partial switch v2 in indexed.value { - case index.SymbolDynamicArrayValue: + case SymbolDynamicArrayValue: symbol, ok = resolve_type_expression(ast_context, v2.expr) - case index.SymbolSliceValue: + case SymbolSliceValue: symbol, ok = resolve_type_expression(ast_context, v2.expr) - case index.SymbolFixedArrayValue: + case SymbolFixedArrayValue: symbol, ok = resolve_type_expression(ast_context, v2.expr) - case index.SymbolMapValue: + case SymbolMapValue: symbol, ok = resolve_type_expression(ast_context, v2.value) } @@ -957,7 +954,7 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i ast_context.call = cast(^Call_Expr)node return resolve_type_expression(ast_context, v.expr) case ^Implicit_Selector_Expr: - return index.Symbol {}, false + return Symbol {}, false case ^Selector_Call_Expr: return resolve_type_expression(ast_context, v.expr) case ^Selector_Expr: @@ -965,7 +962,7 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i ast_context.use_locals = false #partial switch s in selector.value { - case index.SymbolFixedArrayValue: + case SymbolFixedArrayValue: components_count := 0 for c in v.field.name { if c == 'x' || c == 'y' || c == 'z' || c == 'w' || @@ -988,7 +985,7 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i symbol.type = .Variable return symbol, ok } else { - value := index.SymbolFixedArrayValue { + value := SymbolFixedArrayValue { expr = s.expr, len = make_int_basic_value(ast_context, components_count), } @@ -996,14 +993,14 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i selector.type = .Variable return selector, true } - case index.SymbolProcedureValue: + case SymbolProcedureValue: if len(s.return_types) == 1 { - selector_expr := index.new_type(ast.Selector_Expr, s.return_types[0].node.pos, s.return_types[0].node.end, context.temp_allocator) + selector_expr := new_type(ast.Selector_Expr, s.return_types[0].node.pos, s.return_types[0].node.end, context.temp_allocator) selector_expr.expr = s.return_types[0].type selector_expr.field = v.field return resolve_type_expression(ast_context, selector_expr) } - case index.SymbolStructValue: + case SymbolStructValue: if selector.pkg != "" { ast_context.current_package = selector.pkg } else { @@ -1018,17 +1015,17 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i return symbol, ok } } - case index.SymbolPackageValue: + case SymbolPackageValue: ast_context.current_package = selector.pkg if v.field != nil { - return resolve_symbol_return(ast_context, index.lookup(v.field.name, selector.pkg)) + return resolve_symbol_return(ast_context, lookup(v.field.name, selector.pkg)) } else { - return index.Symbol {}, false + return Symbol {}, false } } } else { - return index.Symbol {}, false + return Symbol {}, false } case: log.warnf("default node kind, resolve_type_expression: %T", v) @@ -1037,7 +1034,7 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i } } - return index.Symbol {}, false + return Symbol {}, false } store_local :: proc(ast_context: ^AstContext, expr: ^ast.Expr, offset: int, name: string, id := 0) { @@ -1110,7 +1107,7 @@ get_local_offset :: proc(ast_context: ^AstContext, offset: int, name: string) -> return -1 } -resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (index.Symbol, bool) { +resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (Symbol, bool) { using ast if ast_context.recursion_counter > 15 { @@ -1137,10 +1134,10 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i if _, ok := ast_context.parameters[node.name]; ok { for imp in ast_context.imports { if strings.compare(imp.base, node.name) == 0 { - symbol := index.Symbol { + symbol := Symbol { type = .Package, pkg = imp.name, - value = index.SymbolPackageValue {}, + value = SymbolPackageValue {}, } return symbol, true @@ -1159,7 +1156,7 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i } } - return_symbol: index.Symbol + return_symbol: Symbol ok: bool #partial switch v in local.derived { @@ -1223,7 +1220,7 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i } } - return_symbol: index.Symbol + return_symbol: Symbol ok: bool #partial switch v in global.expr.derived { @@ -1278,36 +1275,36 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i return return_symbol, ok } else if node.name == "context" { - for built in index.indexer.builtin_packages { - if symbol, ok := index.lookup("Context", built); ok { + for built in indexer.builtin_packages { + if symbol, ok := lookup("Context", built); ok { symbol.type = .Variable return symbol, ok } } } else if v, ok := common.keyword_map[node.name]; ok { //keywords - ident := index.new_type(Ident, node.pos, node.end, ast_context.allocator) + ident := new_type(Ident, node.pos, node.end, ast_context.allocator) ident.name = node.name - symbol: index.Symbol + symbol: Symbol switch ident.name { case "true", "false": - symbol = index.Symbol { + symbol = Symbol { type = .Keyword, signature = node.name, pkg = ast_context.current_package, - value = index.SymbolUntypedValue { + value = SymbolUntypedValue { type = .Bool, }, } case: - symbol = index.Symbol { + symbol = Symbol { type = .Keyword, signature = node.name, name = ident.name, pkg = ast_context.current_package, - value = index.SymbolBasicValue { + value = SymbolBasicValue { ident = ident, }, } @@ -1317,10 +1314,10 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i } else { //right now we replace the package ident with the absolute directory name, so it should have '/' which is not a valid ident character if strings.contains(node.name, "/") { - symbol := index.Symbol { + symbol := Symbol { type = .Package, pkg = node.name, - value = index.SymbolPackageValue {}, + value = SymbolPackageValue {}, } return symbol, true @@ -1328,10 +1325,10 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i //part of the ast so we check the imports of the document for imp in ast_context.imports { if strings.compare(imp.base, node.name) == 0 { - symbol := index.Symbol { + symbol := Symbol { type = .Package, pkg = imp.name, - value = index.SymbolPackageValue {}, + value = SymbolPackageValue {}, } return symbol, true @@ -1340,17 +1337,17 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i } //last option is to check the index - if symbol, ok := index.lookup(node.name, ast_context.current_package); ok { + if symbol, ok := lookup(node.name, ast_context.current_package); ok { return resolve_symbol_return(ast_context, symbol) } //If we are resolving a symbol that is in the document package, then we'll check the builtin packages. if ast_context.current_package == ast_context.document_package { - if symbol, ok := index.lookup(node.name, "$builtin"); ok { + if symbol, ok := lookup(node.name, "$builtin"); ok { return resolve_symbol_return(ast_context, symbol) } - for built in index.indexer.builtin_packages { - if symbol, ok := index.lookup(node.name, built); ok { + for built in indexer.builtin_packages { + if symbol, ok := lookup(node.name, built); ok { return resolve_symbol_return(ast_context, symbol) } } @@ -1360,7 +1357,7 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i //TODO(Daniel, make into a map, not really required for performance but looks nicer) for imp in ast_context.imports { if strings.compare(imp.base, u) == 0 { - if symbol, ok := index.lookup(node.name, imp.name); ok { + if symbol, ok := lookup(node.name, imp.name); ok { return resolve_symbol_return(ast_context, symbol) } } @@ -1368,7 +1365,7 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i } } - return index.Symbol {}, false + return Symbol {}, false } resolve_ident_is_package :: proc(ast_context: ^AstContext, node: ast.Ident) -> bool { @@ -1386,7 +1383,7 @@ resolve_ident_is_package :: proc(ast_context: ^AstContext, node: ast.Ident) -> b return false } -expand_struct_usings :: proc(ast_context: ^AstContext, symbol: index.Symbol, value: index.SymbolStructValue) -> index.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) @@ -1407,7 +1404,7 @@ expand_struct_usings :: proc(ast_context: ^AstContext, symbol: index.Symbol, val } if s, ok := resolve_type_expression(ast_context, field_expr); ok { - if struct_value, ok := s.value.(index.SymbolStructValue); ok { + if struct_value, ok := s.value.(SymbolStructValue); ok { for name in struct_value.names { append(&names, name) } @@ -1425,7 +1422,7 @@ expand_struct_usings :: proc(ast_context: ^AstContext, symbol: index.Symbol, val } } -resolve_symbol_return :: proc(ast_context: ^AstContext, symbol: index.Symbol, ok := true) -> (index.Symbol, bool) { +resolve_symbol_return :: proc(ast_context: ^AstContext, symbol: Symbol, ok := true) -> (Symbol, bool) { if !ok { return symbol, ok } @@ -1437,13 +1434,13 @@ resolve_symbol_return :: proc(ast_context: ^AstContext, symbol: index.Symbol, ok } #partial switch v in &symbol.value { - case index.SymbolProcedureGroupValue: + case SymbolProcedureGroupValue: if symbol, ok := resolve_function_overload(ast_context, v.group.derived.(^ast.Proc_Group)^); ok { return symbol, true } else { return symbol, false } - case index.SymbolProcedureValue: + case SymbolProcedureValue: if v.generic { if resolved_symbol, ok := resolve_generic_function(ast_context, v.arg_types, v.return_types); ok { return resolved_symbol, ok @@ -1453,7 +1450,7 @@ resolve_symbol_return :: proc(ast_context: ^AstContext, symbol: index.Symbol, ok } else { return symbol, true } - case index.SymbolUnionValue: + case SymbolUnionValue: if v.poly != nil { //Todo(daniel): Maybe change the function to return a new symbol instead of referencing it. //resolving the poly union means changing the type, so we do a copy of it. @@ -1463,7 +1460,7 @@ resolve_symbol_return :: proc(ast_context: ^AstContext, symbol: index.Symbol, ok resolve_poly_union(ast_context, v.poly, &symbol) } return symbol, ok - case index.SymbolStructValue: + case SymbolStructValue: if v.poly != nil { //Todo(daniel): Maybe change the function to return a new symbol instead of referencing it. //resolving the struct union means changing the type, so we do a copy of it. @@ -1481,7 +1478,7 @@ resolve_symbol_return :: proc(ast_context: ^AstContext, symbol: index.Symbol, ok } else { return symbol, true } - case index.SymbolGenericValue: + case SymbolGenericValue: ret, ok := resolve_type_expression(ast_context, v.expr) return ret, ok } @@ -1489,9 +1486,7 @@ resolve_symbol_return :: proc(ast_context: ^AstContext, symbol: index.Symbol, ok return symbol, true } -resolve_unresolved_symbol :: proc(ast_context: ^AstContext, symbol: ^index.Symbol) { - using index - +resolve_unresolved_symbol :: proc(ast_context: ^AstContext, symbol: ^Symbol) { if symbol.type != .Unresolved { return } @@ -1509,7 +1504,7 @@ resolve_unresolved_symbol :: proc(ast_context: ^AstContext, symbol: ^index.Symbo symbol.type = .Enum case SymbolBitSetValue: symbol.type = .Enum - case index.SymbolGenericValue: + case SymbolGenericValue: ast_context.current_package = symbol.pkg if ret, ok := resolve_type_expression(ast_context, v.expr); ok { symbol.type = ret.type @@ -1518,8 +1513,8 @@ resolve_unresolved_symbol :: proc(ast_context: ^AstContext, symbol: ^index.Symbo } } -resolve_location_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (index.Symbol, bool) { - symbol: index.Symbol +resolve_location_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (Symbol, bool) { + symbol: Symbol if local := get_local(ast_context, node.pos.offset, node.name); local != nil { symbol.range = common.get_token_range(get_local(ast_context, node.pos.offset, node.name), ast_context.file.src) @@ -1529,14 +1524,14 @@ resolve_location_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) - return symbol, true } - if symbol, ok := index.lookup(node.name, ast_context.document_package); ok { + if symbol, ok := lookup(node.name, ast_context.document_package); ok { return symbol, ok } usings := get_using_packages(ast_context) for pkg in usings { - if symbol, ok := index.lookup(node.name, pkg); ok { + if symbol, ok := lookup(node.name, pkg); ok { return symbol, ok } } @@ -1544,7 +1539,7 @@ resolve_location_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) - return {}, false } -resolve_first_symbol_from_binary_expression :: proc(ast_context: ^AstContext, binary: ^ast.Binary_Expr) -> (index.Symbol, bool) { +resolve_first_symbol_from_binary_expression :: proc(ast_context: ^AstContext, binary: ^ast.Binary_Expr) -> (Symbol, bool) { //Fairly simple function to find the earliest identifier symbol in binary expression. if binary.left != nil { @@ -1590,25 +1585,25 @@ find_position_in_call_param :: proc(ast_context: ^AstContext, call: ast.Call_Exp } make_pointer_ast :: proc(ast_context: ^AstContext, elem: ^ast.Expr) -> ^ast.Pointer_Type { - pointer := index.new_type(ast.Pointer_Type, elem.pos, elem.end, ast_context.allocator) + 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) -> ^ast.Ident { - ident := index.new_type(ast.Ident, {}, {}, ast_context.allocator) + ident := new_type(ast.Ident, {}, {}, ast_context.allocator) ident.name = "bool" return ident } make_int_ast :: proc(ast_context: ^AstContext) -> ^ast.Ident { - ident := index.new_type(ast.Ident, {}, {}, ast_context.allocator) + ident := new_type(ast.Ident, {}, {}, ast_context.allocator) ident.name = "int" return ident } make_int_basic_value :: proc(ast_context: ^AstContext, n: int) -> ^ast.Basic_Lit { - basic := index.new_type(ast.Basic_Lit, {}, {}, ast_context.allocator) + basic := new_type(ast.Basic_Lit, {}, {}, ast_context.allocator) basic.tok.text = fmt.tprintf("%v", n) return basic } @@ -1646,8 +1641,8 @@ get_using_packages :: proc(ast_context: ^AstContext) -> []string { return usings } -make_symbol_procedure_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node, v: ast.Proc_Type, name: string) -> index.Symbol { - symbol := index.Symbol { +make_symbol_procedure_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node, v: ast.Proc_Type, name: string) -> Symbol { + symbol := Symbol { range = common.get_token_range(n^, ast_context.file.src), type = .Function, pkg = get_package_from_node(n^), @@ -1675,7 +1670,7 @@ make_symbol_procedure_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node, v } } - symbol.value = index.SymbolProcedureValue { + symbol.value = SymbolProcedureValue { return_types = return_types[:], arg_types = arg_types[:], } @@ -1683,8 +1678,8 @@ make_symbol_procedure_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node, v return symbol } -make_symbol_array_from_ast :: proc(ast_context: ^AstContext, v: ast.Array_Type, name: string) -> index.Symbol { - symbol := index.Symbol { +make_symbol_array_from_ast :: proc(ast_context: ^AstContext, v: ast.Array_Type, name: string) -> Symbol { + symbol := Symbol { range = common.get_token_range(v.node, ast_context.file.src), type = .Variable, pkg = get_package_from_node(v.node), @@ -1692,12 +1687,12 @@ make_symbol_array_from_ast :: proc(ast_context: ^AstContext, v: ast.Array_Type, } if v.len != nil { - symbol.value = index.SymbolFixedArrayValue { + symbol.value = SymbolFixedArrayValue { expr = v.elem, len = v.len, } } else { - symbol.value = index.SymbolSliceValue { + symbol.value = SymbolSliceValue { expr = v.elem, } } @@ -1705,30 +1700,30 @@ make_symbol_array_from_ast :: proc(ast_context: ^AstContext, v: ast.Array_Type, return symbol } -make_symbol_dynamic_array_from_ast :: proc(ast_context: ^AstContext, v: ast.Dynamic_Array_Type, name: string) -> index.Symbol { - symbol := index.Symbol { +make_symbol_dynamic_array_from_ast :: proc(ast_context: ^AstContext, v: ast.Dynamic_Array_Type, name: string) -> Symbol { + symbol := Symbol { range = common.get_token_range(v.node, ast_context.file.src), type = .Variable, pkg = get_package_from_node(v.node), name = name, } - symbol.value = index.SymbolDynamicArrayValue { + symbol.value = SymbolDynamicArrayValue { expr = v.elem, } return symbol } -make_symbol_map_from_ast :: proc(ast_context: ^AstContext, v: ast.Map_Type, name: string) -> index.Symbol { - symbol := index.Symbol { +make_symbol_map_from_ast :: proc(ast_context: ^AstContext, v: ast.Map_Type, name: string) -> Symbol { + symbol := Symbol { range = common.get_token_range(v.node, ast_context.file.src), type = .Variable, pkg = get_package_from_node(v.node), name = name, } - symbol.value = index.SymbolMapValue { + symbol.value = SymbolMapValue { key = v.key, value = v.value, } @@ -1736,22 +1731,22 @@ make_symbol_map_from_ast :: proc(ast_context: ^AstContext, v: ast.Map_Type, name return symbol } -make_symbol_basic_type_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node, v: ^ast.Ident) -> index.Symbol { - symbol := index.Symbol { +make_symbol_basic_type_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node, v: ^ast.Ident) -> Symbol { + symbol := Symbol { range = common.get_token_range(n^, ast_context.file.src), type = .Variable, pkg = get_package_from_node(n^), } - symbol.value = index.SymbolBasicValue { + symbol.value = SymbolBasicValue { ident = v, } return symbol } -make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type, ident: string, inlined := false) -> index.Symbol { - symbol := index.Symbol { +make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type, ident: string, inlined := false) -> Symbol { + symbol := Symbol { range = common.get_token_range(v, ast_context.file.src), type = .Union, pkg = get_package_from_node(v.node), @@ -1763,7 +1758,7 @@ make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type, symbol.name = "union" } - symbol.value = index.SymbolUnionValue { + symbol.value = SymbolUnionValue { types = v.variants, } @@ -1774,8 +1769,8 @@ make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type, return symbol } -make_symbol_enum_from_ast :: proc(ast_context: ^AstContext, v: ast.Enum_Type, ident: string, inlined := false) -> index.Symbol { - symbol := index.Symbol { +make_symbol_enum_from_ast :: proc(ast_context: ^AstContext, v: ast.Enum_Type, ident: string, inlined := false) -> Symbol { + symbol := Symbol { range = common.get_token_range(v, ast_context.file.src), type = .Enum, name = ident, @@ -1802,15 +1797,15 @@ make_symbol_enum_from_ast :: proc(ast_context: ^AstContext, v: ast.Enum_Type, id } } - symbol.value = index.SymbolEnumValue { + symbol.value = SymbolEnumValue { names = names[:], } return symbol } -make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Type, ident: string, inlined := false) -> index.Symbol { - symbol := index.Symbol { +make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Type, ident: string, inlined := false) -> Symbol { + symbol := Symbol { range = common.get_token_range(v, ast_context.file.src), type = .Enum, name = ident, @@ -1822,15 +1817,15 @@ make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Typ symbol.name = "bitset" } - symbol.value = index.SymbolBitSetValue { + symbol.value = SymbolBitSetValue { expr = v.elem, } return symbol } -make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type, ident: string, inlined := false) -> index.Symbol { - symbol := index.Symbol { +make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type, ident: string, inlined := false) -> Symbol { + symbol := Symbol { range = common.get_token_range(v, ast_context.file.src), type = .Struct, pkg = get_package_from_node(v.node), @@ -1850,7 +1845,7 @@ make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type for n in field.names { if identifier, ok := n.derived.(^ast.Ident); ok { append(&names, identifier.name) - append(&types, index.clone_type(field.type, ast_context.allocator, nil)) + append(&types, clone_type(field.type, ast_context.allocator, nil)) if .Using in field.flags { usings[identifier.name] = true @@ -1859,7 +1854,7 @@ make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type } } - symbol.value = index.SymbolStructValue { + symbol.value = SymbolStructValue { names = names[:], types = types[:], usings = usings, @@ -1871,18 +1866,18 @@ make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type //TODO change the expand to not double copy the array, but just pass the dynamic arrays if len(usings) > 0 { - symbol.value = expand_struct_usings(ast_context, symbol, symbol.value.(index.SymbolStructValue)) + symbol.value = expand_struct_usings(ast_context, symbol, symbol.value.(SymbolStructValue)) } return symbol } -resolve_poly_union :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_List, symbol: ^index.Symbol) { +resolve_poly_union :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_List, symbol: ^Symbol) { if ast_context.call == nil { return } - symbol_value := &symbol.value.(index.SymbolUnionValue) + symbol_value := &symbol.value.(SymbolUnionValue) if symbol_value == nil { return @@ -1937,12 +1932,12 @@ resolve_poly_union :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_Lis } } -resolve_poly_struct :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_List, symbol: ^index.Symbol) { +resolve_poly_struct :: proc(ast_context: ^AstContext, poly_params: ^ast.Field_List, symbol: ^Symbol) { if ast_context.call == nil { return } - symbol_value := &symbol.value.(index.SymbolStructValue) + symbol_value := &symbol.value.(SymbolStructValue) if symbol_value == nil { return @@ -2019,7 +2014,7 @@ get_generic_assignment :: proc(file: ast.File, value: ^ast.Expr, ast_context: ^A ast_context.call = cast(^ast.Call_Expr)value if symbol, ok := resolve_type_expression(ast_context, v.expr); ok { - if procedure, ok := symbol.value.(index.SymbolProcedureValue); ok { + if procedure, ok := symbol.value.(SymbolProcedureValue); ok { for ret in procedure.return_types { append(results, ret.type) } @@ -2161,15 +2156,15 @@ get_locals_using_stmt :: proc(stmt: ast.Using_Stmt, ast_context: ^AstContext) { for u in stmt.list { if symbol, ok := resolve_type_expression(ast_context, u); ok { #partial switch v in symbol.value { - case index.SymbolPackageValue: + case SymbolPackageValue: if ident, ok := u.derived.(^ast.Ident); ok { append(&ast_context.usings, ident.name) } - case index.SymbolStructValue: + case SymbolStructValue: for name, i in v.names { - selector := index.new_type(ast.Selector_Expr, v.types[i].pos, v.types[i].end, context.temp_allocator) + selector := new_type(ast.Selector_Expr, v.types[i].pos, v.types[i].end, context.temp_allocator) selector.expr = u - selector.field = index.new_type(ast.Ident, v.types[i].pos, v.types[i].end, context.temp_allocator) + selector.field = new_type(ast.Ident, v.types[i].pos, v.types[i].end, context.temp_allocator) selector.field.name = name store_local(ast_context, selector, 0, name, ast_context.local_id) ast_context.variables[name] = true @@ -2229,7 +2224,7 @@ get_locals_for_range_stmt :: proc(file: ast.File, stmt: ast.Range_Stmt, ast_cont if symbol, ok := resolve_type_expression(ast_context, stmt.expr); ok { #partial switch v in symbol.value { - case index.SymbolMapValue: + case SymbolMapValue: if len(stmt.vals) >= 1 { if ident, ok := stmt.vals[0].derived.(^Ident); ok { store_local(ast_context, v.key, ident.pos.offset, ident.name, ast_context.local_id) @@ -2244,7 +2239,7 @@ get_locals_for_range_stmt :: proc(file: ast.File, stmt: ast.Range_Stmt, ast_cont ast_context.in_package[ident.name] = symbol.pkg } } - case index.SymbolDynamicArrayValue: + case SymbolDynamicArrayValue: if len(stmt.vals) >= 1 { if ident, ok := stmt.vals[0].derived.(^Ident); ok { store_local(ast_context, v.expr, ident.pos.offset, ident.name, ast_context.local_id) @@ -2259,7 +2254,7 @@ get_locals_for_range_stmt :: proc(file: ast.File, stmt: ast.Range_Stmt, ast_cont ast_context.in_package[ident.name] = symbol.pkg } } - case index.SymbolFixedArrayValue: + case SymbolFixedArrayValue: if len(stmt.vals) >= 1 { if ident, ok := stmt.vals[0].derived.(^Ident); ok { store_local(ast_context, v.expr, ident.pos.offset, ident.name, ast_context.local_id) @@ -2275,7 +2270,7 @@ get_locals_for_range_stmt :: proc(file: ast.File, stmt: ast.Range_Stmt, ast_cont ast_context.in_package[ident.name] = symbol.pkg } } - case index.SymbolSliceValue: + case SymbolSliceValue: if len(stmt.vals) >= 1 { if ident, ok := stmt.vals[0].derived.(^Ident); ok { store_local(ast_context, v.expr, ident.pos.offset, ident.name, ast_context.local_id) @@ -2418,14 +2413,14 @@ clear_locals :: proc(ast_context: ^AstContext) { clear(&ast_context.usings) } -resolve_entire_file :: proc(document: ^common.Document, allocator := context.allocator) -> map[uintptr]index.SymbolAndNode { +resolve_entire_file :: proc(document: ^common.Document, allocator := context.allocator) -> map[uintptr]SymbolAndNode { ast_context := make_ast_context(document.ast, document.imports, document.package_name, document.uri.uri, allocator) get_globals(document.ast, &ast_context) ast_context.current_package = ast_context.document_package - symbols := make(map[uintptr]index.SymbolAndNode, 10000, allocator) + symbols := make(map[uintptr]SymbolAndNode, 10000, allocator) for decl in document.ast.decls { resolve_entire_decl(&ast_context, decl, &symbols, allocator) @@ -2436,7 +2431,7 @@ resolve_entire_file :: proc(document: ^common.Document, allocator := context.all return symbols } -resolve_entire_decl :: proc(ast_context: ^AstContext, decl: ^ast.Node, symbols: ^map[uintptr]index.SymbolAndNode, allocator := context.allocator) { +resolve_entire_decl :: proc(ast_context: ^AstContext, decl: ^ast.Node, symbols: ^map[uintptr]SymbolAndNode, allocator := context.allocator) { Scope :: struct { offset: int, id: int, @@ -2444,7 +2439,7 @@ resolve_entire_decl :: proc(ast_context: ^AstContext, decl: ^ast.Node, symbols: Visit_Data :: struct { ast_context: ^AstContext, - symbols: ^map[uintptr]index.SymbolAndNode, + symbols: ^map[uintptr]SymbolAndNode, scopes: [dynamic]Scope, id_counter: int, } @@ -2498,21 +2493,21 @@ resolve_entire_decl :: proc(ast_context: ^AstContext, decl: ^ast.Node, symbols: get_locals_stmt(ast_context.file, cast(^ast.Stmt)node, ast_context, &position_context) case ^ast.Ident: if symbol, ok := resolve_type_identifier(ast_context, v^); ok { - data.symbols[cast(uintptr)node] = index.SymbolAndNode { + data.symbols[cast(uintptr)node] = SymbolAndNode { node = v, symbol = symbol, } } case ^ast.Selector_Expr: if symbol, ok := resolve_type_expression(ast_context, &v.node); ok { - data.symbols[cast(uintptr)node] = index.SymbolAndNode { + data.symbols[cast(uintptr)node] = SymbolAndNode { node = v, symbol = symbol, } } case ^ast.Call_Expr: if symbol, ok := resolve_type_expression(ast_context, &v.node); ok { - data.symbols[cast(uintptr)node] = index.SymbolAndNode { + data.symbols[cast(uintptr)node] = SymbolAndNode { node = v, symbol = symbol, } @@ -2546,11 +2541,11 @@ concatenate_symbol_information :: proc { concatenate_raw_string_information, } -concatenate_raw_symbol_information :: proc(ast_context: ^AstContext, symbol: index.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, symbol.name, symbol.signature, symbol.type, is_completion) } -concatenate_raw_string_information :: proc(ast_context: ^AstContext, pkg: string, name: string, signature: string, type: index.SymbolType, is_completion: bool) -> string { +concatenate_raw_string_information :: proc(ast_context: ^AstContext, pkg: string, name: string, signature: string, type: SymbolType, is_completion: bool) -> string { pkg := path.base(pkg, false, context.temp_allocator) if type == .Package { @@ -2566,14 +2561,14 @@ concatenate_raw_string_information :: proc(ast_context: ^AstContext, pkg: string } } -unwrap_enum :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (index.SymbolEnumValue, bool) { +unwrap_enum :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (SymbolEnumValue, bool) { if node == nil { return {}, false } if enum_symbol, ok := resolve_type_expression(ast_context, node); ok { - if enum_value, ok := enum_symbol.value.(index.SymbolEnumValue); ok { + if enum_value, ok := enum_symbol.value.(SymbolEnumValue); ok { return enum_value, true } } @@ -2581,9 +2576,9 @@ unwrap_enum :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (index.SymbolE return {}, false } -unwrap_union :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (index.SymbolUnionValue, bool) { +unwrap_union :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (SymbolUnionValue, bool) { if union_symbol, ok := resolve_type_expression(ast_context, node); ok { - if union_value, ok := union_symbol.value.(index.SymbolUnionValue); ok { + if union_value, ok := union_symbol.value.(SymbolUnionValue); ok { return union_value, true } } @@ -2591,10 +2586,10 @@ unwrap_union :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (index.Symbol return {}, false } -unwrap_bitset :: proc(ast_context: ^AstContext, bitset_symbol: index.Symbol) -> (index.SymbolEnumValue, bool) { - if bitset_value, ok := bitset_symbol.value.(index.SymbolBitSetValue); ok { +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_value, ok := enum_symbol.value.(index.SymbolEnumValue); ok { + if enum_value, ok := enum_symbol.value.(SymbolEnumValue); ok { return enum_value, true } } @@ -2603,9 +2598,7 @@ unwrap_bitset :: proc(ast_context: ^AstContext, bitset_symbol: index.Symbol) -> return {}, false } -get_signature :: proc(ast_context: ^AstContext, ident: ast.Ident, symbol: index.Symbol, was_variable := false) -> string { - using index - +get_signature :: proc(ast_context: ^AstContext, ident: ast.Ident, symbol: Symbol, was_variable := false) -> string { if symbol.type == .Function { return symbol.signature } @@ -3054,7 +3047,7 @@ fallback_position_context_completion :: proc(document: ^common.Document, positio position_context.selector = e - ident := index.new_type(ast.Ident, e.pos, e.end, context.temp_allocator) + ident := new_type(ast.Ident, e.pos, e.end, context.temp_allocator) ident.name = string(position_context.file.src[last_dot + 1:end_offset]) if ident.name != "" { diff --git a/src/index/build.odin b/src/server/build.odin index f74f02f..c9edf93 100644 --- a/src/index/build.odin +++ b/src/server/build.odin @@ -1,4 +1,4 @@ -package index +package server import "core:path/filepath" import path "core:path/slashpath" diff --git a/src/server/caches.odin b/src/server/caches.odin index cc993c3..42dbc27 100644 --- a/src/server/caches.odin +++ b/src/server/caches.odin @@ -1,19 +1,17 @@ package server -import "shared:index" -import "shared:analysis" import "shared:common" //Used in semantic tokens and inlay hints to handle the entire file being resolved. FileResolveCache :: struct { - files: map[string]map[uintptr]index.SymbolAndNode, + files: map[string]map[uintptr]SymbolAndNode, } file_resolve_cache: FileResolveCache -resolve_entire_file :: proc(document: ^common.Document) -> map[uintptr]index.SymbolAndNode{ +resolve_entire_file_cached :: proc(document: ^common.Document) -> map[uintptr]SymbolAndNode{ if document.uri.uri not_in file_resolve_cache.files { - file_resolve_cache.files[document.uri.uri] = analysis.resolve_entire_file( + file_resolve_cache.files[document.uri.uri] = resolve_entire_file( document, common.scratch_allocator(document.allocator), ) diff --git a/src/index/clone.odin b/src/server/clone.odin index 24a1138..9a4af46 100644 --- a/src/index/clone.odin +++ b/src/server/clone.odin @@ -1,4 +1,4 @@ -package index +package server import "core:mem" import "core:fmt" diff --git a/src/index/collector.odin b/src/server/collector.odin index c915689..e049c66 100644 --- a/src/index/collector.odin +++ b/src/server/collector.odin @@ -1,4 +1,4 @@ -package index +package server import "core:odin/ast" import "core:hash" @@ -16,7 +16,7 @@ SymbolCollection :: struct { allocator: mem.Allocator, config: ^common.Config, packages: map[string]map[string]Symbol, - //references: map[string]map[string]Reference, + references: map[string]map[string]Reference, unique_strings: map[string]string, //store all our strings as unique strings and reference them to save memory. } @@ -261,7 +261,7 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri for expr in exprs { symbol: Symbol - token: ast.Node + token: ast.Node token_type: SymbolType name := expr.name diff --git a/src/server/completion.odin b/src/server/completion.odin index 02ed78f..40018b1 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -16,8 +16,6 @@ import "core:os" import "shared:common" -import "shared:index" -import "shared:analysis" /* TODOS: Making the signature details is really annoying and not that nice - try to see if this can be refractored. @@ -35,7 +33,6 @@ Completion_Type :: enum { } get_completion_list :: proc(document: ^common.Document, position: common.Position, completion_context: CompletionContext) -> (CompletionList, bool) { - using analysis list: CompletionList @@ -90,8 +87,7 @@ get_completion_list :: proc(document: ^common.Document, position: common.Positio ast_context.use_locals = true if symbol, ok := resolve_type_expression(&ast_context, assign.rhs[0]); ok { - - if union_value, ok := symbol.value.(index.SymbolUnionValue); ok { + if union_value, ok := symbol.value.(SymbolUnionValue); ok { completion_type = .Switch_Type } } @@ -118,11 +114,11 @@ get_completion_list :: proc(document: ^common.Document, position: common.Positio return list, true } -get_attribute_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { +get_attribute_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) { } -get_directive_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { +get_directive_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) { list.isIncomplete = false @@ -167,8 +163,7 @@ get_directive_completion :: proc(ast_context: ^analysis.AstContext, position_con list.items = items[:] } -get_comp_lit_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { - using analysis +get_comp_lit_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) { items := make([dynamic]CompletionItem, context.temp_allocator) @@ -180,7 +175,7 @@ get_comp_lit_completion :: proc(ast_context: ^analysis.AstContext, position_cont if comp_symbol, _, ok := resolve_type_comp_literal(ast_context, position_context, symbol, position_context.parent_comp_lit); ok { ast_context.current_package = comp_symbol.pkg; #partial switch v in comp_symbol.value { - case index.SymbolStructValue: + case SymbolStructValue: for name, i in v.names { ast_context.current_package = comp_symbol.pkg @@ -206,14 +201,13 @@ get_comp_lit_completion :: proc(ast_context: ^analysis.AstContext, position_cont list.items = items[:] } -get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { - using analysis +get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) { items := make([dynamic]CompletionItem, context.temp_allocator) ast_context.current_package = ast_context.document_package - selector: index.Symbol + selector: Symbol ok: bool ast_context.use_locals = true @@ -244,7 +238,7 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont } } - if s, ok := selector.value.(index.SymbolProcedureValue); ok { + 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 { return @@ -253,7 +247,7 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont } #partial switch v in selector.value { - case index.SymbolFixedArrayValue: + case SymbolFixedArrayValue: list.isIncomplete = true containsColor := 1 @@ -348,7 +342,7 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont append(&items, item) } } - case index.SymbolUnionValue: + case SymbolUnionValue: list.isIncomplete = false append_magic_union_completion(position_context, selector, &items) @@ -373,7 +367,7 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont } } - case index.SymbolEnumValue: + case SymbolEnumValue: list.isIncomplete = false for name in v.names { @@ -386,7 +380,7 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont append(&items, item) } - case index.SymbolStructValue: + case SymbolStructValue: list.isIncomplete = false for name, i in v.names { @@ -428,10 +422,10 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont } } - case index.SymbolPackageValue: + case SymbolPackageValue: list.isIncomplete = true - if searched, ok := index.fuzzy_search(field, {selector.pkg}); ok { + if searched, ok := fuzzy_search(field, {selector.pkg}); ok { for search in searched { symbol := search.symbol @@ -458,10 +452,10 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont log.errorf("Failed to fuzzy search, field: %v, package: %v", field, selector.pkg) return } - case index.SymbolDynamicArrayValue: + case SymbolDynamicArrayValue: list.isIncomplete = false append_magic_dynamic_array_completion(position_context, selector, &items) - case index.SymbolMapValue: + case SymbolMapValue: list.isIncomplete = false append_magic_map_completion(position_context, selector, &items) } @@ -469,14 +463,13 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont list.items = items[:] } -get_implicit_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { - using analysis +get_implicit_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) { items := make([dynamic]CompletionItem, context.temp_allocator) list.isIncomplete = false - selector: index.Symbol + selector: Symbol ast_context.use_locals = true ast_context.use_globals = true @@ -586,7 +579,7 @@ get_implicit_completion :: proc(ast_context: ^analysis.AstContext, position_cont 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, symbol, position_context.parent_comp_lit); ok { - if s, ok := comp_symbol.value.(index.SymbolStructValue); ok { + if s, ok := comp_symbol.value.(SymbolStructValue); ok { ast_context.current_package = comp_symbol.pkg; //We can either have the final @@ -686,7 +679,7 @@ get_implicit_completion :: proc(ast_context: ^analysis.AstContext, position_cont } 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.(index.SymbolProcedureValue); ok { + if procedure, ok := symbol.value.(SymbolProcedureValue); ok { if procedure.return_types == nil { return } @@ -761,7 +754,7 @@ get_implicit_completion :: proc(ast_context: ^analysis.AstContext, position_cont if call, ok := position_context.call.derived.(^ast.Call_Expr); ok { parameter_index, parameter_ok := find_position_in_call_param(ast_context, call^) if symbol, ok := resolve_type_expression(ast_context, call.expr); ok && parameter_ok { - if proc_value, ok := symbol.value.(index.SymbolProcedureValue); ok { + if proc_value, ok := symbol.value.(SymbolProcedureValue); ok { if len(proc_value.arg_types) <= parameter_index { return } @@ -786,8 +779,7 @@ get_implicit_completion :: proc(ast_context: ^analysis.AstContext, position_cont } } -get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { - using analysis +get_identifier_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) { items := make([dynamic]CompletionItem, context.temp_allocator) @@ -797,11 +789,11 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co score: f32, snippet: Snippet_Info, name: string, - type: index.SymbolType, + type: SymbolType, doc: string, pkg: string, signature: string, - flags: index.SymbolFlags, + flags: SymbolFlags, } combined_sort_interface :: proc(s: ^[dynamic]CombinedResult) -> sort.Interface { @@ -824,11 +816,11 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co combined := make([dynamic]CombinedResult) - lookup := "" + lookup_name := "" if position_context.identifier != nil { if ident, ok := position_context.identifier.derived.(^ast.Ident); ok { - lookup = ident.name + lookup_name = ident.name } } @@ -843,7 +835,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co append(&pkgs, ast_context.document_package) append(&pkgs, "$builtin") - if results, ok := index.fuzzy_search(lookup, pkgs[:]); ok { + if results, ok := fuzzy_search(lookup_name, pkgs[:]); ok { for r in results { r := r resolve_unresolved_symbol(ast_context, &r.symbol) @@ -862,7 +854,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co } } - matcher := common.make_fuzzy_matcher(lookup) + matcher := common.make_fuzzy_matcher(lookup_name) global: for k, v in ast_context.globals { if position_context.global_lhs_stmt { @@ -880,7 +872,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co ast_context.use_globals = true ast_context.current_package = ast_context.document_package - ident := index.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 { @@ -914,7 +906,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co ast_context.use_globals = true ast_context.current_package = ast_context.document_package - ident := index.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 { @@ -942,7 +934,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co break } - symbol := index.Symbol { + symbol := Symbol { name = pkg.base, type = .Package, } @@ -961,7 +953,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co } for keyword, _ in common.keyword_map { - symbol := index.Symbol { + symbol := Symbol { name = keyword, type = .Keyword, } @@ -980,7 +972,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co } for keyword, _ in language_keywords { - symbol := index.Symbol { + symbol := Symbol { name = keyword, type = .Keyword, } @@ -1064,7 +1056,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co list.items = items[:] } -get_package_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { +get_package_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) { items := make([dynamic]CompletionItem, context.temp_allocator) @@ -1146,8 +1138,7 @@ search_for_packages :: proc(fullpath: string) -> [] string { return packages[:] } -get_type_switch_completion :: proc(ast_context: ^analysis.AstContext, position_context: ^analysis.DocumentPositionContext, list: ^CompletionList) { - using analysis +get_type_switch_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) { items := make([dynamic]CompletionItem, context.temp_allocator) list.isIncomplete = false @@ -1197,7 +1188,7 @@ get_type_switch_completion :: proc(ast_context: ^analysis.AstContext, position_c list.items = items[:] } -get_core_insert_package_if_non_existent :: proc(ast_context: ^analysis.AstContext, pkg: string) -> (TextEdit, bool) { +get_core_insert_package_if_non_existent :: proc(ast_context: ^AstContext, pkg: string) -> (TextEdit, bool) { builder := strings.make_builder(context.temp_allocator) for imp in ast_context.imports { @@ -1223,7 +1214,7 @@ get_core_insert_package_if_non_existent :: proc(ast_context: ^analysis.AstContex }, true } -get_range_from_selection_start_to_dot :: proc(position_context: ^analysis.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.end.character += 1 @@ -1233,7 +1224,7 @@ get_range_from_selection_start_to_dot :: proc(position_context: ^analysis.Docume return {}, false } -append_magic_map_completion :: proc(position_context: ^analysis.DocumentPositionContext, symbol: index.Symbol, items: ^[dynamic]CompletionItem) { +append_magic_map_completion :: proc(position_context: ^DocumentPositionContext, symbol: Symbol, items: ^[dynamic]CompletionItem) { range, ok := get_range_from_selection_start_to_dot(position_context) if !ok { @@ -1277,7 +1268,7 @@ append_magic_map_completion :: proc(position_context: ^analysis.DocumentPosition } -append_magic_dynamic_array_completion :: proc(position_context: ^analysis.DocumentPositionContext, symbol: index.Symbol, items: ^[dynamic]CompletionItem) { +append_magic_dynamic_array_completion :: proc(position_context: ^DocumentPositionContext, symbol: Symbol, items: ^[dynamic]CompletionItem) { range, ok := get_range_from_selection_start_to_dot(position_context) if !ok { @@ -1341,7 +1332,7 @@ append_magic_dynamic_array_completion :: proc(position_context: ^analysis.Docume } -append_magic_union_completion :: proc(position_context: ^analysis.DocumentPositionContext, symbol: index.Symbol, items: ^[dynamic]CompletionItem) { +append_magic_union_completion :: proc(position_context: ^DocumentPositionContext, symbol: Symbol, items: ^[dynamic]CompletionItem) { range, ok := get_range_from_selection_start_to_dot(position_context) if !ok { diff --git a/src/server/definition.odin b/src/server/definition.odin index cfa2c49..4447bb2 100644 --- a/src/server/definition.odin +++ b/src/server/definition.odin @@ -14,14 +14,9 @@ import "core:sort" import "core:slice" import "core:os" - import "shared:common" -import "shared:index" -import "shared:analysis" get_definition_location :: proc(document: ^common.Document, position: common.Position) -> ([]common.Location, bool) { - using analysis - locations := make([dynamic]common.Location, context.temp_allocator) location: common.Location @@ -69,7 +64,7 @@ get_definition_location :: proc(document: ^common.Document, position: common.Pos //otherwise it's the field the client wants to go to. - selector: index.Symbol + selector: Symbol ast_context.use_locals = true ast_context.use_globals = true @@ -94,16 +89,16 @@ get_definition_location :: proc(document: ^common.Document, position: common.Pos uri = selector.uri #partial switch v in selector.value { - case index.SymbolEnumValue: + case SymbolEnumValue: location.range = selector.range - case index.SymbolStructValue: + case SymbolStructValue: for name, i in v.names { if strings.compare(name, field) == 0 { location.range = common.get_token_range(v.types[i]^, document.ast.src) } } - case index.SymbolPackageValue: - if symbol, ok := index.lookup(field, selector.pkg); ok { + case SymbolPackageValue: + if symbol, ok := lookup(field, selector.pkg); ok { location.range = symbol.range uri = symbol.uri } else { diff --git a/src/server/document_links.odin b/src/server/document_links.odin index a1514b0..08330ab 100644 --- a/src/server/document_links.odin +++ b/src/server/document_links.odin @@ -16,12 +16,8 @@ import "core:os" import "shared:common" -import "shared:index" -import "shared:analysis" get_document_links :: proc(document: ^common.Document) -> ([]DocumentLink, bool) { - using analysis - links := make([dynamic]DocumentLink, 0, context.temp_allocator) for imp in document.ast.imports { diff --git a/src/server/document_symbols.odin b/src/server/document_symbols.odin index 667b94a..b442bfe 100644 --- a/src/server/document_symbols.odin +++ b/src/server/document_symbols.odin @@ -16,13 +16,8 @@ import "core:os" import "shared:common" -import "shared:index" -import "shared:analysis" - get_document_symbols :: proc(document: ^common.Document) -> []DocumentSymbol { - using analysis - ast_context := make_ast_context(document.ast, document.imports, document.package_name, document.uri.uri) get_globals(document.ast, &ast_context) diff --git a/src/server/hover.odin b/src/server/hover.odin index 4286ee8..1fdecd5 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -14,17 +14,13 @@ import "core:sort" import "core:slice" import "shared:common" -import "shared:index" -import "shared:analysis" - -write_hover_content :: proc(ast_context: ^analysis.AstContext, symbol: index.Symbol) -> MarkupContent { - using analysis +write_hover_content :: proc(ast_context: ^AstContext, symbol: Symbol) -> MarkupContent { content: MarkupContent symbol := symbol - if untyped, ok := symbol.value.(index.SymbolUntypedValue); ok { + if untyped, ok := symbol.value.(SymbolUntypedValue); ok { switch untyped.type { case .String: symbol.signature = "string" case .Bool: symbol.signature = "bool" @@ -49,8 +45,6 @@ write_hover_content :: proc(ast_context: ^analysis.AstContext, symbol: index.Sym get_hover_information :: proc(document: ^common.Document, position: common.Position) -> (Hover, bool) { - using analysis - hover := Hover { contents = { kind = "plaintext", @@ -104,7 +98,7 @@ get_hover_information :: proc(document: ^common.Document, position: common.Posit } } - selector: index.Symbol + selector: Symbol selector, ok = resolve_type_expression(&ast_context, position_context.selector) if !ok { @@ -123,7 +117,7 @@ get_hover_information :: proc(document: ^common.Document, position: common.Posit hover.range = common.get_token_range(position_context.identifier^, document.ast.src) #partial switch v in selector.value { - case index.SymbolStructValue: + case SymbolStructValue: for name, i in v.names { if strings.compare(name, field) == 0 { if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok { @@ -135,7 +129,7 @@ get_hover_information :: proc(document: ^common.Document, position: common.Posit } } } - case index.SymbolPackageValue: + case SymbolPackageValue: if position_context.field != nil { if ident, ok := position_context.field.derived.(^ast.Ident); ok { ast_context.current_package = selector.pkg diff --git a/src/index/indexer.odin b/src/server/indexer.odin index 73dc101..03b3e75 100644 --- a/src/index/indexer.odin +++ b/src/server/indexer.odin @@ -1,4 +1,4 @@ -package index +package server import "core:odin/ast" import "core:fmt" diff --git a/src/server/inlay_hints.odin b/src/server/inlay_hints.odin index a5be9c2..b8f4024 100644 --- a/src/server/inlay_hints.odin +++ b/src/server/inlay_hints.odin @@ -4,13 +4,9 @@ import "core:odin/ast" import "core:fmt" import "shared:common" -import "shared:analysis" -import "shared:index" //document -get_inlay_hints :: proc(document: ^common.Document, symbols: map[uintptr]index.SymbolAndNode) -> ([]InlayHint, bool) { - using analysis - +get_inlay_hints :: proc(document: ^common.Document, symbols: map[uintptr]SymbolAndNode) -> ([]InlayHint, bool) { hints := make([dynamic]InlayHint, context.temp_allocator) ast_context := make_ast_context(document.ast, document.imports, document.package_name, document.uri.uri) @@ -58,7 +54,7 @@ get_inlay_hints :: proc(document: ^common.Document, symbols: map[uintptr]index.S } if symbol_and_node, ok := symbols[cast(uintptr)node_call]; ok { - if symbol_call, ok := symbol_and_node.symbol.value.(index.SymbolProcedureValue); ok { + if symbol_call, ok := symbol_and_node.symbol.value.(SymbolProcedureValue); ok { for arg in symbol_call.arg_types { for name in arg.names { if symbol_arg_count >= len(call.args) { diff --git a/src/server/lens.odin b/src/server/lens.odin index 93827f5..abde537 100644 --- a/src/server/lens.odin +++ b/src/server/lens.odin @@ -2,7 +2,7 @@ package server import "core:odin/ast" -import "shared:analysis" + import "shared:common" @@ -21,9 +21,6 @@ CodeLens :: struct { } get_code_lenses :: proc(document: ^common.Document, position: common.Position) -> ([]CodeLens, bool) { - - using analysis - ast_context := make_ast_context(document.ast, document.imports, document.package_name, document.uri.uri) get_globals(document.ast, &ast_context) diff --git a/src/index/memory_index.odin b/src/server/memory_index.odin index 79cdc43..03504c1 100644 --- a/src/index/memory_index.odin +++ b/src/server/memory_index.odin @@ -1,4 +1,4 @@ -package index +package server import "core:hash" import "core:strings" diff --git a/src/index/references.odin b/src/server/references.odin index 6613925..86645b1 100644 --- a/src/index/references.odin +++ b/src/server/references.odin @@ -1,11 +1,11 @@ -package index +package server + -/* import "shared:common" -import "shared:analysis" import "core:strings" import "core:odin/ast" +import path "core:path/slashpath" Reference :: struct { @@ -16,7 +16,6 @@ Reference :: struct { collect_references :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error { document := common.Document { ast = file, - } uri, ok := common.parse_uri(uri, context.temp_allocator) @@ -31,9 +30,12 @@ collect_references :: proc(collection: ^SymbolCollection, file: ast.File, uri: s document.package_name = path.dir(document.uri.path) } + document.uri = uri + + return {} } -*/ + diff --git a/src/server/rename.odin b/src/server/rename.odin index b7d39ef..7c4629e 100644 --- a/src/server/rename.odin +++ b/src/server/rename.odin @@ -1,14 +1,11 @@ package server import "shared:common" -import "shared:analysis" import "core:log" import "core:odin/ast" get_rename :: proc(document: ^common.Document, new_text: string, position: common.Position) -> (WorkspaceEdit, bool) { - using analysis - workspace: WorkspaceEdit document_changes := make([dynamic]TextDocumentEdit, context.temp_allocator) diff --git a/src/server/requests.odin b/src/server/requests.odin index 8ffaa97..fdc5d31 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -18,7 +18,6 @@ import "core:odin/ast" import "core:odin/parser" import "shared:common" -import "shared:index" Header :: struct { content_length: int, @@ -537,10 +536,10 @@ request_initialize :: proc (params: json.Value, id: RequestId, config: ^common.C Temp index here, but should be some background thread that starts the indexing */ - index.indexer.dynamic_index = index.make_memory_index(index.make_symbol_collection(context.allocator, config)) - index.indexer.dynamic_uri_owned = make(map[string]bool, 200, context.allocator) + indexer.dynamic_index = make_memory_index(make_symbol_collection(context.allocator, config)) + indexer.dynamic_uri_owned = make(map[string]bool, 200, context.allocator) - index.build_static_index(context.allocator, config) + build_static_index(context.allocator, config) /* Add runtime package @@ -548,9 +547,9 @@ request_initialize :: proc (params: json.Value, id: RequestId, config: ^common.C if core, ok := config.collections["core"]; ok { when ODIN_OS == .Windows { - append(&index.indexer.builtin_packages, path.join(strings.to_lower(core, context.temp_allocator), "runtime")) + append(&indexer.builtin_packages, path.join(strings.to_lower(core, context.temp_allocator), "runtime")) } else { - append(&index.indexer.builtin_packages, path.join(core, "runtime")) + append(&indexer.builtin_packages, path.join(core, "runtime")) } } @@ -799,8 +798,8 @@ notification_did_save :: proc (params: json.Value, id: RequestId, config: ^commo fullpath := uri.path p := parser.Parser { - err = index.log_error_handler, - warn = index.log_warning_handler, + err = log_error_handler, + warn = log_warning_handler, flags = {.Optional_Semicolons}, } @@ -827,20 +826,20 @@ notification_did_save :: proc (params: json.Value, id: RequestId, config: ^commo log.errorf("error in parse file for indexing %v", fullpath) } - for k, v in &index.indexer.dynamic_index.collection.packages { + for k, v in &indexer.dynamic_index.collection.packages { for k2, v2 in &v { if v2.uri == uri.uri { - index.free_symbol(v2, context.allocator) + free_symbol(v2, context.allocator) v[k2] = {} } } } - if ret := index.collect_symbols(&index.indexer.dynamic_index.collection, file, uri.uri); ret != .None { + if ret := collect_symbols(&indexer.dynamic_index.collection, file, uri.uri); ret != .None { log.errorf("failed to collect symbols on save %v", ret) } - index.indexer.dynamic_uri_owned[uri.uri] = true + indexer.dynamic_uri_owned[uri.uri] = true check(uri, writer, config) @@ -878,7 +877,7 @@ request_semantic_token_full :: proc (params: json.Value, id: RequestId, config: symbols: SemanticTokens if config.enable_semantic_tokens { - resolve_entire_file(document) + resolve_entire_file_cached(document) if cache_symbols, ok := file_resolve_cache.files[document.uri.uri]; ok { symbols = get_semantic_tokens(document, range, cache_symbols) @@ -1008,7 +1007,7 @@ request_inlay_hint :: proc (params: json.Value, id: RequestId, config: ^common.C hints: []InlayHint - resolve_entire_file(document) + resolve_entire_file_cached(document) if cache_symbols, ok := file_resolve_cache.files[document.uri.uri]; ok { hints, ok = get_inlay_hints(document, cache_symbols) diff --git a/src/server/semantic_tokens.odin b/src/server/semantic_tokens.odin index 5ae011d..acbe1a5 100644 --- a/src/server/semantic_tokens.odin +++ b/src/server/semantic_tokens.odin @@ -6,8 +6,7 @@ import "core:log" import "core:fmt" import "shared:common" -import "shared:index" -import "shared:analysis" + /* Right now I might be setting the wrong types, since there is no documentation as to what should be what, and looking at other LSP there is no consistancy. @@ -78,7 +77,7 @@ SemanticTokens :: struct { SemanticTokenBuilder :: struct { current_start: int, tokens: [dynamic]u32, - symbols: map[uintptr]index.SymbolAndNode, + symbols: map[uintptr]SymbolAndNode, selector: bool, } @@ -94,9 +93,7 @@ get_tokens :: proc(builder: SemanticTokenBuilder) -> SemanticTokens { } } -get_semantic_tokens :: proc(document: ^common.Document, range: common.Range, symbols: map[uintptr]index.SymbolAndNode) -> SemanticTokens { - using analysis - +get_semantic_tokens :: proc(document: ^common.Document, range: common.Range, symbols: map[uintptr]SymbolAndNode) -> SemanticTokens { builder := make_token_builder() if document.ast.pkg_decl != nil { @@ -144,23 +141,23 @@ visit :: proc { visit_stmt, } -visit_array :: proc(array: $A/[]^$T, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { +visit_array :: proc(array: $A/[]^$T, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { for elem, i in array { visit(elem, builder, ast_context) } } -visit_dynamic_array :: proc(array: $A/[dynamic]^$T, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { +visit_dynamic_array :: proc(array: $A/[dynamic]^$T, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { for elem, i in array { visit(elem, builder, ast_context) } } -visit_stmt :: proc(node: ^ast.Stmt, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { +visit_stmt :: proc(node: ^ast.Stmt, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { visit_node(node, builder, ast_context) } -visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { +visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { using ast if node == nil { @@ -179,21 +176,21 @@ visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder, ast_context: } #partial switch v in symbol_and_node.symbol.value { - case index.SymbolPackageValue: + case SymbolPackageValue: write_semantic_node(builder, node, ast_context.file.src, .Namespace, .None) - case index.SymbolStructValue: + case SymbolStructValue: write_semantic_node(builder, node, ast_context.file.src, .Struct, .None) - case index.SymbolEnumValue: + case SymbolEnumValue: write_semantic_node(builder, node, ast_context.file.src, .Enum, .None) - case index.SymbolUnionValue: + case SymbolUnionValue: write_semantic_node(builder, node, ast_context.file.src, .Enum, .None) - case index.SymbolProcedureValue: + case SymbolProcedureValue: write_semantic_node(builder, node, ast_context.file.src, .Function, .None) - case index.SymbolProcedureGroupValue: + case SymbolProcedureGroupValue: write_semantic_node(builder, node, ast_context.file.src, .Function, .None) - case index.SymbolUntypedValue: + case SymbolUntypedValue: write_semantic_node(builder, node, ast_context.file.src, .Type, .None) - case index.SymbolBasicValue: + case SymbolBasicValue: write_semantic_node(builder, node, ast_context.file.src, .Type, .None) case: //log.errorf("Unexpected symbol value: %v", symbol.value); @@ -349,11 +346,9 @@ visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder, ast_context: } } -visit_basic_lit :: proc(basic_lit: ast.Basic_Lit, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { - using analysis - +visit_basic_lit :: proc(basic_lit: ast.Basic_Lit, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { if symbol, ok := resolve_basic_lit(ast_context, basic_lit); ok { - if untyped, ok := symbol.value.(index.SymbolUntypedValue); ok { + if untyped, ok := symbol.value.(SymbolUntypedValue); ok { switch untyped.type { case .Bool: write_semantic_token(builder, basic_lit.tok, ast_context.file.src, .Keyword, .None) @@ -366,7 +361,7 @@ visit_basic_lit :: proc(basic_lit: ast.Basic_Lit, builder: ^SemanticTokenBuilder } } -visit_value_decl :: proc(value_decl: ast.Value_Decl, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { +visit_value_decl :: proc(value_decl: ast.Value_Decl, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { using ast if value_decl.type != nil { @@ -433,7 +428,7 @@ visit_token_op :: proc(builder: ^SemanticTokenBuilder, token: tokenizer.Token, s } } -visit_proc_type :: proc(node: ^ast.Proc_Type, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { +visit_proc_type :: proc(node: ^ast.Proc_Type, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { using ast if node == nil { @@ -460,7 +455,7 @@ visit_proc_type :: proc(node: ^ast.Proc_Type, builder: ^SemanticTokenBuilder, as } } -visit_enum_fields :: proc(node: ast.Enum_Type, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { +visit_enum_fields :: proc(node: ast.Enum_Type, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { using ast if node.fields == nil { @@ -480,7 +475,7 @@ visit_enum_fields :: proc(node: ast.Enum_Type, builder: ^SemanticTokenBuilder, a } } -visit_struct_fields :: proc(node: ast.Struct_Type, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { +visit_struct_fields :: proc(node: ast.Struct_Type, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { using ast if node.fields == nil { @@ -498,7 +493,7 @@ visit_struct_fields :: proc(node: ast.Struct_Type, builder: ^SemanticTokenBuilde } } -visit_selector :: proc(selector: ^ast.Selector_Expr, builder: ^SemanticTokenBuilder, ast_context: ^analysis.AstContext) { +visit_selector :: proc(selector: ^ast.Selector_Expr, builder: ^SemanticTokenBuilder, ast_context: ^AstContext) { if _, ok := selector.expr.derived.(^ast.Selector_Expr); ok { visit_selector(cast(^ast.Selector_Expr)selector.expr, builder, ast_context) } else { @@ -511,17 +506,17 @@ visit_selector :: proc(selector: ^ast.Selector_Expr, builder: ^SemanticTokenBuil write_semantic_node(builder, selector.field, ast_context.file.src, .Method, .None) } #partial switch v in symbol_and_node.symbol.value { - case index.SymbolPackageValue: + case SymbolPackageValue: write_semantic_node(builder, selector.field, ast_context.file.src, .Namespace, .None) - case index.SymbolStructValue: + case SymbolStructValue: write_semantic_node(builder, selector.field, ast_context.file.src, .Struct, .None) - case index.SymbolEnumValue: + case SymbolEnumValue: write_semantic_node(builder, selector.field, ast_context.file.src, .Enum, .None) - case index.SymbolUnionValue: + case SymbolUnionValue: write_semantic_node(builder, selector.field, ast_context.file.src, .Enum, .None) - case index.SymbolProcedureValue: + case SymbolProcedureValue: write_semantic_node(builder, selector.field, ast_context.file.src, .Function, .None) - case index.SymbolProcedureGroupValue: + case SymbolProcedureGroupValue: write_semantic_node(builder, selector.field, ast_context.file.src, .Function, .None) } } diff --git a/src/server/signature.odin b/src/server/signature.odin index e8b3ae1..e866953 100644 --- a/src/server/signature.odin +++ b/src/server/signature.odin @@ -14,8 +14,6 @@ import "core:sort" import "core:slice" import "shared:common" -import "shared:index" -import "shared:analysis" SignatureInformationCapabilities :: struct { parameterInformation: ParameterInformationCapabilities, @@ -52,8 +50,8 @@ ParameterInformation :: struct { /* Lazily build the signature and returns from ast.Nodes */ -build_procedure_symbol_signature :: proc(symbol: ^index.Symbol) { - if value, ok := symbol.value.(index.SymbolProcedureValue); ok { +build_procedure_symbol_signature :: proc(symbol: ^Symbol) { + if value, ok := symbol.value.(SymbolProcedureValue); ok { builder := strings.make_builder(context.temp_allocator) strings.write_string(&builder, "proc") @@ -85,13 +83,13 @@ build_procedure_symbol_signature :: proc(symbol: ^index.Symbol) { } } symbol.signature = strings.to_string(builder) - } else if value, ok := symbol.value.(index.SymbolAggregateValue); ok { + } else if value, ok := symbol.value.(SymbolAggregateValue); ok { symbol.signature = "proc" } } -seperate_proc_field_arguments :: proc(procedure: ^index.Symbol) { - if value, ok := &procedure.value.(index.SymbolProcedureValue); ok { +seperate_proc_field_arguments :: proc(procedure: ^Symbol) { + if value, ok := &procedure.value.(SymbolProcedureValue); ok { types := make([dynamic]^ast.Field, context.temp_allocator) for arg, i in value.arg_types { @@ -101,7 +99,7 @@ seperate_proc_field_arguments :: proc(procedure: ^index.Symbol) { } for name in arg.names { - field : ^ast.Field = index.new_type(ast.Field, {}, {}, context.temp_allocator) + field : ^ast.Field = new_type(ast.Field, {}, {}, context.temp_allocator) field.names = make([]^ast.Expr, 1, context.temp_allocator) field.names[0] = name field.type = arg.type @@ -114,8 +112,6 @@ seperate_proc_field_arguments :: proc(procedure: ^index.Symbol) { } get_signature_information :: proc(document: ^common.Document, position: common.Position) -> (SignatureHelp, bool) { - using analysis - signature_help: SignatureHelp ast_context := make_ast_context(document.ast, document.imports, document.package_name, document.uri.uri) @@ -145,7 +141,7 @@ get_signature_information :: proc(document: ^common.Document, position: common.P } } - call: index.Symbol + call: Symbol call, ok = resolve_type_expression(&ast_context, position_context.call) if !ok { @@ -156,7 +152,7 @@ get_signature_information :: proc(document: ^common.Document, position: common.P signature_information := make([dynamic]SignatureInformation, context.temp_allocator) - if value, ok := call.value.(index.SymbolProcedureValue); ok { + if value, ok := call.value.(SymbolProcedureValue); ok { parameters := make([]ParameterInformation, len(value.arg_types), context.temp_allocator) for arg, i in value.arg_types { @@ -177,13 +173,13 @@ get_signature_information :: proc(document: ^common.Document, position: common.P parameters = parameters, } append(&signature_information, info) - } else if value, ok := call.value.(index.SymbolAggregateValue); ok { + } else if value, ok := call.value.(SymbolAggregateValue); ok { //function overloaded procedures for symbol in value.symbols { symbol := symbol - if value, ok := symbol.value.(index.SymbolProcedureValue); ok { + if value, ok := symbol.value.(SymbolProcedureValue); ok { parameters := make([]ParameterInformation, len(value.arg_types), context.temp_allocator) diff --git a/src/index/symbol.odin b/src/server/symbol.odin index 56336cc..b6a3a3c 100644 --- a/src/index/symbol.odin +++ b/src/server/symbol.odin @@ -1,4 +1,4 @@ -package index +package server import "core:odin/ast" import "core:hash" |