Skip to content

Commit

Permalink
stable feature now offline
Browse files Browse the repository at this point in the history
  • Loading branch information
frederik-uni committed Sep 29, 2024
1 parent fccbe51 commit 1a2080b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargotom"
version = "0.13.5"
version = "0.13.6"
edition = "2021"

[dependencies]
Expand Down
30 changes: 25 additions & 5 deletions src/crate_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct CratesIoStorage {
last_checked: Shared<Duration>,
updating: Shared<bool>,
pub client: Client,
stable: bool,
pub stable: bool,
pub per_page: u32,
pub data: Shared<OfflineCratesData>,
}
Expand Down Expand Up @@ -147,9 +147,23 @@ impl CratesIoStorage {
(
a.to_string(),
None,
b.last()
.map(|(version, _)| version.to_string())
.unwrap_or_default(),
match self.stable {
true => b
.iter()
.rev()
.find(|(version, _)| {
match RustVersion::try_from(version.as_str()) {
Ok(v) => v.is_patch_int(),
Err(_) => false,
}
})
.map(|(version, _)| version.to_string())
.unwrap_or_default(),
false => b
.last()
.map(|(version, _)| version.to_string())
.unwrap_or_default(),
},
)
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -187,14 +201,20 @@ impl CratesIoStorage {
versions
.iter()
.map(|(version, _)| RustVersion::try_from(version.as_str()).unwrap())
.filter(|v| !self.stable || v.is_patch_int())
.collect::<Vec<_>>(),
)
} else {
let v = self.versions_cache.read().await;
match v.get(name) {
Some(v) => match v {
InfoCacheEntry::Pending(_) => None,
InfoCacheEntry::Ready(v) => Some(v.iter().map(|v| v.version.clone()).collect()),
InfoCacheEntry::Ready(v) => Some(
v.iter()
.map(|v| v.version.clone())
.filter(|v| !self.stable || v.is_patch_int())
.collect(),
),
},
None => {
//INFO: thats probably fine, bc CratesIoStorage will exist until the lsp is stopped
Expand Down
19 changes: 19 additions & 0 deletions src/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ pub struct RustVersion {
patch: Option<VersionString>,
}

impl RustVersion {
pub fn is_patch_int(&self) -> bool {
match &self.patch {
Some(v) => {
let items = v.int_or_string();
if items.len() == 1 {
match items.first() {
Some(IntOrString::Int(_)) => true,
_ => false,
}
} else {
false
}
}
None => true,
}
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct VersionString(String);

Expand Down

0 comments on commit 1a2080b

Please sign in to comment.