Soilihi BEN SOILIHI BOINA pushed to branch soilih at Stefan / Typer
Commits: 8e4c5775 by Soilih BEN SOILIH at 2021-06-15T07:07:01-06:00 a better way to complete
- - - - -
1 changed file:
- src/typer_lsp_server.ml
Changes:
===================================== src/typer_lsp_server.ml ===================================== @@ -152,6 +152,7 @@ module Compl = struct | TypeParameter
type t = { + id:int; label:string; newText:string;(*the text the completion will send*) detail:string; @@ -159,10 +160,11 @@ module Compl = struct }
- let t_from_tuple (tup : (string * string * string * k) list) : t list = + let t_from_tuple (tup : (int * string * string * string * k) list) : t list = List.map (fun x - -> let (label,newText,detail,kind) = x in + -> let (id,label,newText,detail,kind) = x in let ret = { + id = id; label = label ; newText = newText ; detail = detail ; @@ -172,13 +174,13 @@ module Compl = struct ) tup
let exemple_liste = [ - ("lambda", "lambda (pattern) -> pattern ", "define a function", Text); - ("case", "case scrutinee \n | pattern -> pattern ", "pattern matching", Function); - ("let", "let_in_ (_=_ x ()) x ", "let...in", Text); - ("if", " if_then_else_ x "x is true" "x is false"", "if...condition", Text); - ("add", "add()", "add a element to a list", Method); + (0, "lambda", "lambda (pattern) -> pattern ", "define a function", Text); + (0, "case", "case scrutinee \n | pattern -> pattern ", "pattern matching", Function); + (0, "let", "let_in_ (_=_ x ()) x ", "let...in", Text); + (0, "if", " if_then_else_ x "x is true" "x is false"", "if...condition", Text); + (1, "add", "add()", "add a element to a list", Method); + (1, "pop", "pop()", "remove a element from a list", Method); ] - let createKind (element:t) = match element.kind with | Text -> Lsp.Types.CompletionItemKind.Text @@ -236,12 +238,16 @@ module Compl = struct |> Str.regexp
- let complete (str:string) (liste: t list) = + let rec complete (str:string) (liste: t list) = match str with - | "List." -> List.filter (fun x -> - String.equal x.label "add" + | "List." -> let lst = List.filter (fun x -> + Int.equal x.id 1 ) - liste + liste + in + let m = String.split_on_char '.' str in + complete (List.nth m 1) lst + | str -> List.filter (fun x -> let reg = match_str str in Str.string_match reg x.label 0 @@ -682,6 +688,7 @@ class lsp_server = let detail = x.detail in let ci = Lsp.Types.CompletionItem.create ~label:label ~kind:kind + ~preselect:(true) ~textEdit:textEdit ~detail:detail () in ci
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/8e4c57753af78736d6b0d58946e1a74217...
Afficher les réponses par date