Skip to content

Commit

Permalink
fix: close files
Browse files Browse the repository at this point in the history
related to #29
  • Loading branch information
Feel-ix-343 committed Mar 11, 2024
1 parent 811a523 commit f004aab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.80"
itertools = "0.10.5"
nanoid = "0.4.0"
nucleo-matcher = { path = "./matcher" }
Expand Down
20 changes: 18 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,19 @@ impl LanguageServer for Backend {
}

async fn did_open(&self, params: DidOpenTextDocumentParams) {
let _ = self
let _new_files = self
.bind_opened_files_mut(|files| {
// diagnostics will only be published for the files that are opened; We must track which files are opened
let path = params_path!(params)?;

files.insert(path);

Ok(())
Ok(files.clone())
})
.await;

self.client.log_message(MessageType::LOG, "Added file").await;

self.update_vault(TextDocumentItem {
uri: params.text_document.uri,
text: params.text_document.text,
Expand All @@ -363,6 +365,20 @@ impl LanguageServer for Backend {
}
}

async fn did_close(&self, params: DidCloseTextDocumentParams) {
let removed_file = self
.bind_opened_files_mut(|files| {
let path = params_path!(params)?;

Ok(files.take(&path))
}).await;

if let Ok(Some(file)) = removed_file {
self.client.log_message(MessageType::LOG, format!("Remove file {:?}", file)).await;
}

}

async fn did_change(&self, mut params: DidChangeTextDocumentParams) {
self.update_vault(TextDocumentItem {
uri: params.text_document.uri,
Expand Down

0 comments on commit f004aab

Please sign in to comment.