From 0da804aac2e7b76d2cf75436fc5a1b005ea27b75 Mon Sep 17 00:00:00 2001 From: ryuukk Date: Fri, 30 Jun 2023 23:52:40 +0200 Subject: use a switch instead and add fields support --- src/server/completion.odin | 61 +++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'src/server') diff --git a/src/server/completion.odin b/src/server/completion.odin index a483bd0..a597ecc 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1772,41 +1772,42 @@ format_to_label_details :: proc(list: ^CompletionList) { // description = right for item in &list.items { // log.errorf("item:%v: %v:%v", item.kind, item.label, item.detail) - if item.kind == .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], ")") + #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], ")") + item.labelDetails = CompletionItemLabelDetails { + detail = item.detail[proc_index + 6: proc_return_index], + description = item.detail[proc_return_index:] + } + item.detail = item.label + } else { + item.labelDetails = CompletionItemLabelDetails { + detail = item.detail[proc_index + 6:len(item.detail)], + description = "" + } + item.detail = "" + } + case .Variable, .Constant, .Field: + type_index := strings.index(item.detail, ":") item.labelDetails = CompletionItemLabelDetails { - detail = item.detail[proc_index + 6: proc_return_index], - description = item.detail[proc_return_index:] + detail = "", + description = item.detail[type_index+1:] } item.detail = item.label - } else { + case .Struct, .Enum, .Class: + type_index := strings.index(item.detail, ":") item.labelDetails = CompletionItemLabelDetails { - detail = item.detail[proc_index + 6:len(item.detail)], - description = "" + detail = "", + description = item.detail[type_index+1:] } - item.detail = "" - } - } else if item.kind == .Variable || item.kind == .Constant { - type_index := strings.index(item.detail, ":") - item.labelDetails = CompletionItemLabelDetails { - detail = "", - description = item.detail[type_index+1:] - } - item.detail = item.label - } else if item.kind == .Struct || item.kind == .Enum || item.kind == .Class { - type_index := strings.index(item.detail, ":") - item.labelDetails = CompletionItemLabelDetails { - detail = "", - description = item.detail[type_index+1:] - } - item.detail = item.label - } else if item.kind == .Keyword { - item.detail = "keyword" - } + item.detail = item.label + case .Keyword: + item.detail = "keyword" + } } } -- cgit v1.2.3