Skip to content

Commit b6e1570

Browse files
spotandjakephated
andauthored
feat(lsp): Support hover on include statements (#1963)
Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
1 parent 6701170 commit b6e1570

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

compiler/src/language_server/hover.re

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ let declaration_lens = (ident: Ident.t, decl: Types.type_declaration) => {
125125
grain_type_code_block(Printtyp.string_of_type_declaration(~ident, decl));
126126
};
127127

128+
let include_lens = (env: Env.t, path: Path.t) => {
129+
let module_decl = Env.find_module(path, None, env);
130+
markdown_join(
131+
grain_code_block("module " ++ Path.name(path)),
132+
module_lens(module_decl),
133+
);
134+
};
135+
128136
let exception_declaration_lens =
129137
(ident: Ident.t, ext: Types.extension_constructor) => {
130138
grain_type_code_block(
@@ -176,6 +184,12 @@ let process =
176184
)
177185
| [Module({path, decl, loc}), ..._] =>
178186
send_hover(~id, ~range=Utils.loc_to_range(loc), module_lens(decl))
187+
| [Include({env, path, loc}), ..._] =>
188+
send_hover(
189+
~id,
190+
~range=Utils.loc_to_range(loc),
191+
include_lens(env, path),
192+
)
179193
| _ => send_no_result(~id)
180194
};
181195
};

compiler/src/language_server/sourcetree.re

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ module type Sourcetree = {
168168
decl: Types.module_declaration,
169169
loc: Location.t,
170170
definition: option(Location.t),
171+
})
172+
| Include({
173+
env: Env.t,
174+
path: Path.t,
175+
loc: Location.t,
171176
});
172177

173178
type sourcetree = t(node);
@@ -253,6 +258,11 @@ module Sourcetree: Sourcetree = {
253258
decl: Types.module_declaration,
254259
loc: Location.t,
255260
definition: option(Location.t),
261+
})
262+
| Include({
263+
env: Env.t,
264+
path: Path.t,
265+
loc: Location.t,
256266
});
257267

258268
type sourcetree = t(node);
@@ -514,6 +524,24 @@ module Sourcetree: Sourcetree = {
514524
...segments^,
515525
];
516526
};
527+
let enter_toplevel_stmt = stmt => {
528+
switch (stmt.ttop_desc) {
529+
| TTopInclude(inc) =>
530+
segments :=
531+
[
532+
(
533+
loc_to_interval(stmt.ttop_loc),
534+
Include({
535+
env: stmt.ttop_env,
536+
path: inc.tinc_path,
537+
loc: stmt.ttop_loc,
538+
}),
539+
),
540+
...segments^,
541+
]
542+
| _ => ()
543+
};
544+
};
517545
});
518546
Iterator.iter_typed_program(program);
519547
create(segments^);

0 commit comments

Comments
 (0)