Soilihi BEN SOILIHI BOINA pushed to branch soilih at Stefan / Typer
Commits: 7783aed8 by Soilih BEN SOILIH at 2021-04-26T14:08:17-06:00 kind of completion and command(still to fix)
- - - - -
1 changed file:
- src/typer_lsp_server.ml
Changes:
===================================== src/typer_lsp_server.ml ===================================== @@ -117,6 +117,60 @@ let diagnostics (_state : state_after_processing) : Lsp.Types.Diagnostic.t list in diagnostic ) log_tab + + (*little method to test completion*) + let little_fonc el = + match el with + | "lambda" -> "lambda (pattern) -> pattern ;" + | "case" -> "case scrutinee \n | pattern -> pattern ;" + | "let" -> "let_in_ (_=_ x ()) x ;" + | "if" -> " if_then_else_ x "x is true" "x is false"" + | _ -> "" + + (* + type t = + | Text + | Method + | Function + | Constructor + | Field + | Variable + | Class + | Interface + | Module + | Property + | Unit + | Value + | Enum + | Keyword + | Snippet + | Color + | File + | Reference + | Folder + | EnumMember + | Constant + | Struct + | Event + | Operator + | TypeParameter + *) + + let little_kind el = + match el with + | "lambda" -> Lsp.Types.CompletionItemKind.Text + | "case" -> Lsp.Types.CompletionItemKind.Function + | "let" -> Lsp.Types.CompletionItemKind.Text + | "if" -> Lsp.Types.CompletionItemKind.Text + | _ -> Lsp.Types.CompletionItemKind.Text + + let little_detail el = + match el with + | "lambda" -> "define a function" + | "case" -> "pattern matching" + | "let" -> "let...in" + | "if" -> "if...condition" + | _ -> ""
(* Lsp server class @@ -198,10 +252,45 @@ class lsp_server = let e = Some r in let f = Linol_lwt.return e in f
- method! config_definition = Some (`Bool true) + method! config_definition = Some (`Bool true)
- method! config_hover = Some (`Bool true) - + method! config_hover = Some (`Bool true) + + + method! on_req_execute_command ~notify_back _c _args = + match _c with + | "typer" -> let file = "command.txt" in + let message = _c in (* Write message to file *) + let oc = open_out file in (* create or truncate file, return channel *) + Printf.fprintf oc "%s\n" message; (* write something *) + close_out oc; (* flush and close the channel *) + let h = Lsp.Types.Command.yojson_of_t + (Lsp.Types.Command.create ~title:_c ~command:_c () ) in + let e = Linol_lwt.return h in e + | _ -> assert false + + method! on_req_completion ~notify_back ~uri ~pos ~ctx doc_state = + match Hashtbl.find buffers uri with + | state_after_processing -> (*let (log_list,ast) = state_after_processing in + let (list_list, ectx) = ast in*) + let tab = ["lambda";"case";"let";"if"] in + let (loc_start, _) = typer_pos_of_lsp_pos pos in + let range = lsp_range_of_loc loc_start in + let r = List.map (fun x -> + let label = x in + let textEdit = Lsp.Types.TextEdit.create ~range:range ~newText:(little_fonc x) in + let kind = little_kind x in + let detail = little_detail x in + let ci = Lsp.Types.CompletionItem.create + ~label:label ~kind:kind + ~textEdit:textEdit ~detail:detail () + in + ci + + ) tab in + let e = Some (`List r) in + let f = Linol_lwt.return e in f + end
(* Main code
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/7783aed82009f2dd093029623ed1b3b7d5...