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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "simplicityhl-lsp"
version = "0.7.3"
version = "0.7.4"
edition = "2021"
rust-version = "1.85.0"
description = "Language Server Protocol (LSP) server for SimplicityHL."
Expand Down Expand Up @@ -30,7 +30,7 @@ thiserror = "2.0.17"

ropey = "1.6.1"
miniscript = "12"
simplicityhl = { version = "0.7.0", features = ["docs"] }
simplicityhl = { version = "0.7.1", features = ["docs"] }
nom = "8.0.0"

[dev-dependencies]
Expand Down
29 changes: 23 additions & 6 deletions src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ pub enum ProjectError {
},
#[error("Configured Simplex manifest was not found at `{0}`")]
MissingConfiguredManifest(PathBuf),
#[error("Dependency `{name}` in `{manifest}` must set exactly one of `path` or `git`")]
#[error(
"Dependency `{name}` in `{manifest}` must set exactly one of `path` or `git`; `path` cannot use `rev`/`tag`, and `git` may set at most one of them"
)]
InvalidDependency { name: String, manifest: PathBuf },
#[error("Git dependency `{name}` from `{url}` is not installed at `{expected}`")]
MissingGitDependency {
Expand Down Expand Up @@ -90,6 +92,8 @@ impl Default for BuildConfig {
struct DependencyConfig {
path: Option<String>,
git: Option<String>,
rev: Option<String>,
tag: Option<String>,
}

struct ProjectCollector {
Expand Down Expand Up @@ -305,9 +309,22 @@ impl ProjectCollector {
package_root: &Path,
) -> Result<PathBuf, ProjectError> {
match (&dependency.path, &dependency.git) {
(Some(path), None) => canonicalize(&package_root.join(path)),
(Some(path), None) if dependency.rev.is_none() && dependency.tag.is_none() => {
canonicalize(&package_root.join(path))
}
(None, Some(url)) => {
let relative = hashed_repository_path(url)?;
let reference = match (&dependency.rev, &dependency.tag) {
(None, None) => None,
(Some(rev), None) => Some(rev.as_str()),
(None, Some(tag)) => Some(tag.as_str()),
(Some(_), Some(_)) => {
return Err(ProjectError::InvalidDependency {
name: name.to_string(),
manifest: package_root.join(SIMPLEX_MANIFEST),
});
}
};
let relative = hashed_repository_path(url, reference)?;
let expected = self
.install_root
.join(DEFAULT_DEPENDENCY_DIRECTORY)
Expand All @@ -318,7 +335,7 @@ impl ProjectCollector {
expected,
})
}
(Some(_), Some(_)) | (None, None) => Err(ProjectError::InvalidDependency {
(_, None) | (Some(_), Some(_)) => Err(ProjectError::InvalidDependency {
name: name.to_string(),
manifest: package_root.join(SIMPLEX_MANIFEST),
}),
Expand Down Expand Up @@ -421,7 +438,7 @@ pub fn find_manifest(path: &Path) -> Option<PathBuf> {
start.ancestors().find_map(manifest_in)
}

fn hashed_repository_path(url: &str) -> Result<PathBuf, ProjectError> {
fn hashed_repository_path(url: &str, reference: Option<&str>) -> Result<PathBuf, ProjectError> {
let clean_url = url.strip_suffix(".git").unwrap_or(url);
let repository_name = clean_url
.split('/')
Expand All @@ -430,7 +447,7 @@ fn hashed_repository_path(url: &str) -> Result<PathBuf, ProjectError> {
.ok_or_else(|| ProjectError::InvalidGitUrl(url.to_string()))?;

let mut hasher = DefaultHasher::new();
url.hash(&mut hasher);
format!("{url}@{}", reference.unwrap_or("HEAD")).hash(&mut hasher);
Ok(PathBuf::from(format!(
"{repository_name}-{:016x}",
hasher.finish()
Expand Down
83 changes: 82 additions & 1 deletion src/project/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ fn resolves_simplex_git_install_directory_exactly() {
let temp = TempDir::new().unwrap();
let root = temp.path();
let url = "https://github.com/BlockstreamResearch/simplicityhl-std";
let installed = root.join("deps").join(hashed_repository_path(url).unwrap());
let installed = root
.join("deps")
.join(hashed_repository_path(url, None).unwrap());
assert_eq!(
installed.file_name().unwrap(),
"simplicityhl-std-8bc347cc4ed271da"
);
write(
&root.join(SIMPLEX_MANIFEST),
&format!("[dependencies]\nstd = {{ git = '{url}' }}\n"),
Expand All @@ -125,6 +131,81 @@ fn resolves_simplex_git_install_directory_exactly() {
);
}

#[test]
fn resolves_simplex_git_install_directories_for_revision_and_tag() {
for (field, reference, expected_directory) in [
("rev", "deadbeef", "simplicityhl-std-c7c631fb6d854c6d"),
("tag", "v1.2.3", "simplicityhl-std-38569687e465cad1"),
] {
let temp = TempDir::new().unwrap();
let root = temp.path();
let url = "https://github.com/BlockstreamResearch/simplicityhl-std";
let installed = root
.join("deps")
.join(hashed_repository_path(url, Some(reference)).unwrap());
assert_eq!(installed.file_name().unwrap(), expected_directory);
write(
&root.join(SIMPLEX_MANIFEST),
&format!("[dependencies]\nstd = {{ git = '{url}', {field} = '{reference}' }}\n"),
);
write(&root.join("simf/main.simf"), "fn main() {}\n");
write(&installed.join(SIMPLEX_MANIFEST), "");
write(&installed.join("simf/lib.simf"), "pub fn helper() {}\n");

let context = ProjectContext::discover(
&root.join("simf/main.simf"),
&ProjectSettings::default(),
&[root.to_path_buf()],
)
.unwrap();

assert_eq!(
context.import_root(&root.join("simf/main.simf"), "std"),
Some(fs::canonicalize(installed.join("simf")).unwrap().as_path())
);
}
}

#[test]
fn rejects_conflicting_simplex_git_references() {
let temp = TempDir::new().unwrap();
let root = temp.path();
write(
&root.join(SIMPLEX_MANIFEST),
"[dependencies]\nstd = { git = 'https://example.com/std', rev = 'deadbeef', tag = 'v1' }\n",
);
write(&root.join("simf/main.simf"), "fn main() {}\n");

let error = ProjectContext::discover(
&root.join("simf/main.simf"),
&ProjectSettings::default(),
&[root.to_path_buf()],
)
.unwrap_err();

assert!(matches!(error, ProjectError::InvalidDependency { .. }));
}

#[test]
fn rejects_git_references_on_path_dependencies() {
let temp = TempDir::new().unwrap();
let root = temp.path();
write(
&root.join(SIMPLEX_MANIFEST),
"[dependencies]\nstd = { path = 'vendor/std', rev = 'deadbeef' }\n",
);
write(&root.join("simf/main.simf"), "fn main() {}\n");

let error = ProjectContext::discover(
&root.join("simf/main.simf"),
&ProjectSettings::default(),
&[root.to_path_buf()],
)
.unwrap_err();

assert!(matches!(error, ProjectError::InvalidDependency { .. }));
}

#[test]
fn manual_mapping_overrides_manifest_mapping() {
let temp = TempDir::new().unwrap();
Expand Down
Loading