Skip to content

Commit

Permalink
Only generate lenses for elp-supported files
Browse files Browse the repository at this point in the history
Summary:
This is to prevent crashes we are seeing trying to generate lenses for file of kind `OutsideProjectModel`.
This diff filters to only try for files known to be supported by ELP.
We are not able to do this at a general request level, because we don't have a `FileId` there.

Discussion of alternatives welcome

Reviewed By: ir-regular

Differential Revision: D56634386

fbshipit-source-id: 1247e3419d56ad2dec1008e62e30a4fdce203db2
  • Loading branch information
alanz authored and facebook-github-bot committed Apr 29, 2024
1 parent bbd75be commit fbd43eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/base_db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ impl FileKind {
_ => false,
}
}

pub fn is_elp_supported(self) -> bool {
match self {
Self::SrcModule | Self::TestModule | Self::Header | Self::Escript => true,
_ => false,
}
}
}

pub trait FileLoader {
Expand Down
3 changes: 3 additions & 0 deletions crates/elp/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,9 @@ pub(crate) fn handle_code_lens(
let lens_config = snap.config.lens();

let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
if !snap.analysis.file_kind(file_id)?.is_elp_supported() {
return Ok(None);
}
let line_index = snap.analysis.line_index(file_id)?;
if let Ok(Some(project_id)) = snap.analysis.project_id(file_id) {
let annotations = snap.analysis.annotations(file_id)?;
Expand Down

0 comments on commit fbd43eb

Please sign in to comment.