Soilihi BEN SOILIHI BOINA pushed to branch soilih at Stefan / Typer
Commits: 5ee099ae by Soilih BEN SOILIH at 2021-04-21T09:39:33-06:00 m
- - - - - 79fc9315 by Soilih BEN SOILIH at 2021-04-21T09:50:16-06:00 -*
- - - - - 8ad9bedf by Soilih BEN SOILIH at 2021-04-23T03:21:14-06:00 -
- - - - - 3eb5e83e by Soilih BEN SOILIH at 2021-04-23T04:07:32-06:00 hover and definition update
- - - - -
2 changed files:
- samples/soilih.typer - src/typer_lsp_server.ml
Changes:
===================================== samples/soilih.typer ===================================== @@ -1 +1,3 @@ -let a = 3 b = 4 in a + b ; \ No newline at end of file +add1 n = n + 1 ; +h = 2 ; +a = 2;
===================================== src/typer_lsp_server.ml ===================================== @@ -80,8 +80,16 @@ let rec search_a_vname_with_a_given_position (vname_list: Util.vname list) (loca | hd::tl -> let (loc, _) = hd in if (loc.line == location.line) && (loc.column == location.column) then hd else search_a_vname_with_a_given_position tl location + +let rec search_lexp_with_a_location (lexp_list: Lexp.lexp list) (location : Util.location): Lexp.lexp option = + match lexp_list with + | [] -> None + | hd::tl -> let r = Lexp.lexp_location hd in + if (r.line == location.line) && (r.column == location.column) then Some hd + else search_lexp_with_a_location tl location
let readstring (str:string) = + (* Log.clear_log () ; *) let ectx = Elab.default_ectx in (*let rctx = Elab.default_rctx in*) let ast = Elab.lexp_decl_str str ectx in @@ -155,19 +163,24 @@ class lsp_server = method on_notif_doc_did_close ~notify_back:_ d : unit Linol_lwt.t = Hashtbl.remove buffers d.uri; Linol_lwt.return () - + method! on_req_definition ~notify_back ~uri ~pos _st = match Hashtbl.find buffers uri with
- | state_after_processing -> let (log_list,ast) = state_after_processing in - let (list_list, ectx) = ast in + | state_after_processing -> let (_,ast) = state_after_processing in + let (list_list, _) = ast in let tab = List.map (fun x -> let (a,b,c) = List.nth x 0 in (a,b,c)) list_list in - let pi = List.map (fun x -> let (a,b,c) = x in a ) tab in - let loc = List.map (fun x -> vname_to_lsp_loc ~vname:x ~uri:uri) pi in - let ret = `Location loc in - Some ret + let lexp_list = List.map (fun x -> let (_,b,_) = x in b ) tab in + let (loc_start,_) = typer_pos_of_lsp_pos pos in + let r = Option.get(search_lexp_with_a_location lexp_list loc_start) in + let loc = Lexp.lexp_location r in + let l = Lsp.Types.Location.create + ~uri:uri ~range:(lsp_range_of_loc loc) + in + let ret = `Location [l] in + let f = Linol_lwt.return (Some ret) in + f
- method! on_req_hover ~notify_back ~uri ~pos doc_state = match Hashtbl.find buffers uri with | state_after_processing -> let (log_list,ast) = state_after_processing in @@ -181,8 +194,14 @@ class lsp_server = let r = Lsp.Types.Hover.create ~contents:(`MarkedString {Lsp.Types.MarkedString.value=s; language=None}) ~range:range () - in Some r + in + let e = Some r in + let f = Linol_lwt.return e in f + + method! config_definition = Some (`Bool true)
+ method! config_hover = Some (`Bool true) + end
(* Main code
View it on GitLab: https://gitlab.com/monnier/typer/-/compare/98f2b0c694d714cf1d57c2553f948bcd0...
Afficher les réponses par date