fix(lsp): inlay hints span issue with user config scripts (#15071)

# Description

Fixes this:

![image](https://github.com/user-attachments/assets/98b523dd-df30-4e85-b069-20aaad0d9bf5)

# User-Facing Changes

# Tests + Formatting

I can't figure out how to test this atm.
Happy to do it if someone show me some hints how.

# After Submitting
This commit is contained in:
zc he 2025-02-10 23:15:03 +08:00 committed by GitHub
parent a7830ac1fd
commit c6fc6bd5a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 2 deletions

View File

@ -160,6 +160,7 @@ impl LanguageServer {
}
}
/// TODO: test for files loaded as user config
#[cfg(test)]
mod tests {
use crate::path_to_uri;

View File

@ -880,7 +880,9 @@ impl EngineState {
}
}
pub fn files(&self) -> impl Iterator<Item = &CachedFile> {
pub fn files(
&self,
) -> impl DoubleEndedIterator<Item = &CachedFile> + ExactSizeIterator<Item = &CachedFile> {
self.files.iter()
}

View File

@ -368,7 +368,15 @@ impl<'a> StateWorkingSet<'a> {
}
pub fn get_span_for_filename(&self, filename: &str) -> Option<Span> {
let file_id = self.files().position(|file| &*file.name == filename)?;
let predicate = |file: &CachedFile| &*file.name == filename;
// search from end to start, in case there're duplicated files with the same name
let file_id = self
.delta
.files
.iter()
.rposition(predicate)
.map(|idx| idx + self.permanent_state.num_files())
.or_else(|| self.permanent_state.files().rposition(predicate))?;
let file_id = FileId::new(file_id);
Some(self.get_span_for_file(file_id))