Skip to content

Commit e86c6f2

Browse files
committed
chore: Remove cmdline toggle
1 parent d281379 commit e86c6f2

File tree

7 files changed

+51
-80
lines changed

7 files changed

+51
-80
lines changed

cli/bin/grain.js

-4
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ program
202202

203203
program
204204
.command("lsp")
205-
.forwardOption(
206-
"--disable-inlay-types",
207-
"Disable's the language server's inlay type hints"
208-
)
209205
.description("start the Grain LSP server")
210206
.action(exec.grainlsp);
211207

compiler/grainlsp/dune

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
(:include ./config/flags.sexp)))
1010
(libraries cmdliner grain_utils grain_language_server grain_formatting
1111
dune-build-info)
12-
(preprocess
13-
(pps ppx_deriving_cmdliner))
1412
(js_of_ocaml
1513
(flags --no-sourcemap --no-extern-fs --quiet)
1614
(javascript_files hacks.js)))

compiler/grainlsp/grainlsp.re

+5-16
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,15 @@ open Cmdliner;
22
open Grain_utils;
33
open Grain_language_server;
44

5-
[@deriving cmdliner]
6-
type params = {
7-
/**
8-
A feature flag to disable inlay type hints.
9-
*/
10-
[@name "disable-inlay-types"]
11-
disable_inlay_types: bool,
12-
};
13-
14-
let run = opts => {
5+
let run = () => {
156
set_binary_mode_in(stdin, true);
167
set_binary_mode_out(stdout, true);
178

189
let rec read_stdin = () => {
1910
switch (Protocol.request()) {
2011
| Error(err) => Trace.log("Failed to read message: " ++ err)
2112
| Ok(msg) =>
22-
switch (
23-
Driver.process(~toggle_type_hints=!opts.disable_inlay_types, msg)
24-
) {
13+
switch (Driver.process(msg)) {
2514
| Exit(code) => exit(code)
2615
| Break => ()
2716
| Reading => read_stdin()
@@ -31,8 +20,8 @@ let run = opts => {
3120
read_stdin();
3221
};
3322

34-
let lsp = opts =>
35-
try(run(opts)) {
23+
let lsp = () =>
24+
try(run()) {
3625
| exn =>
3726
Format.eprintf("@[%s@]@.", Printexc.to_string(exn));
3827
exit(2);
@@ -50,7 +39,7 @@ let cmd = {
5039

5140
Cmd.v(
5241
Cmd.info(Sys.argv[0], ~version, ~doc),
53-
Grain_utils.Config.with_cli_options(lsp) $ params_cmdliner_term(),
42+
Grain_utils.Config.with_cli_options(lsp) $ const(),
5443
);
5544
};
5645

compiler/src/language_server/driver.re

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let compiled_code: Hashtbl.t(Protocol.uri, code) = Hashtbl.create(128);
1515
let is_initialized = ref(false);
1616
let is_shutting_down = ref(false);
1717

18-
let process = (~toggle_type_hints, msg) => {
18+
let process = msg => {
1919
switch (Message.of_request(msg)) {
2020
| Initialize(id, params) =>
2121
Trace.log("initializing");
@@ -26,13 +26,7 @@ let process = (~toggle_type_hints, msg) => {
2626
Hover.process(~id, ~compiled_code, ~documents, params);
2727
Reading;
2828
| TextDocumentInlayHint(id, params) when is_initialized^ =>
29-
Inlayhint.process(
30-
~id,
31-
~compiled_code,
32-
~documents,
33-
~toggle_type_hints,
34-
params,
35-
);
29+
Inlayhint.process(~id, ~compiled_code, ~documents, params);
3630
Reading;
3731
| TextDocumentCodeLens(id, params) when is_initialized^ =>
3832
Lenses.process(~id, ~compiled_code, ~documents, params);

compiler/src/language_server/driver.rei

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ type status =
33
| Break
44
| Exit(int);
55

6-
let process: (~toggle_type_hints: bool, Protocol.request_message) => status;
6+
let process: Protocol.request_message => status;

compiler/src/language_server/inlayhint.re

+43-48
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let is_func_typ = (typ: Types.type_expr) => {
5656
};
5757
};
5858

59-
let find_hints = (~toggle_type_hints: bool, program) => {
59+
let find_hints = program => {
6060
let hints = ref([]);
6161
open Typedtree;
6262
open Protocol;
@@ -65,57 +65,53 @@ let find_hints = (~toggle_type_hints: bool, program) => {
6565
include TypedtreeIter.DefaultIteratorArgument;
6666

6767
let enter_expression = ({exp_desc, exp_type}: expression) =>
68-
if (toggle_type_hints) {
69-
switch (exp_desc) {
70-
| TExpLambda(bindings, _) =>
71-
List.iter(
72-
({mb_pat, mb_loc}: match_branch) => {
73-
switch (mb_pat.pat_desc) {
74-
| TPatTuple(args) =>
75-
switch (resolve_typ(exp_type).desc) {
76-
| TTyArrow(typ_args, _, _) =>
77-
let argument_typs =
78-
List.map(
79-
((arg, typ: Types.type_expr)) =>
80-
switch (arg) {
81-
| Default(_) => None
82-
| _ => Some(typ)
83-
},
84-
typ_args,
85-
);
86-
w;
87-
if (List.length(argument_typs) == List.length(args)) {
88-
List.iter(
89-
((arg: pattern, typ: option(Types.type_expr))) => {
90-
switch (arg.pat_desc, typ) {
91-
| (TPatVar(_, _), Some(typ)) =>
92-
let bind_end = arg.pat_loc.loc_end;
93-
let p: Protocol.position = {
94-
line: bind_end.pos_lnum - 1,
95-
character: bind_end.pos_cnum - bind_end.pos_bol,
96-
};
97-
let typeSignature = string_of_typ(typ);
98-
hints :=
99-
[build_hint(p, typeSignature), ...hints^];
100-
| _ => ()
101-
}
68+
switch (exp_desc) {
69+
| TExpLambda(bindings, _) =>
70+
List.iter(
71+
({mb_pat, mb_loc}: match_branch) => {
72+
switch (mb_pat.pat_desc) {
73+
| TPatTuple(args) =>
74+
switch (resolve_typ(exp_type).desc) {
75+
| TTyArrow(typ_args, _, _) =>
76+
let argument_typs =
77+
List.map(
78+
((arg, typ: Types.type_expr)) =>
79+
switch (arg) {
80+
| Default(_) => None
81+
| _ => Some(typ)
10282
},
103-
List.combine(args, argument_typs),
104-
);
105-
};
106-
| _ => ()
107-
}
83+
typ_args,
84+
);
85+
if (List.length(argument_typs) == List.length(args)) {
86+
List.iter(
87+
((arg: pattern, typ: option(Types.type_expr))) => {
88+
switch (arg.pat_desc, typ) {
89+
| (TPatVar(_, _), Some(typ)) =>
90+
let bind_end = arg.pat_loc.loc_end;
91+
let p: Protocol.position = {
92+
line: bind_end.pos_lnum - 1,
93+
character: bind_end.pos_cnum - bind_end.pos_bol,
94+
};
95+
let typeSignature = string_of_typ(typ);
96+
hints := [build_hint(p, typeSignature), ...hints^];
97+
| _ => ()
98+
}
99+
},
100+
List.combine(args, argument_typs),
101+
);
102+
};
108103
| _ => ()
109104
}
110-
},
111-
bindings,
112-
)
113-
| _ => ()
114-
};
105+
| _ => ()
106+
}
107+
},
108+
bindings,
109+
)
110+
| _ => ()
115111
};
116112

117113
let enter_binding = ({vb_pat, vb_expr}: value_binding, toplevel: bool) =>
118-
if (!toplevel && toggle_type_hints) {
114+
if (!toplevel) {
119115
switch (vb_pat) {
120116
| {pat_extra: [], pat_desc: TPatVar(_, {loc})} =>
121117
let bind_end = loc.loc_end;
@@ -141,14 +137,13 @@ let process =
141137
~id: Protocol.message_id,
142138
~compiled_code: Hashtbl.t(Protocol.uri, code),
143139
~documents: Hashtbl.t(Protocol.uri, string),
144-
~toggle_type_hints: bool,
145140
params: RequestParams.t,
146141
) => {
147142
Trace.log("Inlay hint request received");
148143
switch (Hashtbl.find_opt(compiled_code, params.text_document.uri)) {
149144
| None => send_no_result(~id)
150145
| Some({program, sourcetree}) =>
151-
let hints = find_hints(~toggle_type_hints, program);
146+
let hints = find_hints(program);
152147
Protocol.response(~id, ResponseResult.to_yojson(hints));
153148
};
154149
};

compiler/src/language_server/inlayhint.rei

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ let process:
1717
~id: Protocol.message_id,
1818
~compiled_code: Hashtbl.t(Protocol.uri, Lsp_types.code),
1919
~documents: Hashtbl.t(Protocol.uri, string),
20-
~toggle_type_hints: bool,
2120
RequestParams.t
2221
) =>
2322
unit;

0 commit comments

Comments
 (0)