Skip to content

Commit ed59eb5

Browse files
alanzmeta-codesync[bot]
authored andcommitted
buck: Applicable files for includes
Summary: Diff D85429234 titled `[ELP] Fix incorrect project load on go to def in thrift file` checks when a new file is opened in the LSP client if its canonical path is in the list of applicable files for a given project, and of so does not attempt to load a new project for it. But for historical reasons the list of applicable files did not include `.hrl` ones. This diff fixes that, together with the change in `elp.bxl` introduced in D85573080 `[buck/prelude] elp.bxl keep full include file name` which returns the actual applicable files rather than just the directory containing them. Reviewed By: TheGeorge Differential Revision: D85573144 fbshipit-source-id: da3eb35f1d80e2107ce4ec9eb9585db710aec7ac
1 parent a269e11 commit ed59eb5

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

crates/project_model/src/buck.rs

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -644,16 +644,20 @@ impl Target {
644644
}
645645
}
646646

647-
fn include_files(&self) -> Vec<AbsPathBuf> {
648-
let mut include_files = self.include_files.clone();
647+
fn include_dirs(&self) -> Vec<AbsPathBuf> {
648+
let mut include_dirs = FxHashSet::from_iter(
649+
self.include_files
650+
.iter()
651+
.map(|path| include_path_from_file(path)),
652+
);
649653
if self.private_header {
650654
self.src_files.iter().for_each(|path| {
651655
if Some("hrl") == path.extension() {
652-
include_files.push(include_path_from_file(path));
656+
include_dirs.insert(include_path_from_file(path));
653657
}
654658
});
655659
}
656-
include_files
660+
include_dirs.iter().cloned().collect()
657661
}
658662
}
659663

@@ -750,49 +754,42 @@ fn make_buck_target(
750754
) -> Result<Target> {
751755
let dir = find_app_root_bxl(root, name, target).expect("could not find app root");
752756

753-
let (src_files, include_files, target_type, private_header, ebin) =
754-
if let Some(ref suite) = target.suite {
755-
let src_file = json::canonicalize(buck_path_to_abs_path(root, suite)?)?;
756-
let src = vec![src_file.clone()];
757-
target_info
758-
.path_to_target_name
759-
.insert(src_file, name.clone());
760-
let mut include_files = vec![];
761-
for include in &target.includes {
762-
if let Ok(inc) = AbsPathBuf::try_from(include.as_str()) {
763-
include_files.push(inc);
764-
}
765-
}
766-
(src, include_files, TargetType::ErlangTest, false, None)
767-
} else {
768-
let mut private_header = false;
769-
let target_type = compute_target_type(name, target, targets_include_only_prelude);
770-
let mut src_files = vec![];
771-
for src in &target.srcs {
772-
let src = json::canonicalize(buck_path_to_abs_path(root, src).unwrap())?;
773-
if Some("hrl") == src.extension() {
774-
private_header = true;
775-
}
776-
src_files.push(src);
777-
}
778-
let mut include_files = vec![];
779-
for include in &target.includes {
780-
let mut inc = buck_path_to_abs_path(root, include).unwrap();
781-
if inc.extension().is_some() {
782-
inc.pop();
783-
}
784-
include_files.push(inc);
757+
let (src_files, target_type, private_header, ebin) = if let Some(ref suite) = target.suite {
758+
let src_file = json::canonicalize(buck_path_to_abs_path(root, suite)?)?;
759+
let src = vec![src_file.clone()];
760+
target_info
761+
.path_to_target_name
762+
.insert(src_file, name.clone());
763+
(src, TargetType::ErlangTest, false, None)
764+
} else {
765+
let mut private_header = false;
766+
let target_type = compute_target_type(name, target, targets_include_only_prelude);
767+
let mut src_files = vec![];
768+
for src in &target.srcs {
769+
let src = json::canonicalize(buck_path_to_abs_path(root, src).unwrap())?;
770+
if Some("hrl") == src.extension() {
771+
private_header = true;
785772
}
773+
src_files.push(src);
774+
}
786775

787-
let ebin = match target_type {
788-
TargetType::ThirdParty if build_deps => dep_path
789-
.remove(name)
790-
.map(|dir| dir.join(Utf8PathBuf::from("ebin"))),
791-
TargetType::ThirdParty => Some(dir.clone()),
792-
_ => None,
793-
};
794-
(src_files, include_files, target_type, private_header, ebin)
776+
let ebin = match target_type {
777+
TargetType::ThirdParty if build_deps => dep_path
778+
.remove(name)
779+
.map(|dir| dir.join(Utf8PathBuf::from("ebin"))),
780+
TargetType::ThirdParty => Some(dir.clone()),
781+
_ => None,
795782
};
783+
(src_files, target_type, private_header, ebin)
784+
};
785+
let mut include_files = vec![];
786+
for include in &target.includes {
787+
if let Ok(inc_abs) = buck_path_to_abs_path(root, include)
788+
&& let Ok(inc) = json::canonicalize(inc_abs)
789+
{
790+
include_files.push(inc);
791+
}
792+
}
796793
let gen_src_files = target
797794
.gen_srcs
798795
.iter()
@@ -1297,14 +1294,20 @@ fn targets_to_project_data_bxl(
12971294
dir: target.dir.clone(),
12981295
ebin: None,
12991296
extra_src_dirs: extra_src_dirs.into_iter().collect(),
1300-
include_dirs: target.include_files(),
1297+
include_dirs: target.include_dirs(),
13011298
abs_src_dirs: abs_src_dirs.into_iter().collect(),
13021299
macros,
13031300
parse_transforms: vec![],
13041301
app_type: target.app_type(),
13051302
include_path: vec![],
13061303
gen_src_files: Some(FxHashSet::from_iter(target.gen_src_files.clone())),
1307-
applicable_files: Some(FxHashSet::from_iter(target.src_files.clone())),
1304+
applicable_files: Some(FxHashSet::from_iter(
1305+
target
1306+
.src_files
1307+
.iter()
1308+
.cloned()
1309+
.chain(target.include_files.iter().cloned()),
1310+
)),
13081311
is_test_target: Some(target.target_type == TargetType::ErlangTest),
13091312
is_buck_generated: Some(target.buck_generated),
13101313
};

0 commit comments

Comments
 (0)