diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2021-03-12 16:31:09 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2021-03-12 16:31:09 +0100 |
| commit | 00ccd7e03e17dac40efb9b34a048d968dd77c218 (patch) | |
| tree | 24e9e8d9743bc3e98b63183d1f976b11ab6d93d2 /src/server/hover.odin | |
| parent | baf86e02a2c45170d58ab828a13f52361129b255 (diff) | |
ran odinfmt on project
Diffstat (limited to 'src/server/hover.odin')
| -rw-r--r-- | src/server/hover.odin | 242 |
1 files changed, 117 insertions, 125 deletions
diff --git a/src/server/hover.odin b/src/server/hover.odin index cd09f01..08d49ca 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -16,131 +16,123 @@ import "core:slice" import "shared:common" import "shared:index" -get_hover_information :: proc(document: ^Document, position: common.Position) -> (Hover, bool) { +get_hover_information :: proc (document: ^Document, position: common.Position) -> (Hover, bool) { + + hover := Hover { + contents = { + kind = "plaintext" + } + }; + + ast_context := make_ast_context(document.ast, document.imports, document.package_name); - hover := Hover { - contents = { - kind = "plaintext", - } - }; + position_context, ok := get_document_position_context(document, position, .Hover); + + get_globals(document.ast, &ast_context); - ast_context := make_ast_context(document.ast, document.imports, document.package_name); - - position_context, ok := get_document_position_context(document, position, .Hover); - - get_globals(document.ast, &ast_context); - - if position_context.function != nil { - get_locals(document.ast, position_context.function, &ast_context, &position_context); - } - - if position_context.identifier != nil { - if ident, ok := position_context.identifier.derived.(ast.Ident); ok { - if _, ok := common.keyword_map[ident.name]; ok { - hover.contents.kind = "plaintext"; - hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src); - return hover, true; - } - } - } - - if position_context.selector != nil && position_context.identifier != nil { - - hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src); - - ast_context.use_locals = true; - ast_context.use_globals = true; - ast_context.current_package = ast_context.document_package; - - //if the base selector is the client wants to go to. - if base, ok := position_context.selector.derived.(ast.Ident); ok && position_context.identifier != nil { - - ident := position_context.identifier.derived.(ast.Ident); - - if ident.name == base.name { - - if resolved, ok := resolve_type_identifier(&ast_context, ident); ok { - resolved.name = ident.name; - resolved.signature = get_signature(&ast_context, ident, resolved); - - if is_variable, ok := ast_context.variables[ident.name]; ok && is_variable { - resolved.pkg = ast_context.document_package; - } - - hover.contents = write_hover_content(&ast_context, resolved); - return hover, true; - } - - } - - } - - selector: index.Symbol; - selector, ok = resolve_type_expression(&ast_context, position_context.selector); - - if !ok { - return hover, true; - } - - field: string; - - if position_context.field != nil { - - switch v in position_context.field.derived { - case ast.Ident: - field = v.name; - } - - } - - hover.range = common.get_token_range(position_context.identifier^, document.ast.src); - - #partial switch v in selector.value { - case index.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 { - symbol.name = name; - symbol.pkg = selector.name; - symbol.signature = index.node_to_string(v.types[i]); - hover.contents = write_hover_content(&ast_context, symbol); - return hover, true; - } - } - } - case index.SymbolPackageValue: - if symbol, ok := index.lookup(field, selector.pkg); ok { - hover.contents = write_hover_content(&ast_context, symbol); - return hover, true; - } - } - - } - - else if position_context.identifier != nil { - - ast_context.use_locals = true; - ast_context.use_globals = true; - ast_context.current_package = ast_context.document_package; - - ident := position_context.identifier.derived.(ast.Ident); - - hover.range = common.get_token_range(position_context.identifier^, document.ast.src); - - if resolved, ok := resolve_type_identifier(&ast_context, ident); ok { - resolved.name = ident.name; - resolved.signature = get_signature(&ast_context, ident, resolved); - - if is_variable, ok := ast_context.variables[ident.name]; ok && is_variable { - resolved.pkg = ast_context.document_package; - } - - hover.contents = write_hover_content(&ast_context, resolved); - return hover, true; - } - - } - - return hover, true; -} + if position_context.function != nil { + get_locals(document.ast, position_context.function, &ast_context, &position_context); + } + if position_context.identifier != nil { + if ident, ok := position_context.identifier.derived.(ast.Ident); ok { + if _, ok := common.keyword_map[ident.name]; ok { + hover.contents.kind = "plaintext"; + hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src); + return hover, true; + } + } + } + + if position_context.selector != nil && position_context.identifier != nil { + + hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src); + + ast_context.use_locals = true; + ast_context.use_globals = true; + ast_context.current_package = ast_context.document_package; + + //if the base selector is the client wants to go to. + if base, ok := position_context.selector.derived.(ast.Ident); ok && position_context.identifier != nil { + + ident := position_context.identifier.derived.(ast.Ident); + + if ident.name == base.name { + + if resolved, ok := resolve_type_identifier(&ast_context, ident); ok { + resolved.name = ident.name; + resolved.signature = get_signature(&ast_context, ident, resolved); + + if is_variable, ok := ast_context.variables[ident.name]; ok && is_variable { + resolved.pkg = ast_context.document_package; + } + + hover.contents = write_hover_content(&ast_context, resolved); + return hover, true; + } + } + } + + selector: index.Symbol; + selector, ok = resolve_type_expression(&ast_context, position_context.selector); + + if !ok { + return hover, true; + } + + field: string; + + if position_context.field != nil { + + switch v in position_context.field.derived { + case ast.Ident: + field = v.name; + } + } + + hover.range = common.get_token_range(position_context.identifier^, document.ast.src); + + #partial switch v in selector.value { + case index.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 { + symbol.name = name; + symbol.pkg = selector.name; + symbol.signature = index.node_to_string(v.types[i]); + hover.contents = write_hover_content(&ast_context, symbol); + return hover, true; + } + } + } + case index.SymbolPackageValue: + if symbol, ok := index.lookup(field, selector.pkg); ok { + hover.contents = write_hover_content(&ast_context, symbol); + return hover, true; + } + } + } else if position_context.identifier != nil { + + ast_context.use_locals = true; + ast_context.use_globals = true; + ast_context.current_package = ast_context.document_package; + + ident := position_context.identifier.derived.(ast.Ident); + + hover.range = common.get_token_range(position_context.identifier^, document.ast.src); + + if resolved, ok := resolve_type_identifier(&ast_context, ident); ok { + resolved.name = ident.name; + resolved.signature = get_signature(&ast_context, ident, resolved); + + if is_variable, ok := ast_context.variables[ident.name]; ok && is_variable { + resolved.pkg = ast_context.document_package; + } + + hover.contents = write_hover_content(&ast_context, resolved); + return hover, true; + } + } + + return hover, true; +}
\ No newline at end of file |