Soilihi BEN SOILIHI BOINA pushed to branch soilih at Stefan / Typer
Commits: 6c5dfc8b by Soilih BEN SOILIH at 2021-09-03T15:25:55-06:00 considering the order in the completion suggestions
- - - - -
1 changed file:
- src/typer_lsp_server.ml
Changes:
===================================== src/typer_lsp_server.ml ===================================== @@ -869,15 +869,46 @@ let lsp_compl_from_var (ret : Debruijn.lexp_context * (((Source.Location.t * str then r := !r + 1 else r := !r + 0 done; - Int.equal !r (String.length substr) - + Int.equal !r (String.length substr) + + let str_to_char_list (str: string) : char list = + let char_list = ref [] in + for i=0 to ((String.length str) - 1) do + char_list := (str.[i])::(!char_list) + done; + List.rev !char_list + + let char_list_to_str (char_list: char list) : string = + match char_list with + | [] -> "" + | _ -> List.fold_left (fun x y -> x ^ (String.make 1 y)) "" char_list + + + let rec str_order (substr:string) (str:string) : bool = + match str_to_char_list substr with + | [] -> false + | [hd] -> string_contain (String.make 1 hd) str + | [hd;tl] -> let ihd = String.index str hd in + let itl = String.index str tl in + if (ihd < itl) then true + else false + | hd::ml::tl -> let ihd = String.index str hd in + let iml = String.index str ml in + if ( ihd < iml ) then + str_order (char_list_to_str (ml::tl)) str + else false + (* Filter completions list by a string *) let complete_oth (str:string) (liste: Lsp.Types.CompletionItem.t list) = match liste with | [] -> liste - | _ -> List.filter (fun (x:Lsp.Types.CompletionItem.t) -> - string_contain str x.label - ) liste + | _ -> let lst = List.filter (fun (x:Lsp.Types.CompletionItem.t) -> + string_contain str x.label + ) liste + in + List.filter (fun (x:Lsp.Types.CompletionItem.t) -> + str_order str x.label + ) lst (* List of separators that delimit a word *) let sep_list = [';';',';'(';')';'.';' ';'{';'}']
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/6c5dfc8bb50bdabb58d4d79445221978ae...
Afficher les réponses par date