diff options
| -rw-r--r-- | src/server/definition.odin | 8 | ||||
| -rw-r--r-- | src/server/hover.odin | 21 | ||||
| -rw-r--r-- | tests/hover_test.odin | 23 |
3 files changed, 43 insertions, 9 deletions
diff --git a/src/server/definition.odin b/src/server/definition.odin index 869816c..7ff32d8 100644 --- a/src/server/definition.odin +++ b/src/server/definition.odin @@ -2,17 +2,9 @@ package server import "core:fmt" import "core:log" -import "core:mem" import "core:odin/ast" -import "core:odin/parser" import "core:odin/tokenizer" -import "core:os" import "core:path/filepath" -import path "core:path/slashpath" -import "core:slice" -import "core:sort" -import "core:strconv" -import "core:strings" import "src:common" diff --git a/src/server/hover.odin b/src/server/hover.odin index 9453139..991ea1b 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -55,7 +55,26 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> get_locals(document.ast, position_context.function, &ast_context, &position_context) } - if position_context.import_stmt != nil { + if position_context.import_stmt != nil && position_in_node(position_context.import_stmt, position_context.position) { + for imp in document.imports { + if imp.original != position_context.import_stmt.fullpath { + continue + } + + symbol := Symbol { + name = imp.base, + type = .Package, + pkg = imp.name, + value = SymbolPackageValue{}, + } + try_build_package(symbol.pkg) + if symbol, ok = resolve_symbol_return(&ast_context, symbol); ok { + hover.range = common.get_token_range(document.ast.pkg_decl, ast_context.file.src) + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } + return {}, false, true } diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 6cb9a7f..74cf0d0 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -6133,6 +6133,29 @@ ast_hover_package_docs :: proc(t: ^testing.T) { test.expect_hover(t, &source, "my_package: package\n---\nPackage docs") } +@(test) +ast_hover_import_path_package_docs :: proc(t: ^testing.T) { + packages := make([dynamic]test.Package, context.temp_allocator) + + append( + &packages, + test.Package { + pkg = "my_package", + source = `// Package docs + package my_package + `, + }, + ) + source := test.Source { + main = `package test + import "my_packa{*}ge" + `, + packages = packages[:], + } + + test.expect_hover(t, &source, "my_package: package\n---\nPackage docs") +} + /* Waiting for odin fix |