diff options
| -rw-r--r-- | src/server/analysis.odin | 36 | ||||
| -rw-r--r-- | src/server/indexer.odin | 5 | ||||
| -rw-r--r-- | src/server/locals.odin | 2 | ||||
| -rw-r--r-- | src/server/memory_index.odin | 2 | ||||
| -rw-r--r-- | tests/hover_test.odin | 36 |
5 files changed, 74 insertions, 7 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index a6f3a64..ccaefbf 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1364,12 +1364,48 @@ resolve_call_expr :: proc(ast_context: ^AstContext, v: ^ast.Call_Expr) -> (Symbo } else { return {}, false } + } else if directive, ok := v.expr.derived.(^ast.Basic_Directive); ok { + return resolve_call_directive(ast_context, v) } ok := internal_resolve_type_expression(ast_context, v.expr, &symbol) return symbol, ok } +resolve_call_directive :: proc(ast_context: ^AstContext, call: ^ast.Call_Expr) -> (Symbol, bool) { + directive, ok := call.expr.derived.(^ast.Basic_Directive) + if !ok { + return {}, false + } + + switch directive.name { + case "config": + return resolve_type_expression(ast_context, call.args[1]) + case "load": + if len(call.args) == 1 { + ident := new_type(ast.Ident, call.pos, call.end, ast_context.allocator) + ident.name = "u8" + value := SymbolSliceValue{ + expr = ident + } + symbol := Symbol{name = "#load", value = value} + return symbol, true + } else if len(call.args) == 2 { + return resolve_type_expression(ast_context, call.args[1]) + } + case "location": + return lookup("Source_Code_Location", indexer.runtime_package, call.pos.file) + case "hash", "load_hash": + ident := new_type(ast.Ident, call.pos, call.end, ast_context.allocator) + ident.name = "int" + return resolve_type_identifier(ast_context, ident^) + case "load_directory": + return lookup("Load_Directory_File", indexer.runtime_package, call.pos.file) + } + + return {}, false +} + resolve_index_expr :: proc(ast_context: ^AstContext, index_expr: ^ast.Index_Expr, expr: ^ast.Expr) -> (Symbol, bool) { indexed := Symbol{} ok := internal_resolve_type_expression(ast_context, expr, &indexed) diff --git a/src/server/indexer.odin b/src/server/indexer.odin index 3ffc3c3..3337b3b 100644 --- a/src/server/indexer.odin +++ b/src/server/indexer.odin @@ -1,13 +1,8 @@ package server -import "core:fmt" import "core:log" -import "core:odin/ast" -import "core:path/filepath" -import "core:slice" import "core:strings" - Indexer :: struct { builtin_packages: [dynamic]string, runtime_package: string, diff --git a/src/server/locals.odin b/src/server/locals.odin index edebd85..b02a841 100644 --- a/src/server/locals.odin +++ b/src/server/locals.odin @@ -216,6 +216,8 @@ get_generic_assignment :: proc( } } } + } else if directive, ok := v.expr.derived.(^Basic_Directive); ok { + append(results, v) } //We have to resolve early and can't rely on lazy evalutation because it can have multiple returns. diff --git a/src/server/memory_index.odin b/src/server/memory_index.odin index 80c137f..487d7a2 100644 --- a/src/server/memory_index.odin +++ b/src/server/memory_index.odin @@ -1,8 +1,6 @@ package server import "core:fmt" -import "core:hash" -import "core:log" import "core:slice" import "core:strings" diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 75b3341..51a2edc 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -5894,6 +5894,42 @@ ast_hover_const_aliases_from_other_pkg :: proc(t: ^testing.T) { test.expect_hover(t, &source, "test.Bar :: my_package.Foo") } +@(test) +ast_hover_directives_config_local :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + foo :: proc() { + b{*}ar := #config(TEST, false) + } + `, + } + test.expect_hover(t, &source, "test.bar: bool") +} + +@(test) +ast_hover_directives_load_type_local :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + foo :: proc() { + b{*}ar := #load("foo", string) + } + `, + } + test.expect_hover(t, &source, "test.bar: string") +} + +@(test) +ast_hover_directives_load_hash_local :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + foo :: proc() { + b{*}ar := #load_hash("a", "b") + } + `, + } + test.expect_hover(t, &source, "test.bar: int") +} /* Waiting for odin fix |