Skip to content

Commit a291460

Browse files
committed
remove lsp lock on didClose event
1 parent 518e07a commit a291460

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

sway-lsp/src/core/document.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ pub fn mark_file_as_dirty(uri: &Url) -> Result<(), LanguageServerError> {
129129
/// If the flag file does not exist, this function will do nothing.
130130
pub fn remove_dirty_flag(uri: &Url) -> Result<(), LanguageServerError> {
131131
let path = document::get_path_from_url(uri)?;
132+
eprintln!("path to remove dirty flag: {:?}", path);
132133
let dirty_file_path = forc_util::is_dirty_path(&path);
134+
eprintln!("dirty_file_path: {:?}", dirty_file_path);
133135
if dirty_file_path.exists() {
136+
eprintln!("Removing dirty flag file: {:?}", dirty_file_path);
134137
// Remove the "dirty" file
135138
std::fs::remove_file(dirty_file_path).map_err(|err| DocumentError::UnableToRemoveFile {
136139
path: uri.path().to_string(),

sway-lsp/src/core/session.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ impl Session {
130130
let _ = join_handle.join();
131131
}
132132

133-
// TODO: clean up any remaining .dirty files
134-
135133
// Delete the temporary directory.
136134
self.sync.remove_temp_dir();
137135
}
@@ -392,7 +390,10 @@ impl Session {
392390
fn store_sway_files(&self) -> Result<(), LanguageServerError> {
393391
let temp_dir = self.sync.temp_dir()?;
394392
// Store the documents.
395-
for path in get_sway_files(temp_dir).iter().filter_map(|fp| fp.to_str()) {
393+
for path in get_sway_files(&temp_dir)
394+
.iter()
395+
.filter_map(|fp| fp.to_str())
396+
{
396397
self.store_document(TextDocument::build_from_path(path)?)?;
397398
}
398399
Ok(())

sway-lsp/src/server.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
//! It provides an interface between the LSP protocol and the sway-lsp internals.
33
44
use crate::{
5+
core::document,
56
handlers::{notification, request},
67
lsp_ext::{OnEnterParams, ShowAstParams},
78
server_state::ServerState,
89
};
910
use lsp_types::{
1011
CodeActionParams, CodeActionResponse, CodeLens, CodeLensParams, CompletionParams,
1112
CompletionResponse, DidChangeTextDocumentParams, DidChangeWatchedFilesParams,
12-
DidOpenTextDocumentParams, DidSaveTextDocumentParams, DocumentFormattingParams,
13-
DocumentHighlight, DocumentHighlightParams, DocumentSymbolParams, DocumentSymbolResponse,
14-
GotoDefinitionParams, GotoDefinitionResponse, Hover, HoverParams, InitializeParams,
15-
InitializeResult, InitializedParams, InlayHint, InlayHintParams, PrepareRenameResponse,
16-
RenameParams, SemanticTokensParams, SemanticTokensResult, TextDocumentIdentifier,
17-
TextDocumentPositionParams, TextEdit, WorkspaceEdit,
13+
DidCloseTextDocumentParams, DidOpenTextDocumentParams, DidSaveTextDocumentParams,
14+
DocumentFormattingParams, DocumentHighlight, DocumentHighlightParams, DocumentSymbolParams,
15+
DocumentSymbolResponse, GotoDefinitionParams, GotoDefinitionResponse, Hover, HoverParams,
16+
InitializeParams, InitializeResult, InitializedParams, InlayHint, InlayHintParams,
17+
PrepareRenameResponse, RenameParams, SemanticTokensParams, SemanticTokensResult,
18+
TextDocumentIdentifier, TextDocumentPositionParams, TextEdit, WorkspaceEdit,
1819
};
1920
use tower_lsp::{jsonrpc::Result, LanguageServer};
2021

@@ -38,6 +39,12 @@ impl LanguageServer for ServerState {
3839
}
3940
}
4041

42+
async fn did_close(&self, params: DidCloseTextDocumentParams) {
43+
if let Err(err) = document::remove_dirty_flag(&params.text_document.uri) {
44+
tracing::error!("{}", err.to_string());
45+
}
46+
}
47+
4148
async fn did_change(&self, params: DidChangeTextDocumentParams) {
4249
if let Err(err) = notification::handle_did_change_text_document(self, params).await {
4350
tracing::error!("{}", err.to_string());

0 commit comments

Comments
 (0)