Soilihi BEN SOILIHI BOINA pushed to branch minimal-server at Stefan / Typer
Commits: 30526f2f by Soilih at 2022-05-16T02:06:00-04:00 -
- - - - - 2c27abb1 by Soilih at 2022-05-16T13:56:35-04:00 -
- - - - - 7795c2bd by Soilih at 2022-05-16T16:24:57-04:00 fixing completion order problem
- - - - -
1 changed file:
- src/typer_lsp_server.ml
Changes:
===================================== src/typer_lsp_server.ml ===================================== @@ -686,45 +686,45 @@ let ctx_to_ci_list (lctx : Debruijn.env_elem list) (range:Lsp.Types.Range.t) =
(* Verify if a string contains some other *) let string_contain (substr:string) (str:string) : bool = -let r = ref 0 in -for i=0 to ((String.length substr) - 1) do - if ( - String.contains str (Char.lowercase_ascii substr.[i]) - || String.contains str (Char.uppercase_ascii substr.[i]) - ) - then r := !r + 1 - else r := !r + 0 -done; -Int.equal !r (String.length substr) + let r = ref 0 in + for i = 0 to ((String.length substr) - 1) do + if ( + String.contains str (Char.lowercase_ascii substr.[i]) + || String.contains str (Char.uppercase_ascii substr.[i]) + ) + then r := !r + 1 + else r := !r + 0 + done; + 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 = 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 + match char_list with + | [] -> "" + | _ -> List.fold_left (fun x y -> x ^ (String.make 1 y)) "" char_list
let char_index (str:string) (chr:char) : int = -try String.index str chr -with _ -> String.index str (Char.uppercase_ascii chr) + try String.index str (Char.lowercase_ascii chr) + with _ -> String.index str (Char.uppercase_ascii chr) 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 = char_index str hd in - let itl = char_index str tl in - if (ihd < itl) then true - else false -| hd::ml::tl -> let ihd = char_index str hd in - let iml = char_index str ml in - if ( ihd < iml ) then - str_order (char_list_to_str (ml::tl)) str + match str_to_char_list substr with + | [] -> false + | [hd] -> string_contain (String.make 1 hd) str + | [hd;tl] -> let ihd = char_index str hd in + let itl = char_index str tl in + if (ihd < itl) then true else false + | hd::ml::tl -> let ihd = char_index str hd in + let iml = char_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 *) @@ -891,7 +891,7 @@ let browse_list_defs (tab : Source.Location.t list) (cursor:Source.Location.t) = let ret' = List.fold_right (fun (_, ( _, l, lxp)) ret -> let j = List.length l in find_references lxp vr (idx_vr + j) ret - ) lst [] + ) lst ret in find_references e vr idx_vr (find_references retu vr idx_vr ret') @@ -923,7 +923,7 @@ let browse_list_defs (tab : Source.Location.t list) (cursor:Source.Location.t) = -> let idx = (List.length defs) - 1 in let rec foo (ctx_list: (vname * Lexp.lexp * Lexp.lexp) list) cursor comp = match ctx_list with - | [] -> failwith "No Variable in the cursor" + | [] -> failwith "No Variable on the cursor" | ((_, (Some _) as v),_,_)::tl -> if (vn_on_the_cursor v cursor) then Some (el, v, comp - idx) else foo tl cursor (comp + 1) @@ -954,22 +954,23 @@ let browse_list_defs (tab : Source.Location.t list) (cursor:Source.Location.t) = | Proj (_, e, (_, _)) -> browse_defs e cursor | Case (_, e, _, branches, _) -> - let (vn, lxp, comp) = SMap.fold - (fun _name (_l, vdefs, branch) (_lst: vname * Lexp.lexp * int) - -> let rec collect vdefs comp = - match vdefs with - | [] -> failwith "Cursor is not on any branch !" - | (_, vdef)::vdefs - -> if (vn_on_the_cursor vdef cursor) then (vdef, branch, List.length vdefs) - else collect vdefs (comp + 1) - in - collect vdefs 0 - ) - branches ((Source.Location.dummy, Some ""), Lexp.impossible, 0) - in - if (Lexp.hc_eq lxp Lexp.impossible) then - browse_defs e cursor - else Some (lxp, vn, comp) + let ret = SMap.fold + (fun _name (_l, vdefs, branch) (_lst: (Lexp.lexp * vname * int) option) + -> let rec collect vdefs = + match vdefs with + | [] -> browse_defs branch cursor + | (_, vdef)::vdefs + -> if (vn_on_the_cursor vdef cursor) then Some (branch, vdef, List.length vdefs) + else collect vdefs + in + collect vdefs + ) + branches (Some (Lexp.impossible, (Source.Location.dummy, Some ""), 0)) + in + let (lxp, _, _) = Option.get ret in + if (Lexp.hc_eq lxp Lexp.impossible) then + browse_defs e cursor + else ret
| Cons _ -> None | Metavar _ -> None @@ -1219,9 +1220,11 @@ class lsp_server = let (list_list, _) = Option.get ast in let typer_loc = typer_pos_of_lsp_pos pos in let ctx = Debruijn.ectx_to_lctx (Elab.default_ectx) in + (* let (lctx,vx) = lexp_search_deeper ctx list_list typer_loc in let (_, lexp, _) = vx in - (*let lexp = trans_list_in_list_to_let list_list in*) + *) + let lexp = trans_list_in_list_to_let list_list in
(* let trans_string = Compl.tranform_string doc_state.content in @@ -1229,7 +1232,7 @@ class lsp_server = let word = Compl.find_the_nearest_compl fbyline ((pos.line + 1),pos.character) in *)
- match browse_lexp lctx lexp typer_loc [] with + match browse_lexp ctx lexp typer_loc [] with
| (l_ctx,_,_, None,_,_) ->
View it on GitLab: https://gitlab.com/monnier/typer/-/compare/d92349b72ccf64b5dcc6b2e12bc260fba...