[ty] Remove FileLookupError (#19323)

## Summary

This PR removes the `FileLookupError` as it's not really required. The
original intention was that this would be returned from the `.file`
lookup to the different handlers but we've since moved the logic of
"lookup file and add trace message if file unavailable with the reason"
under the `file_ok` method which all of the handlers use.
This commit is contained in:
Dhruv Manilawala
2025-07-14 19:05:14 +05:30
committed by GitHub
parent f7973ac870
commit 8a217e5920
8 changed files with 20 additions and 30 deletions

View File

@@ -38,7 +38,7 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler {
return Ok(None);
}
let Some(file) = snapshot.file_ok(db) else {
let Some(file) = snapshot.file(db) else {
return Ok(None);
};

View File

@@ -34,7 +34,7 @@ impl BackgroundDocumentRequestHandler for GotoTypeDefinitionRequestHandler {
return Ok(None);
}
let Some(file) = snapshot.file_ok(db) else {
let Some(file) = snapshot.file(db) else {
return Ok(None);
};

View File

@@ -34,7 +34,7 @@ impl BackgroundDocumentRequestHandler for HoverRequestHandler {
return Ok(None);
}
let Some(file) = snapshot.file_ok(db) else {
let Some(file) = snapshot.file(db) else {
return Ok(None);
};

View File

@@ -33,7 +33,7 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler {
return Ok(None);
}
let Some(file) = snapshot.file_ok(db) else {
let Some(file) = snapshot.file(db) else {
return Ok(None);
};

View File

@@ -30,7 +30,7 @@ impl BackgroundDocumentRequestHandler for SemanticTokensRequestHandler {
return Ok(None);
}
let Some(file) = snapshot.file_ok(db) else {
let Some(file) = snapshot.file(db) else {
return Ok(None);
};

View File

@@ -32,7 +32,7 @@ impl BackgroundDocumentRequestHandler for SemanticTokensRangeRequestHandler {
return Ok(None);
}
let Some(file) = snapshot.file_ok(db) else {
let Some(file) = snapshot.file(db) else {
return Ok(None);
};

View File

@@ -36,7 +36,7 @@ impl BackgroundDocumentRequestHandler for SignatureHelpRequestHandler {
return Ok(None);
}
let Some(file) = snapshot.file_ok(db) else {
let Some(file) = snapshot.file(db) else {
return Ok(None);
};

View File

@@ -508,35 +508,25 @@ impl DocumentSnapshot {
self.document_query_result.as_ref()
}
pub(crate) fn file_ok(&self, db: &dyn Db) -> Option<File> {
match self.file(db) {
Ok(file) => Some(file),
Err(err) => {
tracing::debug!("Failed to resolve file: {}", err);
None
}
}
}
fn file(&self, db: &dyn Db) -> Result<File, FileLookupError> {
pub(crate) fn file(&self, db: &dyn Db) -> Option<File> {
let document = match self.document() {
Ok(document) => document,
Err(err) => return Err(FileLookupError::DocumentQuery(err.clone())),
Err(err) => {
tracing::debug!("Failed to resolve file: {}", err);
return None;
}
};
document
.file(db)
.ok_or_else(|| FileLookupError::NotFound(document.file_path().clone()))
let file = document.file(db);
if file.is_none() {
tracing::debug!(
"Failed to resolve file: file not found for path `{}`",
document.file_path()
);
}
file
}
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum FileLookupError {
#[error("file not found for path `{0}`")]
NotFound(AnySystemPath),
#[error(transparent)]
DocumentQuery(DocumentQueryError),
}
/// An immutable snapshot of the current state of [`Session`].
pub(crate) struct SessionSnapshot {
projects: Vec<ProjectDatabase>,