diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-06-12 02:00:31 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-06-12 02:00:31 +0200 |
| commit | a2f3b5ddb1bb77b2736150d57ec6eee2bcfd0e55 (patch) | |
| tree | 020399d3bb094cf10191b062f0c4bd6b568db895 | |
| parent | 12a1db1e284e4ce2af9a51bb60f9817e76c1a481 (diff) | |
Add custom hover map
| -rw-r--r-- | src/server/analysis.odin | 4 | ||||
| -rw-r--r-- | src/server/documents.odin | 4 | ||||
| -rw-r--r-- | src/server/hover.odin | 20 |
3 files changed, 24 insertions, 4 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 09564ba..62b3da9 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -31,6 +31,7 @@ DocumentPositionContext :: struct { function: ^ast.Proc_Lit, //used to help with type resolving in function scope selector: ^ast.Expr, //used for completion identifier: ^ast.Node, + implicit_context: ^ast.Implicit, tag: ^ast.Node, field: ^ast.Expr, //used for completion call: ^ast.Expr, //used for signature help @@ -3213,6 +3214,9 @@ get_document_position_node :: proc(node: ^ast.Node, position_context: ^DocumentP case ^Ident: position_context.identifier = node case ^Implicit: + if n.tok.text == "context" { + position_context.implicit_context = n + } case ^Undef: case ^Basic_Lit: case ^Ellipsis: diff --git a/src/server/documents.odin b/src/server/documents.odin index 8750720..8142524 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -374,10 +374,6 @@ parse_document :: proc(document: ^common.Document, config: ^common.Config) -> ([ parser.parse_file(&p, &document.ast) - if len(document.ast.decls) >= 1 { - log.error(document.ast.decls[0]) - } - parse_imports(document, config) return current_errors[:], true diff --git a/src/server/hover.odin b/src/server/hover.odin index 25975c0..39b9a33 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -43,6 +43,10 @@ write_hover_content :: proc(ast_context: ^AstContext, symbol: Symbol) -> MarkupC return content } +builtin_identifier_hover: map[string]string = { + "context" = fmt.aprintf("```odin\n %v\n```\n%v", "runtime.context: Context", "This context variable is local to each scope and is implicitly passed by pointer to any procedure call in that scope (if the procedure has the Odin calling convention)."), +} + get_hover_information :: proc(document: ^common.Document, position: common.Position) -> (Hover, bool) { hover := Hover { @@ -68,6 +72,22 @@ get_hover_information :: proc(document: ^common.Document, position: common.Posit hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src) return hover, true } + + if str, ok := builtin_identifier_hover[ident.name]; ok { + hover.contents.kind = "markdown" + hover.contents.value = str + hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src) + return hover, true + } + } + } + + if position_context.implicit_context != nil { + if str, ok := builtin_identifier_hover[position_context.implicit_context.tok.text]; ok { + hover.contents.kind = "markdown" + hover.contents.value = str + hover.range = common.get_token_range(position_context.implicit_context^, ast_context.file.src) + return hover, true } } |