Soilihi BEN SOILIHI BOINA pushed to branch soilih at Stefan / Typer

Commits:

2 changed files:

Changes:

  • src/opslexp.ml
    ... ... @@ -772,9 +772,9 @@ and check'' erased ctx e =
    772 772
                                 | [] -> log_tc_error ~loc:l "Tuple has no field named: %s" label; etype
    
    773 773
                                 | (ak, (_, Some fn), ftype)::_ when fn = label
    
    774 774
                                   (* We found our field! *)
    
    775
    -                              -> mkSusp ftype s (*if ak = Aerasable
    
    775
    +                              -> if ak = Aerasable
    
    776 776
                                     then mkSusp ftype s (* Yay!  We found our field! *)
    
    777
    -                                else (log_tc_error ~loc:l "Can't Proj an erasale field: %s" label; etype)*)
    
    777
    +                                else (log_tc_error ~loc:l "Can't Proj an erasale field: %s" label; etype)
    
    778 778
                                 | (ak, vdef, ftype)::fieldtypes
    
    779 779
                                   ->  let fvdef vdef e loc lbl = 
    
    780 780
                                       match vdef with
    
    ... ... @@ -1139,9 +1139,9 @@ and get_type ctx e =
    1139 1139
                               | [] -> log_tc_error ~loc:l "Tuple has no field named: %s" label; etype
    
    1140 1140
                               | (ak, (_, Some fn), ftype)::_ when fn = label
    
    1141 1141
                                 (* We found our field! *)
    
    1142
    -                            -> mkSusp ftype s(*if ak = Aerasable
    
    1142
    +                            -> if ak = Aerasable
    
    1143 1143
                                   then mkSusp ftype s (* Yay!  We found our field! *)
    
    1144
    -                              else (log_tc_error ~loc:l "Can't Proj an erasale field: %s" label; etype)*)
    
    1144
    +                              else (log_tc_error ~loc:l "Can't Proj an erasale field: %s" label; etype)
    
    1145 1145
                               | (ak, vdef, ftype)::fieldtypes
    
    1146 1146
                                 ->  let fvdef vdef e loc lbl = 
    
    1147 1147
                                     match vdef with
    

  • src/typer_lsp_server.ml
    ... ... @@ -42,9 +42,23 @@ open Util
    42 42
     type list_in_list = (vname * Lexp.lexp * Lexp.ltype) list list
    
    43 43
     
    
    44 44
     type state_after_processing = (log_entry list *
    
    45
    -                              (list_in_list * Debruijn.elab_context) 
    
    45
    +                              (list_in_list * Debruijn.elab_context) * ((int * int) option ref)
    
    46 46
                                   )
    
    47 47
     
    
    48
    +(*
    
    49
    +let last_pos = ref [(0,0)]
    
    50
    +
    
    51
    +let add_to_tab tab a =
    
    52
    +  if((List.length !tab) > 4) then 
    
    53
    +    let l = List.tl(List.rev !tab) in 
    
    54
    +    tab := a::(List.rev l)
    
    55
    +  else
    
    56
    +    tab := a::(!tab)
    
    57
    +
    
    58
    +let get_pos_tab tab = 
    
    59
    +  List.hd !tab
    
    60
    +*)
    
    61
    +
    
    48 62
     (* transform a list of logs to a list of tuple
    
    49 63
     to facilitate the manipulation
    
    50 64
     *)
    
    ... ... @@ -135,14 +149,14 @@ let readstring (str:string) =
    135 149
       let ectx = Elab.default_ectx in
    
    136 150
       (*let rctx = Elab.default_rctx in*)
    
    137 151
       let ast = Elab.lexp_decl_str str ectx in   
    
    138
    -  (!Log.typer_log, ast)
    
    152
    +  (!Log.typer_log, ast, ref None)
    
    139 153
     
    
    140 154
     let process_some_input_file (_file_contents : string) : state_after_processing =
    
    141 155
       readstring _file_contents
    
    142 156
     
    
    143 157
     (*Return the diagnostics of a document state *)
    
    144 158
     let diagnostics (_state : state_after_processing) : Lsp.Types.Diagnostic.t list =
    
    145
    -  let (log, _) = _state in
    
    159
    +  let (log, _, _) = _state in
    
    146 160
       let log_tab = log_entry_to_list log in
    
    147 161
       List.map (fun x -> 
    
    148 162
                   let (loc, lev, msg) = x  in
    
    ... ... @@ -626,11 +640,11 @@ let update_the_context (ctx: Debruijn.lexp_context) (liste : list_in_list ) : (D
    626 640
                               | [] -> ()
    
    627 641
                               | (ak, (_, Some fn), ftype)::_ when fn = label
    
    628 642
                                 (* We found our field! *)
    
    629
    -                            -> if ak = Aerasable
    
    630
    -                              then 
    
    631
    -                                let a = Lexp.mkSusp ftype s in 
    
    632
    -                                candidats  := (browse_lexp ctx a cursor):: !candidats;
    
    633
    -                              else ()
    
    643
    +                            ->  if ak = Aerasable
    
    644
    +                                then 
    
    645
    +                                  let a = Lexp.mkSusp ftype s in 
    
    646
    +                                  candidats  := (browse_lexp ctx a cursor):: !candidats;
    
    647
    +                                else failwith "Fail Here!!!"
    
    634 648
                               | (ak, vdef, ftype)::fieldtypes
    
    635 649
                                 ->  let fvdef vdef e loc lbl = 
    
    636 650
                                     match vdef with
    
    ... ... @@ -805,9 +819,29 @@ let def_loc_search (ctx : Debruijn.lexp_context) (v: vref) =
    805 819
                       else tl
    
    806 820
         |hd::ml::tl ->  if (dist hd cursor < dist ml cursor ) then (foo (hd::tl) cursor)
    
    807 821
                         else foo (ml::tl) cursor
    
    808
    -in foo tab cursor
    
    822
    +  in foo tab cursor
    
    823
    +
    
    824
    +  let vn_on_the_cursor (vn:vname) (cursor:location) : bool = 
    
    825
    +      let (l,_) = vn in
    
    826
    +      if ((cursor.start_column >= l.start_column)
    
    827
    +         && (cursor.end_column <= l.end_column))
    
    828
    +      then true 
    
    829
    +      else false
    
    830
    +
    
    831
    +  let tup_browse_defs_in_ctx (lctx: Debruijn.lexp_context) (vn : vname) =
    
    832
    +    let lctx_l = Myers.list lctx in
    
    833
    +    let (_,so) = vn in 
    
    834
    +    let str = Option.get so in
    
    835
    +    let rec foo lst comp str rlst  = 
    
    836
    +      match lst with
    
    837
    +      | [] -> rlst
    
    838
    +      | ((_, Some s) as vne, _, _)::tl
    
    839
    +                -> if String.equal s str then
    
    840
    +                   foo tl (comp + 1) str ((Some (vne,comp))::rlst) 
    
    841
    +                   else foo tl (comp + 1) str rlst 
    
    842
    +      | _::tl -> foo tl (comp + 1) str rlst 
    
    843
    +    in foo lctx_l 0 str []
    
    809 844
     
    
    810
    -(*
    
    811 845
     let rec browse_defs (ctx:Debruijn.lexp_context) (e:Lexp.lexp) (cursor:Source.Location.t)  =
    
    812 846
     
    
    813 847
       match Lexp.lexp_lexp' e with
    
    ... ... @@ -824,164 +858,42 @@ let rec browse_defs (ctx:Debruijn.lexp_context) (e:Lexp.lexp) (cursor:Source.Loc
    824 858
       | Sort (_, StypeOmega) -> None
    
    825 859
       | Builtin (_, t) -> None
    
    826 860
       | Var (vn, idx) 
    
    827
    -      -> Some (e,vn,idx)        
    
    861
    +      -> Some (vn,idx)        
    
    828 862
       | Susp (e, s) -> None
    
    829 863
       | Let (l, defs, e)
    
    830 864
         -> let ctx' =
    
    831 865
             List.fold_left (fun ctx (v, _e, t)
    
    832 866
                             -> (Debruijn.lctx_extend ctx v ForwardRef t))
    
    833 867
                           ctx defs in
    
    834
    -        let rec foo ctx defs cursor ret_list = 
    
    835
    -                match defs with
    
    836
    -                | [] -> ret_list
    
    837
    -                | hd::tl -> let (vn,lxp,ltp) = hd in
    
    838
    -                            foo ctx tl cursor ((browse_defs ctx lxp cursor)::ret_list)
    
    868
    +        let rec foo (ctx_list:Debruijn.env_elem list) cursor comp = 
    
    869
    +                match ctx_list with
    
    870
    +                | [] -> failwith "No Variable in the cursor"
    
    871
    +                | ((l, (Some vn) as v),_,_)::tl 
    
    872
    +                  -> if (vn_on_the_cursor v cursor) then Some (v,comp)
    
    873
    +                     else foo tl cursor (comp + 1)
    
    874
    +                | _::tl -> foo tl cursor (comp + 1)
    
    839 875
             in
    
    840
    -        let tab = List.map 
    
    841
    -                  (fun (vn,lxp,ltp) -> 
    
    842
    -                    browse_defs ctx' lxp cursor
    
    843
    -                  )
    
    844
    -                  defs 
    
    845
    -        in
    
    846
    -        
    
    847
    -        (browse_defs ctx' e cursor)::tab           
    
    876
    +        let ctx_list = Myers.list ctx' in 
    
    877
    +        foo ctx_list cursor 0         
    
    848 878
     
    
    849 879
       | Arrow (ak, v, t1, l, t2)
    
    850
    -    -> (
    
    851
    -
    
    852
    -      let (_,_,k1,_) = browse_lexp ctx t1 cursor in
    
    853
    -      let nctx = Debruijn.lexp_ctx_cons ctx v Variable t1 in
    
    854
    -      let (_,_,k2,_) = browse_lexp nctx t2 cursor in
    
    855
    -      match Opslexp.sort_compose ctx nctx l ak k1 k2 with
    
    856
    -      | SortResult k -> (nctx, None, k, location)
    
    857
    -      | SortInvalid
    
    858
    -        -> (nctx, None, Lexp.mkSort (l, StypeOmega), location)
    
    859
    -      | SortK1NotType
    
    860
    -        -> (nctx, None, Lexp.mkSort (l, StypeOmega), location)
    
    861
    -      | SortK2NotType
    
    862
    -        -> (nctx, None, Lexp.mkSort (l, StypeOmega), location) 
    
    863
    -      )
    
    880
    +    -> None
    
    864 881
     
    
    865
    -  | Lambda (ak, ((l,_) as v), t, e) ->  let ctx' = Debruijn.lctx_extend ctx v Variable t in
    
    866
    -                                        let a = browse_lexp ctx' e cursor in
    
    867
    -                                        let b =  browse_lexp ctx t cursor in
    
    868
    -                                        (*let etp = Opslexp.get_type ctx' e in
    
    869
    -                                        let c = (ctx,None, Lexp.mkArrow (ak,v,t,l,etp),l) in*)
    
    870
    -                                        let d = (ctx,None, t,l) in
    
    871
    -                                        browse_list_lexp ([a;b;d]) cursor 
    
    882
    +  | Lambda (ak, ((l,_) as v), t, e) ->  if (vn_on_the_cursor v cursor) then
    
    883
    +                                        try List.hd (tup_browse_defs_in_ctx ctx v)
    
    884
    +                                        with exe -> None
    
    885
    +                                        else None
    
    872 886
                                         
    
    873
    -  | Call (f, args)
    
    874
    -    -> (
    
    875
    -      let fonc = browse_lexp ctx f cursor in
    
    876
    -      let args_list = List.map
    
    877
    -        (fun (_ , e) -> browse_lexp ctx e cursor)
    
    878
    -        args 
    
    879
    -      in 
    
    880
    -
    
    881
    -      browse_list_lexp (fonc::args_list) cursor
    
    882
    -      )
    
    883
    -  
    
    884
    -  | Inductive (l, _label, args, cases)
    
    885
    -    ->
    
    886
    -    (
    
    887
    -      let rec arg_loop ctx args =
    
    888
    -
    
    889
    -        match args with
    
    890
    -
    
    891
    -        | []
    
    892
    -          -> let (level, tab) =
    
    893
    -                  SMap.fold
    
    894
    -                  (fun _ case (level,tab) ->
    
    895
    -                    let ((level, _, _), tab) =
    
    896
    -                      List.fold_left
    
    897
    -                        (
    
    898
    -                          fun ((level, ictx, n), tab) (ak, v, t) ->
    
    899
    -                          (
    
    900
    -                              ((let lwhnf = Opslexp.lexp_whnf  (Opslexp.get_type ictx t) ictx in
    
    901
    -                              match Lexp.lexp_lexp' lwhnf with
    
    902
    -                              | Sort (_, Stype _)
    
    903
    -                                  when ak == Pexp.Aerasable
    
    904
    -                                -> level
    
    905
    -                              | Sort (_, Stype level')
    
    906
    -                                -> Opslexp.mkSLlub ctx level
    
    907
    -                                    (Lexp.mkSusp level' (Lexp.sunshift n))
    
    908
    -                              | _tt -> level),
    
    909
    -                            Debruijn.lctx_extend ictx v Variable t,
    
    910
    -                            n + 1), 
    
    911
    -                            ((browse_lexp ictx t cursor)::tab)
    
    912
    -                          )
    
    913
    -                        )
    
    914
    -                        ((level, ctx, 0), [] )
    
    915
    -                        case in
    
    916
    -                        (level, tab)
    
    917
    -                    )
    
    918
    -                  cases 
    
    919
    -                  (Lexp.mkSortLevel SLz, []) in 
    
    920
    -              browse_list_lexp ((ctx, None,level,l)::tab) cursor
    
    921
    -              
    
    922
    -        | (ak, v, t)::args
    
    923
    -          -> let ctx' = Debruijn.lctx_extend ctx v Variable t in
    
    924
    -            browse_list_lexp 
    
    925
    -                (
    
    926
    -                  (browse_lexp ctx' t cursor)::(arg_loop ctx' args)::[]                                                                               
    
    927
    -                ) cursor
    
    928
    -              in
    
    929
    -      arg_loop ctx args
    
    930
    -    )                 
    
    931
    -  
    
    932
    -  | Proj (l, e, (loc, label))
    
    933
    -  ->  let candidats = ref [] in
    
    934
    -      ( 
    
    935
    -      let call_split (e: Lexp.lexp) =
    
    936
    -        match Lexp.lexp_lexp' e with
    
    937
    -        | Call (f, args) -> (f, args)
    
    938
    -        | _ -> (e,[]) in
    
    939
    -      candidats  := (browse_lexp ctx e cursor):: !candidats;
    
    940
    -      let etype = Opslexp.get_type ctx e in
    
    941
    -      let it, aargs = call_split etype in
    
    942
    -          match Opslexp.lexp'_whnf it ctx, aargs with
    
    943
    -            | Inductive (_, _, fargs, constructors), aargs
    
    944
    -                when SMap.cardinal constructors = 1
    
    945
    -              -> let rec mksubst s fargs aargs =
    
    946
    -                    match fargs, aargs with
    
    947
    -                      | [], [] -> s
    
    948
    -                      | _farg::fargs, (_ak, aarg)::aargs
    
    949
    -                        -> mksubst (Subst.cons aarg s) fargs aargs
    
    950
    -                      | _,_ -> s in
    
    951
    -                  let s = mksubst Subst.identity fargs aargs in
    
    952
    -                  let (_,fieldtypes) = List.hd (SMap.bindings constructors) in
    
    953
    -                  let rec getfieldtype s (fieldtypes : (Pexp.arg_kind * vname * Lexp.ltype) list) =
    
    954
    -                      match fieldtypes with
    
    955
    -                        | [] -> ()
    
    956
    -                        | (ak, (_, Some fn), ftype)::_ when fn = label
    
    957
    -                          (* We found our field! *)
    
    958
    -                          -> if ak = Aerasable
    
    959
    -                            then 
    
    960
    -                              let a = Lexp.mkSusp ftype s in 
    
    961
    -                              candidats  := (browse_lexp ctx a cursor):: !candidats;
    
    962
    -                            else ()
    
    963
    -                        | (ak, vdef, ftype)::fieldtypes
    
    964
    -                          ->  let fvdef vdef e loc lbl = 
    
    965
    -                              match vdef with
    
    966
    -                              |(l, Some n) -> Lexp.mkProj (loc, e, lbl)
    
    967
    -                              |_ -> Lexp.impossible in
    
    968
    -                  let fieldref = fvdef vdef e l (loc, label) in 
    
    969
    -                  getfieldtype (Subst.cons fieldref s) fieldtypes in
    
    970
    -                  getfieldtype s fieldtypes; ()
    
    971
    -            | Inductive _, _
    
    972
    -              -> ()
    
    973
    -            | _,_ -> ());
    
    974
    -            browse_list_lexp !candidats cursor
    
    975
    -
    
    887
    +  | Call (f, args) ->  None
    
    888
    +  | Inductive (l, _label, args, cases) ->  None
    
    889
    +  | Proj (l, e, (loc, label)) ->  None
    
    976 890
       | Case (l, e, ret, branches, default)
    
    977
    -    -> 
    
    978
    -      let candidats = ref [] in
    
    979
    -
    
    891
    +    -> let candidats = ref [] in
    
    980 892
           let call_split (e: Lexp.lexp) =
    
    981 893
             match Lexp.lexp_lexp' e with
    
    982 894
             | Call (f, args) -> (f, args)
    
    983 895
             | _ -> (e,[]) in
    
    984
    -        candidats  := (browse_lexp ctx e cursor):: !candidats;
    
    896
    +       (* candidats  := (browse_lexp ctx e cursor):: !candidats;*)
    
    985 897
           let etype = Opslexp.get_type ctx e in
    
    986 898
           (* FIXME save the type in the case lexp instead of recomputing
    
    987 899
               it over and over again *)
    
    ... ... @@ -994,7 +906,7 @@ let rec browse_defs (ctx:Debruijn.lexp_context) (e:Lexp.lexp) (cursor:Source.Loc
    994 906
         let it, aargs = call_split etype in
    
    995 907
         (
    
    996 908
         match Opslexp.lexp'_whnf it ctx, aargs with
    
    997
    -    
    
    909
    +
    
    998 910
           | Inductive (_, _, fargs, constructors), aargs ->
    
    999 911
                 let rec mksubst s fargs aargs =
    
    1000 912
                   match fargs, aargs with
    
    ... ... @@ -1019,7 +931,7 @@ let rec browse_defs (ctx:Debruijn.lexp_context) (e:Lexp.lexp) (cursor:Source.Loc
    1019 931
                   (erased, nctx) in
    
    1020 932
                 
    
    1021 933
                 let brch = SMap.bindings branches in
    
    1022
    -            let lst = 
    
    934
    +            let _ = 
    
    1023 935
                 List.map
    
    1024 936
                 (
    
    1025 937
                 fun (name, (l, vdefs, branch))
    
    ... ... @@ -1030,7 +942,8 @@ let rec browse_defs (ctx:Debruijn.lexp_context) (e:Lexp.lexp) (cursor:Source.Loc
    1030 942
                     (* FIXME: If ak is Aerasable, make sure the var only
    
    1031 943
                       * appears in type annotations.  *)
    
    1032 944
                     | (ak, vdef)::vdefs, (_ak', _vdef', ftype)::fieldtypes
    
    1033
    -                  -> mkctx (Opslexp.dbset_push ak erased)
    
    945
    +                  ->  candidats := ((Debruijn.lexp_ctx_cons ctx vdef Variable (Lexp.mkSusp ftype s)), vdef)::!candidats;
    
    946
    +                      mkctx (Opslexp.dbset_push ak erased)
    
    1034 947
                               (Debruijn.lexp_ctx_cons ctx vdef Variable (Lexp.mkSusp ftype s))
    
    1035 948
                               (Lexp.ssink vdef s)
    
    1036 949
                               (Lexp.mkCall (Lexp.mkSusp hlxp (Subst.shift 1), [(ak, Lexp.mkVar (vdef, 0))]))
    
    ... ... @@ -1042,66 +955,33 @@ let rec browse_defs (ctx:Debruijn.lexp_context) (e:Lexp.lexp) (cursor:Source.Loc
    1042 955
                   let (nerased, nctx, hlxp) =
    
    1043 956
                     mkctx erased ctx s hctor vdefs fieldtypes in
    
    1044 957
                   let subst = Subst.shift (List.length vdefs) in
    
    1045
    -              let (nerased, nctx) = ctx_extend_with_eq nctx subst hlxp in
    
    1046
    -              candidats  := (browse_lexp nctx branch cursor) :: !candidats;
    
    958
    +              ignore(ctx_extend_with_eq nctx subst hlxp)
    
    1047 959
                 )
    
    1048 960
                 brch
    
    1049 961
                 in
    
    1050
    -
    
    1051
    -            let diff = SMap.cardinal constructors - List.length lst in
    
    1052
    -            (
    
    1053
    -            match default with
    
    1054
    -            | Some (v, d)
    
    1055
    -              -> if diff <= 0 then ();
    
    1056
    -                let nctx = (Debruijn.lctx_extend ctx v (LetDef (0, e)) etype) in
    
    1057
    -                let subst = Subst.shift 1 in
    
    1058
    -                let hlxp = Lexp.mkVar ((l, None), 0) in
    
    1059
    -                let (_, nctx) =
    
    1060
    -                  ctx_extend_with_eq nctx subst hlxp in
    
    1061
    -                candidats  := (browse_lexp nctx d cursor) :: !candidats;
    
    1062
    -                ()
    
    1063
    -            | None
    
    1064
    -                -> if diff > 0 then (); ()
    
    1065
    -            )
    
    962
    +            ()
    
    963
    +            
    
    964
    +            
    
    1066 965
           | _,_ -> () ;
    
    1067 966
         );
    
    1068
    -    browse_list_lexp !candidats cursor
    
    967
    +    let rec cands (lst: (Debruijn.lexp_context * vname) list) = 
    
    968
    +      match lst with
    
    969
    +      | [] -> failwith "No Valid Candidate"
    
    970
    +      | hd::tl -> let (ctx,(l,s)) = hd in
    
    971
    +                  if (l.start_column <= cursor.start_column 
    
    972
    +                     && l.end_column >= cursor.end_column 
    
    973
    +                    )
    
    974
    +                  then hd 
    
    975
    +                  else cands tl
    
    976
    +    in
    
    977
    +    let (lctx,vn) = cands !candidats in
    
    978
    +    List.hd (tup_browse_defs_in_ctx lctx vn)
    
    979
    +
    
    1069 980
       | Cons (t, (_l, name))
    
    1070
    -    -> (match Opslexp.lexp'_whnf t ctx with
    
    1071
    -      | Inductive (l, _, fargs, constructors)
    
    1072
    -        -> (try
    
    1073
    -              let fieldtypes = Util.SMap.find name constructors in
    
    1074
    -              let rec indtype fargs start_index =
    
    1075
    -                match fargs with
    
    1076
    -                | [] -> []
    
    1077
    -                | (ak, vd, _)::fargs -> (ak, Lexp.mkVar (vd, start_index))
    
    1078
    -                                      :: indtype fargs (start_index - 1) in
    
    1079
    -              let rec fieldargs ftypes =
    
    1080
    -                match ftypes with
    
    1081
    -                | [] -> let nargs = List.length fieldtypes + List.length fargs in
    
    1082
    -                      Lexp.mkCall (Lexp.mkSusp t (Subst.shift nargs),
    
    1083
    -                              indtype fargs (nargs - 1))
    
    1084
    -                | (ak, vd, ftype) :: ftypes
    
    1085
    -                  -> Lexp.mkArrow (ak, vd, ftype, Lexp.lexp_location ftype,
    
    1086
    -                            fieldargs ftypes) in
    
    1087
    -              let rec buildtype fargs =
    
    1088
    -                match fargs with
    
    1089
    -                | [] -> fieldargs fieldtypes
    
    1090
    -                | (_ak, ((l,_) as vd), atype) :: fargs
    
    1091
    -                  -> Lexp.mkArrow (Pexp.Aerasable, vd, atype, l,
    
    1092
    -                            buildtype fargs) in
    
    1093
    -              (ctx, None, buildtype fargs, location)
    
    1094
    -            with Not_found
    
    1095
    -                -> (ctx, None, Debruijn.type_int, location)
    
    1096
    -              )
    
    1097
    -      | _ -> (ctx, None, Debruijn.type_int, location))
    
    1098
    -  
    
    981
    +    -> None 
    
    1099 982
       | Metavar (idx, s, _)
    
    1100
    -    -> (match Lexp.metavar_lookup idx with
    
    1101
    -      | MVal e -> let e = Lexp.push_susp e s in 
    
    1102
    -                  browse_lexp ctx e cursor
    
    1103
    -      | MVar (_, t, _) -> (ctx, None, Lexp.push_susp t s, location))
    
    1104
    -*)
    
    983
    +    -> None
    
    984
    +
    
    1105 985
     (*==================================Parcourir les définitions==========================*)
    
    1106 986
     
    
    1107 987
     (* Search if the vname is in the context *)
    
    ... ... @@ -1485,6 +1365,7 @@ class lsp_server =
    1485 1365
             Lsp.Types.CompletionOptions.create ~triggerCharacters:[ "."; "#"; "\""; "'"; "/"; "@"; "<"]
    
    1486 1366
               ~resolveProvider:true () 
    
    1487 1367
           in
    
    1368
    +      (*
    
    1488 1369
           let referencesProvider = `Bool true
    
    1489 1370
           in
    
    1490 1371
           let documentHighlightProvider = `Bool true
    
    ... ... @@ -1493,7 +1374,7 @@ class lsp_server =
    1493 1374
           let documentSymbol = 
    
    1494 1375
             Lsp.Types.DocumentSymbolOptions.create ~workDoneProgress:true ()
    
    1495 1376
           in
    
    1496
    -      
    
    1377
    +      *)
    
    1497 1378
           let hoverOption =
    
    1498 1379
             Lsp.Types.HoverOptions.create ~workDoneProgress:true ()
    
    1499 1380
           in
    
    ... ... @@ -1504,16 +1385,17 @@ class lsp_server =
    1504 1385
           
    
    1505 1386
          { arg with Lsp.Types.ServerCapabilities.completionProvider = Some completionProvider ;
    
    1506 1387
                     Lsp.Types.ServerCapabilities.hoverProvider = Some (`HoverOptions hoverOption);
    
    1507
    -                Lsp.Types.ServerCapabilities.definitionProvider = Some (`DefinitionOptions definitionOption);
    
    1388
    +                Lsp.Types.ServerCapabilities.definitionProvider = Some (`DefinitionOptions definitionOption)(*;
    
    1508 1389
                     Lsp.Types.ServerCapabilities.referencesProvider = Some referencesProvider ;
    
    1509 1390
                     Lsp.Types.ServerCapabilities.documentHighlightProvider = Some documentHighlightProvider;
    
    1510
    -                Lsp.Types.ServerCapabilities.documentSymbolProvider = Some (`DocumentSymbolOptions documentSymbol)
    
    1391
    +                Lsp.Types.ServerCapabilities.documentSymbolProvider = Some (`DocumentSymbolOptions documentSymbol)*)
    
    1511 1392
          }
    
    1512 1393
     
    
    1513 1394
         method! on_req_definition ~notify_back ~id ~uri ~pos _st =
    
    1514 1395
           match Hashtbl.find buffers uri with
    
    1515 1396
           
    
    1516
    -      | state_after_processing -> let (_,ast) = state_after_processing in
    
    1397
    +      | state_after_processing -> let (_,ast,cur) = state_after_processing in
    
    1398
    +                                  cur := Some (pos.line,pos.character);
    
    1517 1399
                                       let (list_list, _) = ast in 
    
    1518 1400
                                       let typer_loc = typer_pos_of_lsp_pos pos in
    
    1519 1401
                                       let ctx = Debruijn.ectx_to_lctx (Elab.default_ectx) in 
    
    ... ... @@ -1531,7 +1413,8 @@ class lsp_server =
    1531 1413
         method! on_req_hover ~notify_back ~id ~uri ~pos doc_state =
    
    1532 1414
           match Hashtbl.find buffers uri with
    
    1533 1415
     
    
    1534
    -    | state_after_processing -> let (_,ast) = state_after_processing in
    
    1416
    +    | state_after_processing -> let (_,ast,cur) = state_after_processing in
    
    1417
    +                                cur := Some (pos.line,pos.character);
    
    1535 1418
                                     let (list_list, ectx) = ast in   
    
    1536 1419
                                     let typer_loc = typer_pos_of_lsp_pos pos in
    
    1537 1420
                                     let ctx = Debruijn.ectx_to_lctx (Elab.default_ectx) in
    
    ... ... @@ -1546,7 +1429,7 @@ class lsp_server =
    1546 1429
                                     in
    
    1547 1430
                                     (*let s = Lexp.lexp_string_for_lsp l_type in*)
    
    1548 1431
                                     let r = Lsp.Types.Hover.create
    
    1549
    -                                  ~contents:(`MarkedString {Lsp.Types.MarkedString.value=s; language=None})
    
    1432
    +                                  ~contents:(`MarkedString {Lsp.Types.MarkedString.value=s; language=(Some "Typer")})
    
    1550 1433
                                       ~range:range ()
    
    1551 1434
                                     in
    
    1552 1435
                                     let e = Some r in 
    
    ... ... @@ -1556,7 +1439,8 @@ class lsp_server =
    1556 1439
         method! on_req_completion  ~notify_back ~id ~uri ~pos ~ctx doc_state = 
    
    1557 1440
           match Hashtbl.find buffers uri with
    
    1558 1441
     
    
    1559
    -      | state_after_processing -> let (_,ast) = state_after_processing in
    
    1442
    +      | state_after_processing -> let (_,ast,cur) = state_after_processing in
    
    1443
    +                                  cur := Some (pos.line,pos.character);
    
    1560 1444
                                       let (list_list, _) = ast in   
    
    1561 1445
                                       let typer_loc = typer_pos_of_lsp_pos pos in
    
    1562 1446
                                       let ctx = Debruijn.ectx_to_lctx (Elab.default_ectx) in
    
    ... ... @@ -1601,7 +1485,7 @@ class lsp_server =
    1601 1485
                                       let e = Some (`DocumentSymbol r) in
    
    1602 1486
                                       let f = Linol_lwt.return e in f
    
    1603 1487
         
    
    1604
    -
    
    1488
    +    
    
    1605 1489
         method! on_request_unhandled ~notify_back ~id req =
    
    1606 1490
     
    
    1607 1491
         let f :type r. r Lsp.Client_request.t -> r Linol_lwt.Jsonrpc2.IO.t =  
    
    ... ... @@ -1643,7 +1527,7 @@ class lsp_server =
    1643 1527
           | _ -> super#on_request_unhandled ~notify_back ~id req
    
    1644 1528
         ) 
    
    1645 1529
         in f req
    
    1646
    -    *)                     
    
    1530
    +    *)                    
    
    1647 1531
     end
    
    1648 1532
     
    
    1649 1533
     
    
    ... ... @@ -1654,7 +1538,7 @@ let comp (a:string) (b:string) : string =
    1654 1538
         else "/*******-----:-(:-(:-(:-(:-(:-(:-(____FAILED___:-(:-(:-(:-(:-(:-(:-(-----*******/\n\n\n"
    
    1655 1539
         
    
    1656 1540
     let hoverTest (ctx:Debruijn.lexp_context) (name:string) (content:string)  (position: int * int) (expected:string) = 
    
    1657
    -  let (_, ast) = readstring content in 
    
    1541
    +  let (_, ast,_) = readstring content in 
    
    1658 1542
       let (list_list, _) = ast in
    
    1659 1543
       let (l,c) = position in
    
    1660 1544
       let pos = pos_of_tuple position in
    
    ... ... @@ -1796,7 +1680,13 @@ let test () =
    1796 1680
       hoverTest ctx name "foo x = case x\n\n| true => \"true\"\n\n|  false => \"false\" ;" (5,4) "";
    
    1797 1681
       hoverTest ctx name "foo x = case x\n\n| true => \"true\"\n\n|  false => \"false\" ;" (5,14) ""
    
    1798 1682
       
    
    1799
    - 
    
    1683
    +  
    
    1684
    +let time f a b =
    
    1685
    +  let t = Sys.time() in
    
    1686
    +  let fx = f a b in
    
    1687
    +  Printf.printf "Execution time: %fs\n" (Sys.time() -. t);
    
    1688
    +  fx
    
    1689
    +
    
    1800 1690
     
    
    1801 1691
     (*=======================================Test======================================*)
    
    1802 1692