mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Merge commit 'aa9bc86125
' into sync-from-ra
This commit is contained in:
parent
1570299af4
commit
c48062fe2a
598 changed files with 57696 additions and 17615 deletions
|
@ -5,8 +5,8 @@
|
|||
use std::fmt;
|
||||
|
||||
use fst::{IntoStreamer, Streamer};
|
||||
use nohash_hasher::IntMap;
|
||||
use rustc_hash::FxHashMap;
|
||||
use stdx::hash::NoHashHashMap;
|
||||
|
||||
use crate::{AnchoredPath, FileId, Vfs, VfsPath};
|
||||
|
||||
|
@ -14,7 +14,7 @@ use crate::{AnchoredPath, FileId, Vfs, VfsPath};
|
|||
#[derive(Default, Clone, Eq, PartialEq)]
|
||||
pub struct FileSet {
|
||||
files: FxHashMap<VfsPath, FileId>,
|
||||
paths: NoHashHashMap<FileId, VfsPath>,
|
||||
paths: IntMap<FileId, VfsPath>,
|
||||
}
|
||||
|
||||
impl FileSet {
|
||||
|
|
|
@ -62,7 +62,8 @@ pub use paths::{AbsPath, AbsPathBuf};
|
|||
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
||||
pub struct FileId(pub u32);
|
||||
|
||||
impl stdx::hash::NoHashHashable for FileId {}
|
||||
/// safe because `FileId` is a newtype of `u32`
|
||||
impl nohash_hasher::IsEnabled for FileId {}
|
||||
|
||||
/// Storage for all files read by rust-analyzer.
|
||||
///
|
||||
|
@ -108,13 +109,6 @@ pub enum ChangeKind {
|
|||
}
|
||||
|
||||
impl Vfs {
|
||||
/// Amount of files currently stored.
|
||||
///
|
||||
/// Note that this includes deleted files.
|
||||
pub fn len(&self) -> usize {
|
||||
self.data.len()
|
||||
}
|
||||
|
||||
/// Id of the given path if it exists in the `Vfs` and is not deleted.
|
||||
pub fn file_id(&self, path: &VfsPath) -> Option<FileId> {
|
||||
self.interner.get(path).filter(|&it| self.get(it).is_some())
|
||||
|
@ -139,6 +133,11 @@ impl Vfs {
|
|||
self.get(file_id).as_deref().unwrap()
|
||||
}
|
||||
|
||||
/// Returns the overall memory usage for the stored files.
|
||||
pub fn memory_usage(&self) -> usize {
|
||||
self.data.iter().flatten().map(|d| d.capacity()).sum()
|
||||
}
|
||||
|
||||
/// Returns an iterator over the stored ids and their corresponding paths.
|
||||
///
|
||||
/// This will skip deleted files.
|
||||
|
@ -158,16 +157,18 @@ impl Vfs {
|
|||
///
|
||||
/// If the path does not currently exists in the `Vfs`, allocates a new
|
||||
/// [`FileId`] for it.
|
||||
pub fn set_file_contents(&mut self, path: VfsPath, contents: Option<Vec<u8>>) -> bool {
|
||||
pub fn set_file_contents(&mut self, path: VfsPath, mut contents: Option<Vec<u8>>) -> bool {
|
||||
let file_id = self.alloc_file_id(path);
|
||||
let change_kind = match (&self.get(file_id), &contents) {
|
||||
let change_kind = match (self.get(file_id), &contents) {
|
||||
(None, None) => return false,
|
||||
(Some(old), Some(new)) if old == new => return false,
|
||||
(None, Some(_)) => ChangeKind::Create,
|
||||
(Some(_), None) => ChangeKind::Delete,
|
||||
(Some(_), Some(_)) => ChangeKind::Modify,
|
||||
};
|
||||
|
||||
if let Some(contents) = &mut contents {
|
||||
contents.shrink_to_fit();
|
||||
}
|
||||
*self.get_mut(file_id) = contents;
|
||||
self.changes.push(ChangedFile { file_id, change_kind });
|
||||
true
|
||||
|
|
|
@ -107,10 +107,7 @@ impl VfsPath {
|
|||
/// Returns `self`'s base name and file extension.
|
||||
pub fn name_and_extension(&self) -> Option<(&str, Option<&str>)> {
|
||||
match &self.0 {
|
||||
VfsPathRepr::PathBuf(p) => Some((
|
||||
p.file_stem()?.to_str()?,
|
||||
p.extension().and_then(|extension| extension.to_str()),
|
||||
)),
|
||||
VfsPathRepr::PathBuf(p) => p.name_and_extension(),
|
||||
VfsPathRepr::VirtualPath(p) => p.name_and_extension(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue