diff options
| author | Kirill Bulatov <mail4score@gmail.com> | 2023-08-29 14:19:17 +0300 |
|---|---|---|
| committer | Kirill Bulatov <mail4score@gmail.com> | 2023-09-02 18:28:36 +0300 |
| commit | caf018507aed5f627100c8c5d625edfac0bf73a8 (patch) | |
| tree | 6ebe01a36119ec4f4c6567a6af674f138a7ad5b1 | |
| parent | 10464c7c42950f1138290670c7177873f8fc3cbe (diff) | |
| download | rust-caf018507aed5f627100c8c5d625edfac0bf73a8.tar.gz rust-caf018507aed5f627100c8c5d625edfac0bf73a8.zip | |
Ensure resolved hint's file exists
| -rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 4 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/handlers/request.rs | 2 | ||||
| -rw-r--r-- | crates/vfs/src/lib.rs | 5 |
3 files changed, 11 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 22a7dd1548f..869afbe907d 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -489,6 +489,10 @@ impl GlobalStateSnapshot { pub(crate) fn vfs_memory_usage(&self) -> usize { self.vfs.read().0.memory_usage() } + + pub(crate) fn file_exists(&self, file_id: FileId) -> bool { + self.vfs.read().0.exists(file_id) + } } pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url { diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs index dbf3a4792d6..a21206b5b13 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -1438,6 +1438,8 @@ pub(crate) fn handle_inlay_hints_resolve( let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?; let file_id = FileId(resolve_data.file_id); + anyhow::ensure!(snap.file_exists(file_id), "Invalid LSP resolve data"); + let line_index = snap.file_line_index(file_id)?; let range = from_proto::text_range( &line_index, diff --git a/crates/vfs/src/lib.rs b/crates/vfs/src/lib.rs index fe3dfe61968..06004adad34 100644 --- a/crates/vfs/src/lib.rs +++ b/crates/vfs/src/lib.rs @@ -184,6 +184,11 @@ impl Vfs { mem::take(&mut self.changes) } + /// Provides a panic-less way to verify file_id validity. + pub fn exists(&self, file_id: FileId) -> bool { + self.get(file_id).is_some() + } + /// Returns the id associated with `path` /// /// - If `path` does not exists in the `Vfs`, allocate a new id for it, associated with a |
