Skip to content

Commit

Permalink
feat(lsp): Support hover on include statements (#1963)
Browse files Browse the repository at this point in the history
Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
  • Loading branch information
spotandjake and phated committed Jan 29, 2024
1 parent 6701170 commit b6e1570
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler/src/language_server/hover.re
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ let declaration_lens = (ident: Ident.t, decl: Types.type_declaration) => {
grain_type_code_block(Printtyp.string_of_type_declaration(~ident, decl));
};

let include_lens = (env: Env.t, path: Path.t) => {
let module_decl = Env.find_module(path, None, env);
markdown_join(
grain_code_block("module " ++ Path.name(path)),
module_lens(module_decl),
);
};

let exception_declaration_lens =
(ident: Ident.t, ext: Types.extension_constructor) => {
grain_type_code_block(
Expand Down Expand Up @@ -176,6 +184,12 @@ let process =
)
| [Module({path, decl, loc}), ..._] =>
send_hover(~id, ~range=Utils.loc_to_range(loc), module_lens(decl))
| [Include({env, path, loc}), ..._] =>
send_hover(
~id,
~range=Utils.loc_to_range(loc),
include_lens(env, path),
)
| _ => send_no_result(~id)
};
};
Expand Down
28 changes: 28 additions & 0 deletions compiler/src/language_server/sourcetree.re
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ module type Sourcetree = {
decl: Types.module_declaration,
loc: Location.t,
definition: option(Location.t),
})
| Include({
env: Env.t,
path: Path.t,
loc: Location.t,
});

type sourcetree = t(node);
Expand Down Expand Up @@ -253,6 +258,11 @@ module Sourcetree: Sourcetree = {
decl: Types.module_declaration,
loc: Location.t,
definition: option(Location.t),
})
| Include({
env: Env.t,
path: Path.t,
loc: Location.t,
});

type sourcetree = t(node);
Expand Down Expand Up @@ -514,6 +524,24 @@ module Sourcetree: Sourcetree = {
...segments^,
];
};
let enter_toplevel_stmt = stmt => {
switch (stmt.ttop_desc) {
| TTopInclude(inc) =>
segments :=
[
(
loc_to_interval(stmt.ttop_loc),
Include({
env: stmt.ttop_env,
path: inc.tinc_path,
loc: stmt.ttop_loc,
}),
),
...segments^,
]
| _ => ()
};
};
});
Iterator.iter_typed_program(program);
create(segments^);
Expand Down

0 comments on commit b6e1570

Please sign in to comment.