diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/analysis.odin | 36 | ||||
| -rw-r--r-- | src/server/completion.odin | 1 | ||||
| -rw-r--r-- | src/server/definition.odin | 17 | ||||
| -rw-r--r-- | src/server/hover.odin | 26 | ||||
| -rw-r--r-- | src/server/references.odin | 6 | ||||
| -rw-r--r-- | src/server/rename.odin | 10 | ||||
| -rw-r--r-- | src/server/signature.odin | 3 |
7 files changed, 86 insertions, 13 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 668260b..f13fad9 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -102,6 +102,7 @@ AstContext :: struct { fullpath: string, non_mutable_only: bool, //Only store local value declarations that are non mutable. overloading: bool, + position_hint: DocumentPositionContextHint, } make_ast_context :: proc( @@ -562,10 +563,31 @@ get_field_list_name_index :: proc(name: string, field_list: []^ast.Field) -> (in return 0, false } +get_unnamed_arg_count :: proc(args: []^ast.Expr) -> int { + total := 0 + for arg in args { + if field, is_field := arg.derived.(^ast.Field_Value); !is_field { + total += 1 + } + } + return total +} + +get_unnamed_field_count :: proc(fields: []^ast.Field) -> int { + total := 0 + for field in fields { + if field.default_value == nil { + total += len(field.names) + } + } + return total +} + /* Figure out which function the call expression is using out of the list from proc group */ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Group) -> (Symbol, bool) { + resolve_all_possibilities := ast_context.position_hint == .Completion || ast_context.position_hint == .SignatureHelp old_overloading := ast_context.overloading ast_context.overloading = true @@ -577,24 +599,32 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou call_expr := ast_context.call - //If there is nothing to resolve from, we actually want to get the invalid overloaded results through setting overloading to false if call_expr == nil || len(call_expr.args) == 0 { ast_context.overloading = false } + call_unnamed_arg_count := 0 + if call_expr != nil { + call_unnamed_arg_count = get_unnamed_arg_count(call_expr.args) + } candidates := make([dynamic]Symbol, context.temp_allocator) for arg_expr in group.args { next_fn: if f, ok := internal_resolve_type_expression(ast_context, arg_expr); ok { - if call_expr == nil || len(call_expr.args) == 0 { + if call_expr == nil || (resolve_all_possibilities && len(call_expr.args) == 0) { append(&candidates, f) break next_fn } - if procedure, ok := f.value.(SymbolProcedureValue); ok { i := 0 named := false + if !resolve_all_possibilities { + unnamed_field_count := get_unnamed_field_count(procedure.arg_types) + if call_expr != nil && unnamed_field_count != call_unnamed_arg_count { + break next_fn + } + } for proc_arg in procedure.arg_types { for name in proc_arg.names { if i >= len(call_expr.args) { diff --git a/src/server/completion.odin b/src/server/completion.odin index 8d61e3e..c554841 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -73,6 +73,7 @@ get_completion_list :: proc( document.uri.uri, document.fullpath, ) + ast_context.position_hint = position_context.hint get_globals(document.ast, &ast_context) diff --git a/src/server/definition.odin b/src/server/definition.odin index 0a216cc..7957b9d 100644 --- a/src/server/definition.odin +++ b/src/server/definition.odin @@ -47,13 +47,6 @@ get_definition_location :: proc(document: ^Document, position: common.Position) location: common.Location - ast_context := make_ast_context( - document.ast, - document.imports, - document.package_name, - document.uri.uri, - document.fullpath, - ) uri: string @@ -64,6 +57,16 @@ get_definition_location :: proc(document: ^Document, position: common.Position) return {}, false } + ast_context := make_ast_context( + document.ast, + document.imports, + document.package_name, + document.uri.uri, + document.fullpath, + ) + + ast_context.position_hint = position_context.hint + get_globals(document.ast, &ast_context) if position_context.function != nil { diff --git a/src/server/hover.odin b/src/server/hover.odin index cc3c5b2..9c4d33a 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -71,6 +71,12 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> ) position_context, ok := get_document_position_context(document, position, .Hover) + if !ok { + log.warn("Failed to get position context") + return hover, false, false + } + + ast_context.position_hint = position_context.hint get_globals(document.ast, &ast_context) @@ -227,8 +233,24 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> case SymbolPackageValue: if position_context.field != nil { if ident, ok := position_context.field.derived.(^ast.Ident); ok { - if symbol, ok := resolve_type_identifier(&ast_context, ident^); ok { - hover.contents = write_hover_content(&ast_context, symbol) + // check to see if we are in a position call context + if position_context.call != nil && ast_context.call == nil { + if call, ok := position_context.call.derived.(^ast.Call_Expr); ok { + if !position_in_exprs(call.args, position_context.position) { + ast_context.call = call + } + } + } + if resolved, ok := resolve_type_identifier(&ast_context, ident^); ok { + resolved.signature = get_signature(&ast_context, ident^, resolved) + resolved.name = ident.name + + if resolved.type == .Variable { + resolved.pkg = ast_context.document_package + } + + + hover.contents = write_hover_content(&ast_context, resolved) return hover, true, true } } diff --git a/src/server/references.odin b/src/server/references.odin index 944a337..cada3af 100644 --- a/src/server/references.odin +++ b/src/server/references.odin @@ -347,6 +347,12 @@ get_references :: proc(document: ^Document, position: common.Position) -> ([]com ) position_context, ok := get_document_position_context(document, position, .Hover) + if !ok { + log.warn("Failed to get position context") + return {}, false + } + + ast_context.position_hint = position_context.hint get_globals(document.ast, &ast_context) diff --git a/src/server/rename.odin b/src/server/rename.odin index 5e02af6..786104a 100644 --- a/src/server/rename.odin +++ b/src/server/rename.odin @@ -20,6 +20,11 @@ get_rename :: proc(document: ^Document, new_text: string, position: common.Posit ) position_context, ok := get_document_position_context(document, position, .Hover) + if !ok { + log.warn("Failed to get position context") + return {}, false + } + ast_context.position_hint = position_context.hint get_globals(document.ast, &ast_context) @@ -70,6 +75,11 @@ get_prepare_rename :: proc(document: ^Document, position: common.Position) -> (c ) position_context, ok := get_document_position_context(document, position, .Hover) + if !ok { + log.warn("Failed to get position context") + return {}, false + } + ast_context.position_hint = position_context.hint get_globals(document.ast, &ast_context) diff --git a/src/server/signature.odin b/src/server/signature.odin index 5cc4c05..5dd910b 100644 --- a/src/server/signature.odin +++ b/src/server/signature.odin @@ -124,10 +124,11 @@ get_signature_information :: proc(document: ^Document, position: common.Position ) position_context, ok := get_document_position_context(document, position, .SignatureHelp) - if !ok { + log.warn("Failed to get position context") return signature_help, true } + ast_context.position_hint = position_context.hint //TODO(should probably not be an ast.Expr, but ast.Call_Expr) if position_context.call == nil { |