Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/oak_db/src/package_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ impl<'db> Package {
name: Name<'db>,
visibility: PackageVisibility,
) -> Vec<Definition<'db>> {
// When resolving an export, the `name` must be present in the `NAMESPACE`
// exports. If the package is `base`, there is no `NAMESPACE`, but all top-level
// bindings in `base` are visible by construction, so we skip this check entirely.
if visibility == PackageVisibility::Exported &&
self.name(db) != "base" &&
!self
.namespace(db)
.exports
Expand Down
20 changes: 20 additions & 0 deletions crates/oak_db/src/tests/package_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,23 @@ fn test_same_name_defined_in_multiple_files_returns_each() {
assert!(target_files.contains(&files[0]));
assert!(target_files.contains(&files[1]));
}

#[test]
fn test_base_exports_every_top_level_binding() {
// `base` doesn't have a `NAMESPACE`, so there are no namespace exports for it.
// Instead, `PackageVisibility::Exported` lookups on `base` skip the export check and
// fall straight through to looking for a top-level binding anywhere in the `base`
// source files.
//
// Note that this won't find primitives! These have no top-level binding.
let mut db = TestDb::new();
let (pkg, files) = setup_package(&mut db, "base", &[], &[(
"workspace/base/R/a.R",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that you could add the R sources in the workspace to get LSP analysis against dev base packages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea and I suppose the example should probably have really been using an "installed" Package version of base, but the setup_package() workspace package infra was right there already, and it mostly accomplishes the same thing, so I just went with that

"foo <- function() 1\n",
)]);

let defs = pkg.resolve(&db, name(&db, "foo"), PackageVisibility::Exported);
assert_eq!(defs.len(), 1);
assert_eq!(defs[0].file(&db), files[0]);
assert_eq!(defs[0].name(&db).text(&db).as_str(), "foo");
}
Loading