diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2021-05-07 17:02:52 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2021-05-07 17:02:52 +0200 |
| commit | b3548adc1efcb143767e63d370efed1a60f724c5 (patch) | |
| tree | de87c64991f7fdfdf38fd6405574339c63c0516c /src | |
| parent | 1d5897230e1387fd6fe861b7fa59066361d27a11 (diff) | |
make sure complex calls is handled correctly with comma positions
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/analysis.odin | 20 | ||||
| -rw-r--r-- | src/server/signature.odin | 34 |
2 files changed, 45 insertions, 9 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 8c68252..999c7c1 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2284,11 +2284,27 @@ get_call_commas :: proc(position_context: ^DocumentPositionContext, document: ^D commas := make([dynamic]int, 0, 10, context.temp_allocator); + paren_count := 0; + bracket_count := 0; + brace_count := 0; + if call, ok := position_context.call.derived.(ast.Call_Expr); ok { + if document.text[call.open.offset] == '(' { + paren_count -= 1; + } for i := call.open.offset; i < call.close.offset; i += 1 { - if document.text[i] == ',' { - append(&commas, i); + switch document.text[i] { + case '[': paren_count += 1; + case ']': paren_count -= 1; + case '{': brace_count += 1; + case '}': brace_count -= 1; + case '(': paren_count += 1; + case ')': paren_count -= 1; + case ',': + if paren_count == 0 && brace_count == 0 && bracket_count == 0 { + append(&commas, i); + } } } } diff --git a/src/server/signature.odin b/src/server/signature.odin index 181adbe..fb3f8e6 100644 --- a/src/server/signature.odin +++ b/src/server/signature.odin @@ -45,6 +45,7 @@ SignatureInformation :: struct { ParameterInformation :: struct { label: string, + activeParameter: int, } /* @@ -154,14 +155,33 @@ get_signature_information :: proc(document: ^Document, position: common.Position symbol := symbol; - build_symbol_signature(&symbol); - build_symbol_return(&symbol); + if value, ok := symbol.value.(index.SymbolProcedureValue); ok { + + parameters := make([]ParameterInformation, len(value.arg_types), context.temp_allocator); + + for arg, i in value.arg_types { + + if arg.type != nil { + if _, is_ellipsis := arg.type.derived.(ast.Ellipsis); is_ellipsis { + signature_help.activeParameter = min(i, signature_help.activeParameter); + } + } + + parameters[i].label = common.node_to_string(arg); + parameters[i].activeParameter = i; + } + + build_symbol_signature(&symbol); + build_symbol_return(&symbol); - info := SignatureInformation { - label = concatenate_symbols_information(&ast_context, symbol, false), - documentation = symbol.doc, - }; - append(&signature_information, info); + info := SignatureInformation { + label = concatenate_symbols_information(&ast_context, symbol, false), + documentation = symbol.doc, + parameters = parameters, + }; + + append(&signature_information, info); + } } } |