mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Document vfs private items
This commit is contained in:
parent
311ec70d03
commit
4b71c8332d
5 changed files with 117 additions and 2 deletions
|
@ -5,6 +5,7 @@ use rustc_hash::FxHashMap;
|
|||
|
||||
use crate::{FileId, VfsPath};
|
||||
|
||||
/// Structure to map between [`VfsPath`] and [`FileId`].
|
||||
#[derive(Default)]
|
||||
pub(crate) struct PathInterner {
|
||||
map: FxHashMap<VfsPath, FileId>,
|
||||
|
@ -12,9 +13,17 @@ pub(crate) struct PathInterner {
|
|||
}
|
||||
|
||||
impl PathInterner {
|
||||
/// Get the id corresponding to `path`.
|
||||
///
|
||||
/// If `path` does not exists in `self`, returns [`None`].
|
||||
pub(crate) fn get(&self, path: &VfsPath) -> Option<FileId> {
|
||||
self.map.get(path).copied()
|
||||
}
|
||||
|
||||
/// Insert `path` in `self`.
|
||||
///
|
||||
/// - If `path` already exists in `self`, returns its associated id;
|
||||
/// - Else, returns a newly allocated id.
|
||||
pub(crate) fn intern(&mut self, path: VfsPath) -> FileId {
|
||||
if let Some(id) = self.get(&path) {
|
||||
return id;
|
||||
|
@ -25,6 +34,11 @@ impl PathInterner {
|
|||
id
|
||||
}
|
||||
|
||||
/// Returns the path corresponding to `id`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `id` does not exists in `self`.
|
||||
pub(crate) fn lookup(&self, id: FileId) -> &VfsPath {
|
||||
&self.vec[id.0 as usize]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue