Skip to content

Commit bf8d8a4

Browse files
authored
Continue even if the lsp cannot acquire an exclusive lock (#5740)
## Description Before this PR the lsp will throw an error if it can't acquire a lock, instead, log the error and continue gracefully. ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers.
1 parent e41e82b commit bf8d8a4

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

forc-util/src/fs_locking.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ impl PidFileLocking {
7171
if self.is_locked() {
7272
Err(io::Error::new(
7373
std::io::ErrorKind::Other,
74-
"Cannot remove a dirty lock file, it is locked by another process",
74+
format!(
75+
"Cannot remove a dirty lock file, it is locked by another process (PID: {:#?})",
76+
self.get_locker_pid()
77+
),
7578
))
7679
} else {
7780
self.remove_file()?;

sway-lsp/src/core/document.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn mark_file_as_dirty(uri: &Url) -> Result<(), LanguageServerError> {
115115
let path = document::get_path_from_url(uri)?;
116116
Ok(PidFileLocking::lsp(path)
117117
.lock()
118-
.map_err(|_| DirectoryError::LspLocksDirFailed)?)
118+
.map_err(|e| DirectoryError::LspLocksDirFailed(e.to_string()))?)
119119
}
120120

121121
/// Removes the corresponding flag file for the specifed Url.

sway-lsp/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub enum DirectoryError {
5454
ManifestDirNotFound,
5555
#[error("Can't extract project name from {:?}", dir)]
5656
CantExtractProjectName { dir: String },
57-
#[error("Failed to create hidden .lsp_locks directory")]
58-
LspLocksDirFailed,
57+
#[error("Failed to create hidden .lsp_locks directory: {0}")]
58+
LspLocksDirFailed(String),
5959
#[error("Failed to create temp directory")]
6060
TempDirFailed,
6161
#[error("Failed to canonicalize path")]

sway-lsp/src/handlers/notification.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ pub async fn handle_did_change_text_document(
7878
state: &ServerState,
7979
params: DidChangeTextDocumentParams,
8080
) -> Result<(), LanguageServerError> {
81-
document::mark_file_as_dirty(&params.text_document.uri)?;
81+
if let Err(err) = document::mark_file_as_dirty(&params.text_document.uri) {
82+
tracing::warn!("Failed to mark file as dirty: {}", err);
83+
}
84+
8285
let (uri, session) = state
8386
.sessions
8487
.uri_and_session_from_workspace(&params.text_document.uri)

0 commit comments

Comments
 (0)