Skip to content

Commit

Permalink
Merge pull request #15 from wakatime/fix-14
Browse files Browse the repository at this point in the history
fix: send event when write
  • Loading branch information
bestgopher authored Jan 24, 2025
2 parents 8c00f88 + f3f7c55 commit 1a04ac2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions wakatime-ls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,24 @@ struct WakatimeLanguageServer {

impl WakatimeLanguageServer {
async fn send(&self, event: Event) {
// if isWrite is false, and file has not changed since last heartbeat,
// if is_write is false, and file has not changed since last heartbeat,
// and less than 2 minutes since last heartbeat, and do nothing
const INTERVAL: TimeDelta = TimeDelta::minutes(2);

let mut current_file = self.current_file.lock().await;
let now = Local::now();

#[cfg(debug_assertions)]
self.client
.log_message(
MessageType::LOG,
format!("Wakatime language server send called, event: {event:?}",),
)
.await;

if event.uri == current_file.uri
&& now - current_file.timestamp < INTERVAL
&& event.is_write
&& !event.is_write
{
return;
}
Expand Down Expand Up @@ -102,7 +110,7 @@ impl WakatimeLanguageServer {
.log_message(
MessageType::LOG,
format!(
"Wakatime language server send msg faild: {e:?}, command: {:?}",
"Wakatime language server send msg failed: {e:?}, command: {:?}",
command.as_std()
),
)
Expand Down

0 comments on commit 1a04ac2

Please sign in to comment.