diff options
Diffstat (limited to 'src/server/hover.odin')
| -rw-r--r-- | src/server/hover.odin | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/src/server/hover.odin b/src/server/hover.odin index 20651e4..991ea1b 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -16,7 +16,11 @@ write_hover_content :: proc(ast_context: ^AstContext, symbol: Symbol) -> MarkupC if cat != "" { content.kind = "markdown" - content.value = fmt.tprintf("```odin\n%v\n```%v", cat, doc) + if doc != "" { + content.value = fmt.tprintf(DOC_FMT_MARKDOWN, cat, doc) + } else { + content.value = fmt.tprintf(DOC_FMT_ODIN, cat) + } } else { content.kind = "plaintext" } @@ -51,10 +55,45 @@ 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 } + if document.ast.pkg_decl != nil && position_in_node(document.ast.pkg_decl, position_context.position) { + symbol := Symbol { + name = document.ast.pkg_name, + type = .Package, + pkg = ast_context.document_package, + 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 + } + + } + if position_context.type_cast != nil && !position_in_node(position_context.type_cast.type, position_context.position) && !position_in_node(position_context.type_cast.expr, position_context.position) { // check that we're actually on the 'cast' word @@ -66,6 +105,15 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } } + if position_context.directive != nil && position_in_node(position_context.directive, position_context.position) { + if str, ok := directive_docs[position_context.directive.name]; ok { + hover.contents.kind = "markdown" + hover.contents.value = str + hover.range = common.get_token_range(position_context.directive, ast_context.file.src) + return hover, true, true + } + } + if position_context.identifier != nil { if ident, ok := position_context.identifier.derived.(^ast.Ident); ok { if str, ok := keywords_docs[ident.name]; ok { @@ -323,7 +371,10 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } } - if resolved, ok := resolve_symbol_return(&ast_context, lookup(ident.name, selector.pkg, ast_context.fullpath)); ok { + if resolved, ok := resolve_symbol_return( + &ast_context, + lookup(ident.name, selector.pkg, ast_context.fullpath), + ); ok { build_documentation(&ast_context, &resolved, false) resolved.name = ident.name |