diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2023-07-24 16:45:25 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2023-07-24 16:45:25 +0200 |
| commit | 8450d82765f9ce77f9f2fb8cc75080c4c32ebc72 (patch) | |
| tree | aedb22718554fa77cc6243a3dd26e4097ef5866b /src/server | |
| parent | 967d070f1600266d0af5847bfb3bd5f4f24c0532 (diff) | |
Fix format_to_label_details out of bounds slice
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/completion.odin | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin index 88a5bea..17e8946 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -335,7 +335,12 @@ get_selector_completion :: proc( } if common.config.enable_fake_method { - append_method_completion(ast_context, selector, position_context, &items) + append_method_completion( + ast_context, + selector, + position_context, + &items, + ) } #partial switch v in selector.value { @@ -1777,47 +1782,54 @@ append_magic_union_completion :: proc( format_to_label_details :: proc(list: ^CompletionList) { // detail = left // description = right + for item in &list.items { // log.errorf("item:%v: %v:%v", item.kind, item.label, item.detail) #partial switch item.kind { - case .Function: - proc_index := strings.index(item.detail, ": proc") - // check if the function return somrthing - proc_return_index := strings.index(item.detail, "->") - if proc_return_index > 0 { - proc_end_index := strings.index(item.detail[0:proc_return_index], ")") - if proc_return_index + 2 >= len(item.detail) { - break - } - item.labelDetails = CompletionItemLabelDetails { - detail = item.detail[proc_index + 6: proc_return_index], - description = item.detail[proc_return_index + 2:] - } - item.detail = item.label - } else { - item.labelDetails = CompletionItemLabelDetails { - detail = item.detail[proc_index + 6:len(item.detail)], - description = "" - } - item.detail = "" + case .Function: + proc_index := strings.index(item.detail, ": proc") + // check if the function return somrthing + proc_return_index := strings.index(item.detail, "->") + if proc_return_index > 0 { + proc_end_index := strings.index( + item.detail[0:proc_return_index], + ")", + ) + if proc_return_index + 2 >= len(item.detail) { + break } - case .Variable, .Constant, .Field: - type_index := strings.index(item.detail, ":") item.labelDetails = CompletionItemLabelDetails { - detail = "", - description = item.detail[type_index+1:] + detail = item.detail[proc_index + 6:proc_return_index], + description = item.detail[proc_return_index + 2:], } item.detail = item.label - case .Struct, .Enum, .Class: - type_index := strings.index(item.detail, ":") + } else { + if proc_index + 6 >= len(item.detail) { + break + } item.labelDetails = CompletionItemLabelDetails { - detail = "", - description = item.detail[type_index+1:] + detail = item.detail[proc_index + 6:], + description = "", } - item.detail = item.label - case .Keyword: - item.detail = "keyword" - } + item.detail = "" + } + case .Variable, .Constant, .Field: + type_index := strings.index(item.detail, ":") + item.labelDetails = CompletionItemLabelDetails { + detail = "", + description = item.detail[type_index + 1:], + } + item.detail = item.label + case .Struct, .Enum, .Class: + type_index := strings.index(item.detail, ":") + item.labelDetails = CompletionItemLabelDetails { + detail = "", + description = item.detail[type_index + 1:], + } + item.detail = item.label + case .Keyword: + item.detail = "keyword" + } } } |