Skip to content

Commit

Permalink
daemon now working
Browse files Browse the repository at this point in the history
  • Loading branch information
frederik-uni committed Oct 12, 2024
1 parent f8808e9 commit 299eca4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 30 deletions.
19 changes: 14 additions & 5 deletions 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.15.0"
version = "0.15.1"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/crate_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl CratesIoStorage {
true
}
pub fn stop(&self) {
exit(0)
exit(0);
}
pub async fn search(&self, query: &str) -> Vec<(String, Option<String>, String)> {
let lock = self.data.read().await;
Expand Down
51 changes: 28 additions & 23 deletions src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ fn start_daemon(port: u16, storage: &Path, stable: bool, offline: bool, per_page
impl Deamon {
async fn handle_error(&self, e: tcp_struct::Error) {
match e {
tcp_struct::Error::StreamError(error) => match error.kind() {
std::io::ErrorKind::ConnectionRefused => {
tcp_struct::Error::StreamError(error) => match error.kind.as_str() {
"connection refused" => {
if let Deamon::Deamon((_, config, path)) = &self {
start_daemon(
config.daemon_port,
Expand Down Expand Up @@ -416,29 +416,34 @@ impl LanguageServer for Backend {
let daemon = CratesIoStorage::read(config.daemon_port, crate_version());
match daemon.update(config).await {
Ok(_) => {}
Err(err) => match err {
tcp_struct::Error::StreamError(error) => match error.kind() {
std::io::ErrorKind::ConnectionRefused => start_daemon(
config.daemon_port,
&self.path,
config.stable,
config.offline,
config.per_page_web,
),
Err(err) => {
self.client
.log_message(MessageType::INFO, format!("{err:?}"))
.await;
match err {
tcp_struct::Error::StreamError(error) => match error.kind.as_str() {
"connection refused" => start_daemon(
config.daemon_port,
&self.path,
config.stable,
config.offline,
config.per_page_web,
),
_ => {}
},
tcp_struct::Error::ApiMisMatch(_) => {
let _ = daemon.stop().await;
start_daemon(
config.daemon_port,
&self.path,
config.stable,
config.offline,
config.per_page_web,
);
}
_ => {}
},
tcp_struct::Error::ApiMisMatch(_) => {
let _ = daemon.stop().await;
start_daemon(
config.daemon_port,
&self.path,
config.stable,
config.offline,
config.per_page_web,
);
}
_ => {}
},
}
}
*self.crates.write().await = Deamon::Deamon((daemon, config, self.path.clone()));
}
Expand Down

0 comments on commit 299eca4

Please sign in to comment.