Skip to content

Commit

Permalink
Continue even if the lsp cannot acquire an exclusive lock (#5740)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
crodas authored Mar 18, 2024
1 parent e41e82b commit bf8d8a4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion forc-util/src/fs_locking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ impl PidFileLocking {
if self.is_locked() {
Err(io::Error::new(
std::io::ErrorKind::Other,
"Cannot remove a dirty lock file, it is locked by another process",
format!(
"Cannot remove a dirty lock file, it is locked by another process (PID: {:#?})",
self.get_locker_pid()
),
))
} else {
self.remove_file()?;
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/core/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn mark_file_as_dirty(uri: &Url) -> Result<(), LanguageServerError> {
let path = document::get_path_from_url(uri)?;
Ok(PidFileLocking::lsp(path)
.lock()
.map_err(|_| DirectoryError::LspLocksDirFailed)?)
.map_err(|e| DirectoryError::LspLocksDirFailed(e.to_string()))?)
}

/// Removes the corresponding flag file for the specifed Url.
Expand Down
4 changes: 2 additions & 2 deletions sway-lsp/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub enum DirectoryError {
ManifestDirNotFound,
#[error("Can't extract project name from {:?}", dir)]
CantExtractProjectName { dir: String },
#[error("Failed to create hidden .lsp_locks directory")]
LspLocksDirFailed,
#[error("Failed to create hidden .lsp_locks directory: {0}")]
LspLocksDirFailed(String),
#[error("Failed to create temp directory")]
TempDirFailed,
#[error("Failed to canonicalize path")]
Expand Down
5 changes: 4 additions & 1 deletion sway-lsp/src/handlers/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ pub async fn handle_did_change_text_document(
state: &ServerState,
params: DidChangeTextDocumentParams,
) -> Result<(), LanguageServerError> {
document::mark_file_as_dirty(&params.text_document.uri)?;
if let Err(err) = document::mark_file_as_dirty(&params.text_document.uri) {
tracing::warn!("Failed to mark file as dirty: {}", err);
}

let (uri, session) = state
.sessions
.uri_and_session_from_workspace(&params.text_document.uri)
Expand Down

0 comments on commit bf8d8a4

Please sign in to comment.