Skip to content

Commit

Permalink
8/n: Remove duplicates in Vfs loader config
Browse files Browse the repository at this point in the history
Summary:
Our vfs loader config is based on the assumption that each application has a unique directory, and we make a list of these directories to load.

But with the buck bxl project model, especially test targets, we can have more than one application in the same root directory.

To avoid redundant load directories for the vfs loader, use a set of directories rather than a vector.

Note: this has an effect on the loading feedback, since we now only have 2 entries in the loader, one for directories and one for files.  We remedy this toward the end of the stack.

Reviewed By: robertoaloi

Differential Revision: D65944205

fbshipit-source-id: 44d1fcb05af835d5c7161e14fbe6f47443e4f8e0
  • Loading branch information
alanz authored and facebook-github-bot committed Nov 25, 2024
1 parent bdec080 commit 0decf14
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
43 changes: 21 additions & 22 deletions crates/elp/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use elp_ide::elp_ide_db::elp_base_db::AppType;
use elp_ide::elp_ide_db::elp_base_db::FileSetConfig;
use elp_ide::elp_ide_db::elp_base_db::ProjectApps;
use elp_ide::elp_ide_db::elp_base_db::VfsPath;
use fxhash::FxHashSet;

#[derive(Debug)]
pub struct ProjectFolders {
Expand All @@ -30,38 +31,36 @@ impl ProjectFolders {
.fold(
FileSetConfig::builder(),
|mut builder, (_project_id, app)| {
let mut file_sets: Vec<VfsPath> = app
let mut file_sets: FxHashSet<VfsPath> = app
.abs_src_dirs
.iter()
.map(|src| VfsPath::from(src.clone()))
.collect();
let dir = VfsPath::from(app.dir.clone());
file_sets.push(dir);
builder.add_file_set(file_sets);
file_sets.insert(dir);
builder.add_file_set(file_sets.into_iter().collect());
builder
},
)
.build();

let load = project_apps
.all_apps
.iter()
.flat_map(|(_, app)| {
let dirs = loader::Directories {
extensions: vec!["erl".to_string(), "hrl".to_string(), "escript".to_string()],
include: app.all_source_dirs(),
exclude: vec![],
};
let dir_entry = loader::Entry::Directories(dirs);
match app.app_type {
AppType::App => vec![
dir_entry,
loader::Entry::Files(vec![app.dir.join(".eqwalizer")]),
],
_ => vec![dir_entry],
}
})
.collect();
let mut app_dirs = FxHashSet::default();
let mut files = FxHashSet::default();
project_apps.all_apps.iter().for_each(|(_, app)| {
app_dirs.extend(app.all_source_dirs());
if app.app_type == AppType::App {
files.insert(app.dir.join(".eqwalizer"));
}
});

let load = vec![
loader::Entry::Directories(loader::Directories {
extensions: vec!["erl".to_string(), "hrl".to_string(), "escript".to_string()],
include: app_dirs.into_iter().collect(),
exclude: vec![],
}),
loader::Entry::Files(files.into_iter().collect()),
];

let mut watch: Vec<_> = project_apps
.all_apps
Expand Down
2 changes: 1 addition & 1 deletion crates/project_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ impl ProjectAppData {

/// Source directories for the application including the extra
/// sources and includes
pub fn all_source_dirs(&self) -> Vec<AbsPathBuf> {
pub fn all_source_dirs(&self) -> FxHashSet<AbsPathBuf> {
self.extra_src_dirs
.iter()
.map(|src_dir| self.dir.join(src_dir))
Expand Down

0 comments on commit 0decf14

Please sign in to comment.