-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
182 additions
and
130 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod appraiser; | ||
mod cargo; | ||
mod change_timer; | ||
mod code_action; | ||
mod hover; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::time::Duration; | ||
|
||
use tokio::sync::mpsc::{self, Sender}; | ||
use tokio::time::{sleep, Instant}; | ||
use tower_lsp::lsp_types::Url; | ||
|
||
use super::{appraiser::Ctx, CargoDocumentEvent}; | ||
|
||
//change timer | ||
pub struct ChangeTimer { | ||
tx: Sender<CargoDocumentEvent>, | ||
timeout: u64, | ||
} | ||
|
||
impl ChangeTimer { | ||
pub fn new(tx: Sender<CargoDocumentEvent>, timeout: u64) -> Self { | ||
Self { tx, timeout } | ||
} | ||
|
||
pub fn spawn(&self) -> Sender<Ctx> { | ||
//create a tokio mpsc channel | ||
let (internal_tx, mut internal_rx) = mpsc::channel::<Ctx>(32); | ||
let tx = self.tx.clone(); | ||
let timeout = self.timeout; | ||
tokio::spawn(async move { | ||
let mut uri: Option<Url> = None; | ||
let mut rev = 0; | ||
let delay = sleep(Duration::from_millis(timeout)); | ||
tokio::pin!(delay); | ||
loop { | ||
tokio::select! { | ||
Some(ctx) = internal_rx.recv() => { | ||
uri = Some(ctx.uri.clone()); | ||
rev = ctx.rev; | ||
// Reset the delay to 1 second after receiving a message | ||
delay.as_mut().reset(Instant::now() + Duration::from_millis(timeout)); | ||
} | ||
_ = &mut delay => { | ||
if let Some(current_uri) = &uri { | ||
let ctx = Ctx { | ||
uri: current_uri.clone(), | ||
rev, | ||
}; | ||
if let Err(e) = tx.send(CargoDocumentEvent::ChangeTimer(ctx)).await { | ||
eprintln!("Failed to send Ctx: {}", e); | ||
} | ||
} | ||
// Reset the delay after it has elapsed | ||
delay.as_mut().reset(Instant::now() + Duration::from_millis(timeout)); | ||
} | ||
} | ||
} | ||
}); | ||
internal_tx | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
mod dependency; | ||
mod manifest; | ||
mod package; | ||
mod symbol; | ||
mod table; | ||
|
||
pub use dependency::*; | ||
pub use manifest::*; | ||
pub use symbol::*; | ||
pub use table::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub struct SymbolDiff { | ||
pub created: Vec<String>, | ||
pub range_updated: Vec<String>, | ||
pub value_updated: Vec<String>, | ||
pub deleted: Vec<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.