Skip to content

Commit 61098d8

Browse files
committed
Fixes and test update
1 parent 00a613d commit 61098d8

File tree

7 files changed

+97
-175
lines changed

7 files changed

+97
-175
lines changed

ocaml-lsp-server/src/merlin_config.ml

Lines changed: 15 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -27,133 +27,11 @@
2727

2828
open Import
2929
open Fiber.O
30+
open Merlin_kernel
3031
module Std = Merlin_utils.Std
3132
module Misc = Merlin_utils.Misc
3233

33-
module List = struct
34-
include List
35-
36-
let filter_dup' ~equiv lst =
37-
let tbl = Hashtbl.create 17 in
38-
let f a b =
39-
let b' = equiv b in
40-
if Hashtbl.mem tbl b'
41-
then a
42-
else (
43-
Hashtbl.add tbl b' ();
44-
b :: a)
45-
in
46-
rev (fold_left ~f ~init:[] lst)
47-
;;
48-
49-
let filter_dup lst = filter_dup' ~equiv:(fun x -> x) lst
50-
end
51-
52-
module Config = struct
53-
type t =
54-
{ build_path : string list
55-
; source_path : string list
56-
; cmi_path : string list
57-
; cmt_path : string list
58-
; flags : string list Std.with_workdir list
59-
; extensions : string list
60-
; suffixes : (string * string) list
61-
; stdlib : string option
62-
; reader : string list
63-
; exclude_query_dir : bool
64-
; use_ppx_cache : bool
65-
}
66-
67-
let empty =
68-
{ build_path = []
69-
; source_path = []
70-
; cmi_path = []
71-
; cmt_path = []
72-
; extensions = []
73-
; suffixes = []
74-
; flags = []
75-
; stdlib = None
76-
; reader = []
77-
; exclude_query_dir = false
78-
; use_ppx_cache = false
79-
}
80-
;;
81-
82-
(* Parses suffixes pairs that were supplied as whitespace separated pairs
83-
designating implementation/interface suffixes. These would be supplied in
84-
the .merlin file as:
85-
86-
SUFFIX .sfx .sfxi *)
87-
let parse_suffix str =
88-
match
89-
let trimmed = String.trim str in
90-
String.extract_blank_separated_words trimmed
91-
with
92-
| [ first; second ] ->
93-
if String.get first 0 <> '.' || String.get second 0 <> '.'
94-
then []
95-
else [ first, second ]
96-
| _ -> []
97-
;;
98-
99-
let prepend ~dir:cwd (directives : Merlin_dot_protocol.directive list) config =
100-
List.fold_left ~init:(config, []) directives ~f:(fun (config, errors) ->
101-
function
102-
| `B path -> { config with build_path = path :: config.build_path }, errors
103-
| `S path -> { config with source_path = path :: config.source_path }, errors
104-
| `CMI path -> { config with cmi_path = path :: config.cmi_path }, errors
105-
| `CMT path -> { config with cmt_path = path :: config.cmt_path }, errors
106-
| `EXT exts -> { config with extensions = exts @ config.extensions }, errors
107-
| `SUFFIX suffix ->
108-
{ config with suffixes = parse_suffix suffix @ config.suffixes }, errors
109-
| `FLG flags ->
110-
let flags = { Std.workdir = cwd; workval = flags } in
111-
{ config with flags = flags :: config.flags }, errors
112-
| `STDLIB path -> { config with stdlib = Some path }, errors
113-
| `READER reader -> { config with reader }, errors
114-
| `EXCLUDE_QUERY_DIR -> { config with exclude_query_dir = true }, errors
115-
| `USE_PPX_CACHE -> { config with use_ppx_cache = true }, errors
116-
| `UNKNOWN_TAG _ ->
117-
(* For easier forward compatibility we ignore unknown configuration tags
118-
when they are provided by dune *)
119-
config, errors
120-
| `ERROR_MSG str -> config, str :: errors)
121-
;;
122-
123-
let postprocess =
124-
let clean list = List.rev (List.filter_dup list) in
125-
fun config ->
126-
{ build_path = clean config.build_path
127-
; source_path = clean config.source_path
128-
; cmi_path = clean config.cmi_path
129-
; cmt_path = clean config.cmt_path
130-
; extensions = clean config.extensions
131-
; suffixes = clean config.suffixes
132-
; flags = clean config.flags
133-
; stdlib = config.stdlib
134-
; reader = config.reader
135-
; exclude_query_dir = config.exclude_query_dir
136-
; use_ppx_cache = config.use_ppx_cache
137-
}
138-
;;
139-
140-
let merge t (merlin : Mconfig.merlin) failures config_path =
141-
{ merlin with
142-
build_path = t.build_path @ merlin.build_path
143-
; source_path = t.source_path @ merlin.source_path
144-
; cmi_path = t.cmi_path @ merlin.cmi_path
145-
; cmt_path = t.cmt_path @ merlin.cmt_path
146-
; exclude_query_dir = t.exclude_query_dir || merlin.exclude_query_dir
147-
; extensions = t.extensions @ merlin.extensions
148-
; suffixes = t.suffixes @ merlin.suffixes
149-
; stdlib = (if t.stdlib = None then merlin.stdlib else t.stdlib)
150-
; reader = (if t.reader = [] then merlin.reader else t.reader)
151-
; flags_to_apply = t.flags @ merlin.flags_to_apply
152-
; failures = failures @ merlin.failures
153-
; config_path = Some config_path
154-
}
155-
;;
156-
end
34+
let empty = Mconfig_dot.empty_config
15735

15836
module Process = struct
15937
type nonrec t =
@@ -324,11 +202,17 @@ let get_config (p : Process.t) ~workdir path_abs =
324202
in
325203
match answer with
326204
| Ok directives ->
327-
let cfg, failures = Config.prepend ~dir:workdir directives Config.empty in
328-
Config.postprocess cfg, failures
329-
| Error (Merlin_dot_protocol.Unexpected_output msg) -> Config.empty, [ msg ]
205+
let cfg, failures =
206+
Mconfig_dot.prepend_config
207+
~dir:workdir
208+
Mconfig_dot.Configurator.Dune
209+
directives
210+
empty
211+
in
212+
Mconfig_dot.postprocess_config cfg, failures
213+
| Error (Merlin_dot_protocol.Unexpected_output msg) -> empty, [ msg ]
330214
| Error (Csexp_parse_error _) ->
331-
( Config.empty
215+
( empty
332216
, [ "ocamllsp could not load its configuration from the external reader. Building \
333217
your project with `dune` might solve this issue."
334218
] )
@@ -437,7 +321,9 @@ let config (t : t) : Mconfig.t Fiber.t =
437321
use_entry entry
438322
in
439323
let+ dot, failures = get_config entry.process ~workdir:ctx.workdir t.path in
440-
let merlin = Config.merge dot t.initial.merlin failures config_path in
324+
let merlin =
325+
Mconfig.merge_merlin_config dot t.initial.merlin ~failures ~config_path
326+
in
441327
Mconfig.normalize { t.initial with merlin })
442328
;;
443329

ocaml-lsp-server/src/ocaml_lsp_server.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ let references (state : State.t) { ReferenceParams.textDocument = { uri }; posit
419419
match Document.kind doc with
420420
| `Other -> Fiber.return None
421421
| `Merlin doc ->
422-
let+ locs =
422+
let+ locs, _status =
423423
Document.Merlin.dispatch_exn
424424
~name:"occurrences"
425425
doc
@@ -441,7 +441,7 @@ let highlight
441441
match Document.kind doc with
442442
| `Other -> Fiber.return None
443443
| `Merlin m ->
444-
let+ locs =
444+
let+ locs, _status =
445445
Document.Merlin.dispatch_exn
446446
~name:"occurrences"
447447
m
@@ -628,7 +628,7 @@ let on_request
628628
match Document.kind doc with
629629
| `Other -> Fiber.return None
630630
| `Merlin doc ->
631-
let+ locs =
631+
let+ locs, _status =
632632
Document.Merlin.dispatch_exn
633633
~name:"occurrences"
634634
doc

ocaml-lsp-server/src/rename.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let rename (state : State.t) { RenameParams.textDocument = { uri }; position; ne
1010
let command =
1111
Query_protocol.Occurrences (`Ident_at (Position.logical position), `Buffer)
1212
in
13-
let+ locs = Document.Merlin.dispatch_exn ~name:"rename" merlin command in
13+
let+ locs, _status = Document.Merlin.dispatch_exn ~name:"rename" merlin command in
1414
let version = Document.version doc in
1515
let source = Document.source doc in
1616
let edits =

ocaml-lsp-server/src/semantic_highlighting.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,10 @@ end = struct
425425
self.attributes self pld_attributes
426426
;;
427427

428-
let value_binding (self : Ast_iterator.iterator)
429-
({ pvb_pat; pvb_expr; pvb_attributes; pvb_loc = _ } as vb :
430-
Parsetree.value_binding) =
428+
let value_binding
429+
(self : Ast_iterator.iterator)
430+
({ pvb_pat; pvb_expr; pvb_attributes; pvb_loc = _ } as vb : Parsetree.value_binding)
431+
=
431432
match
432433
match pvb_pat.ppat_desc, pvb_expr.pexp_desc with
433434
| Parsetree.Ppat_var fn_name, _ ->
@@ -761,8 +762,7 @@ end = struct
761762
self.module_type self mt);
762763
`Custom_iterator
763764
| Pmod_extension _ -> `Custom_iterator
764-
| Pmod_unpack _ | Pmod_apply (_, _) | Pmod_structure _ ->
765-
`Default_iterator
765+
| Pmod_unpack _ | Pmod_apply (_, _) | Pmod_structure _ -> `Default_iterator
766766
with
767767
| `Custom_iterator -> self.attributes self pmod_attributes
768768
| `Default_iterator -> Ast_iterator.default_iterator.module_expr self me

ocaml-lsp-server/test/e2e-new/documentation.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let%expect_test "Documentation when List module is shadowed" =
109109
{
110110
"doc": {
111111
"kind": "plaintext",
112-
"value": "[iter f [a1; ...; an]] applies function [f] in turn to\n [[a1; ...; an]]. It is equivalent to\n [f a1; f a2; ...; f an]."
112+
"value": "[iter f [a1; ...; an]] applies function [f] in turn to\n [a1; ...; an]. It is equivalent to\n [begin f a1; f a2; ...; f an; () end]."
113113
}
114114
} |}]
115115
;;

ocaml-lsp-server/test/e2e-new/type_search.ml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ let%expect_test "Polarity Search for a simple query that takes an int and return
5757
"name": "string_of_int",
5858
"typ": "int -> string",
5959
"loc": {
60-
"end": { "character": 33, "line": 740 },
61-
"start": { "character": 0, "line": 740 }
60+
"end": { "character": 33, "line": 749 },
61+
"start": { "character": 0, "line": 749 }
6262
},
6363
"doc": {
6464
"kind": "markdown",
@@ -71,8 +71,8 @@ let%expect_test "Polarity Search for a simple query that takes an int and return
7171
"name": "string_of_int",
7272
"typ": "int -> string",
7373
"loc": {
74-
"end": { "character": 33, "line": 740 },
75-
"start": { "character": 0, "line": 740 }
74+
"end": { "character": 33, "line": 749 },
75+
"start": { "character": 0, "line": 749 }
7676
},
7777
"doc": {
7878
"kind": "markdown",
@@ -110,8 +110,8 @@ let%expect_test "Polarity Search for a simple query that takes an int and return
110110
"name": "string_of_int",
111111
"typ": "int -> string",
112112
"loc": {
113-
"end": { "character": 33, "line": 740 },
114-
"start": { "character": 0, "line": 740 }
113+
"end": { "character": 33, "line": 749 },
114+
"start": { "character": 0, "line": 749 }
115115
},
116116
"doc": null,
117117
"cost": 4,
@@ -121,8 +121,8 @@ let%expect_test "Polarity Search for a simple query that takes an int and return
121121
"name": "string_of_int",
122122
"typ": "int -> string",
123123
"loc": {
124-
"end": { "character": 33, "line": 740 },
125-
"start": { "character": 0, "line": 740 }
124+
"end": { "character": 33, "line": 749 },
125+
"start": { "character": 0, "line": 749 }
126126
},
127127
"doc": null,
128128
"cost": 4,
@@ -156,8 +156,8 @@ let%expect_test "Type Search for a simple query that takes an int and returns a
156156
"name": "string_of_int",
157157
"typ": "int -> string",
158158
"loc": {
159-
"end": { "character": 33, "line": 740 },
160-
"start": { "character": 0, "line": 740 }
159+
"end": { "character": 33, "line": 749 },
160+
"start": { "character": 0, "line": 749 }
161161
},
162162
"doc": null,
163163
"cost": 0,
@@ -167,8 +167,8 @@ let%expect_test "Type Search for a simple query that takes an int and returns a
167167
"name": "string_of_int",
168168
"typ": "int -> string",
169169
"loc": {
170-
"end": { "character": 33, "line": 740 },
171-
"start": { "character": 0, "line": 740 }
170+
"end": { "character": 33, "line": 749 },
171+
"start": { "character": 0, "line": 749 }
172172
},
173173
"doc": null,
174174
"cost": 0,
@@ -205,8 +205,8 @@ let%expect_test "Type Search for a simple query that takes an int and returns a
205205
"name": "string_of_int",
206206
"typ": "int -> string",
207207
"loc": {
208-
"end": { "character": 33, "line": 740 },
209-
"start": { "character": 0, "line": 740 }
208+
"end": { "character": 33, "line": 749 },
209+
"start": { "character": 0, "line": 749 }
210210
},
211211
"doc": {
212212
"kind": "plaintext",
@@ -219,8 +219,8 @@ let%expect_test "Type Search for a simple query that takes an int and returns a
219219
"name": "string_of_int",
220220
"typ": "int -> string",
221221
"loc": {
222-
"end": { "character": 33, "line": 740 },
223-
"start": { "character": 0, "line": 740 }
222+
"end": { "character": 33, "line": 749 },
223+
"start": { "character": 0, "line": 749 }
224224
},
225225
"doc": {
226226
"kind": "plaintext",

0 commit comments

Comments
 (0)