-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
608 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
(executables | ||
(names ocaml_lsp_bench) | ||
|
||
(libraries | ||
ocaml_lsp_server | ||
core_unix.command_unix | ||
merlin-lib.kernel | ||
|
||
base | ||
core | ||
core_bench | ||
) | ||
|
||
(preprocess(pps ppx_jane ppx_bench)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
open Core | ||
open Core_bench | ||
open Ocaml_lsp_server.Testing | ||
|
||
let () = | ||
let document = | ||
"let mem = ListLabels.mem\n\nlet _ = mem ~se" |> Merlin_kernel.Msource.make | ||
in | ||
|
||
let position = `Logical (3, 15) in | ||
Command_unix.run | ||
(Bench.make_command | ||
[ Bench.Test.create ~name:"non-regex" (fun _ -> | ||
Compl.prefix_of_position ~short_path:false document position | ||
|> ignore) | ||
; Bench.Test.create ~name:"regex" (fun _ -> | ||
Compl.prefix_of_position_regex ~short_path:false document position | ||
|> ignore) | ||
; Bench.Test.create ~name:"old" (fun _ -> | ||
Compl.prefix_of_position_old ~short_path:false document position | ||
|> ignore) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
open Core | ||
open Core_bench | ||
open Ocaml_lsp_server.Testing | ||
|
||
let () = | ||
let document = | ||
"let mem = ListLabels.mem\n\nlet _ = mem ~se" |> Merlin_kernel.Msource.make | ||
in | ||
|
||
let position = `Logical (3, 15) in | ||
Command.summary | ||
(Bench.make_command | ||
[ Bench.Test.create ~name:"non-regex" (fun _ -> | ||
Compl.prefix_of_position ~short_path:false document position | ||
|> ignore) | ||
; Bench.Test.create ~name:"regex" (fun _ -> | ||
Compl.prefix_of_position_regex ~short_path:false document position | ||
|> ignore) | ||
; Bench.Test.create ~name:"old" (fun _ -> | ||
Compl.prefix_of_position_old ~short_path:false document position | ||
|> ignore) | ||
]) | ||
|> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
type parse_state = | ||
| Continue | ||
| End | ||
| IncludeAndEnd | ||
| Fail | ||
|
||
let next continue = if continue then Continue else End | ||
|
||
let is_name_body_char char = | ||
match char with | ||
| '0' .. '9' | '\'' | '_' | 'a' .. 'z' | 'A' .. 'Z' -> true | ||
| _ -> false | ||
|
||
let parse_name_char ~next_char currentChar = | ||
match currentChar with | ||
| '.' -> next_char |> is_name_body_char |> next | ||
| '`' -> IncludeAndEnd | ||
| '~' | '?' -> | ||
if next_char |> is_name_body_char || next_char = ' ' then IncludeAndEnd | ||
else End | ||
| c -> c |> is_name_body_char |> next | ||
|
||
let is_name_char ~next_char currentChar = | ||
match parse_name_char ~next_char currentChar with | ||
| IncludeAndEnd | Continue -> true | ||
| Fail | End -> false | ||
|
||
let is_infix_char' char = | ||
match char with | ||
| '~' | ||
| '?' | ||
| ':' | ||
| '!' | ||
| '$' | ||
| '&' | ||
| '*' | ||
| '+' | ||
| '-' | ||
| '/' | ||
| '=' | ||
| '>' | ||
| '@' | ||
| '^' | ||
| '|' | ||
| '%' | ||
| '<' | ||
| '.' | ||
| '#' -> true | ||
| _ -> false | ||
|
||
let parse_infix_char ~next_char:_ char = is_infix_char' char |> next | ||
|
||
let parse_char is_correct_char text = | ||
let rec loop text length = | ||
match text with | ||
| char :: (next_char :: _ as tail) -> ( | ||
match is_correct_char ~next_char char with | ||
| Continue -> loop tail (length + 1) | ||
| IncludeAndEnd -> Some (length + 1) | ||
| End -> Some length | ||
| Fail -> None) | ||
(*This is ugly but i'm not sure how else to deal with reaching the start of | ||
the string*) | ||
| [ char ] -> ( | ||
match is_correct_char ~next_char:' ' char with | ||
| Continue -> Some (length + 1) | ||
| IncludeAndEnd -> Some (length + 1) | ||
| End -> Some length | ||
| Fail -> None) | ||
| _ -> Some length | ||
in | ||
let len = loop text 0 in | ||
Option.bind len (fun x -> if x = 0 then None else Some x) | ||
|
||
let infix_prefix text = | ||
if text |> List.hd |> is_infix_char' && List.nth text 1 |> is_infix_char' then | ||
None | ||
else parse_char parse_infix_char text | ||
|
||
let name_prefix = parse_char parse_name_char | ||
|
||
let rec try_parse parsers str = | ||
match parsers with | ||
| head :: tail -> ( | ||
match head str with | ||
| Some l -> Some l | ||
| None -> str |> try_parse tail) | ||
| [] -> None | ||
open Re | ||
|
||
(*Regex based parser*) | ||
|
||
let name_or_label_regex = | ||
Re.compile @@ Re.Posix.re {|([~?`])?([a-zA-Z0-9_']|[a-zA-Z0-9_']\.)+$|} | ||
|
||
let infixRegex =Re.compile @@ Re.Posix.re {|[~?:!$&*+\-\/=><@^|%<.#]+$|} | ||
|
||
open Import | ||
|
||
module Option = struct | ||
include Option | ||
|
||
let none_bind func option = | ||
match option with | ||
| None -> func () | ||
| Some x -> Some x | ||
end | ||
|
||
let try_parse_regex text = | ||
|
||
let matched = | ||
Re.exec_opt name_or_label_regex text | ||
|> Option.none_bind (fun () -> Re.exec_opt infixRegex text) | ||
in | ||
matched |>Option.map ~f:(fun x->Group.get x 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Compl=Compl | ||
module Document =Document | ||
module Import =Import | ||
module Merlin_kernel =Merlin_kernel | ||
module Position =Position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Compl=Compl | ||
module Document =Document | ||
module Import =Import | ||
module Merlin_kernel =Merlin_kernel | ||
module Position =Position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.