mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +00:00
Upgrade ra_vfs to use new Filtering
Currently this matches the previous filtering, meaning all roots are filtered using the same rules.
This commit is contained in:
parent
1cd18f9237
commit
e70e2361b6
5 changed files with 61 additions and 10 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -928,7 +928,7 @@ dependencies = [
|
|||
"ra_hir 0.1.0",
|
||||
"ra_project_model 0.1.0",
|
||||
"ra_syntax 0.1.0",
|
||||
"ra_vfs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ra_vfs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"test_utils 0.1.0",
|
||||
]
|
||||
|
@ -1050,7 +1050,7 @@ dependencies = [
|
|||
"ra_project_model 0.1.0",
|
||||
"ra_syntax 0.1.0",
|
||||
"ra_text_edit 0.1.0",
|
||||
"ra_vfs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ra_vfs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1131,7 +1131,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ra_vfs"
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1996,7 +1996,7 @@ dependencies = [
|
|||
"checksum proptest 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea66c78d75f2c6e9f304269eaef90899798daecc69f1a625d5a3dd793ff3522"
|
||||
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
|
||||
"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
|
||||
"checksum ra_vfs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5978b0ced52f013ce44bfca6ac903141359e7cc3baea462a4a670de9e5087101"
|
||||
"checksum ra_vfs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1839e4e003d865b58b8b6c231aae6c463dfcd01bfbbddffbdb7662a7b5a627"
|
||||
"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
|
||||
"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
|
||||
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
|
|
|
@ -10,7 +10,7 @@ rustc-hash = "1.0"
|
|||
|
||||
failure = "0.1.4"
|
||||
|
||||
ra_vfs = "0.1.0"
|
||||
ra_vfs = "0.2.0"
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_db = { path = "../ra_db" }
|
||||
ra_hir = { path = "../ra_hir" }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::sync::Arc;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::collections::HashSet;
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
|
@ -9,7 +9,7 @@ use ra_db::{
|
|||
};
|
||||
use ra_hir::{db, HirInterner};
|
||||
use ra_project_model::ProjectWorkspace;
|
||||
use ra_vfs::{Vfs, VfsChange};
|
||||
use ra_vfs::{Vfs, VfsChange, RootEntry, Filter, RelativePath};
|
||||
|
||||
type Result<T> = std::result::Result<T, failure::Error>;
|
||||
|
||||
|
@ -43,6 +43,30 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
|
|||
SourceRootId(r.0.into())
|
||||
}
|
||||
|
||||
struct IncludeRustFiles;
|
||||
|
||||
impl IncludeRustFiles {
|
||||
fn to_entry(path: PathBuf) -> RootEntry {
|
||||
RootEntry::new(path, Box::new(Self {}))
|
||||
}
|
||||
}
|
||||
|
||||
impl Filter for IncludeRustFiles {
|
||||
fn include_dir(&self, dir_path: &RelativePath) -> bool {
|
||||
const IGNORED_FOLDERS: &[&str] = &["node_modules", "target", ".git"];
|
||||
|
||||
let is_ignored = dir_path.components().any(|c| IGNORED_FOLDERS.contains(&c.as_str()));
|
||||
|
||||
let hidden = dir_path.components().any(|c| c.as_str().starts_with("."));
|
||||
|
||||
!is_ignored && !hidden
|
||||
}
|
||||
|
||||
fn include_file(&self, file_path: &RelativePath) -> bool {
|
||||
file_path.extension() == Some("rs")
|
||||
}
|
||||
}
|
||||
|
||||
impl BatchDatabase {
|
||||
pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase {
|
||||
let mut db =
|
||||
|
@ -100,6 +124,7 @@ impl BatchDatabase {
|
|||
let mut roots = Vec::new();
|
||||
roots.push(root.clone());
|
||||
roots.extend(ws.to_roots());
|
||||
let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>();
|
||||
let (mut vfs, roots) = Vfs::new(roots);
|
||||
let mut load = |path: &Path| {
|
||||
let vfs_file = vfs.load(path);
|
||||
|
|
|
@ -19,7 +19,7 @@ lsp-types = "0.56.0"
|
|||
rustc-hash = "1.0"
|
||||
parking_lot = "0.7.0"
|
||||
|
||||
ra_vfs = "0.1.0"
|
||||
ra_vfs = "0.2.0"
|
||||
thread_worker = { path = "../thread_worker" }
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_text_edit = { path = "../ra_text_edit" }
|
||||
|
|
|
@ -8,8 +8,8 @@ use ra_ide_api::{
|
|||
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData,
|
||||
SourceRootId
|
||||
};
|
||||
use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
|
||||
use relative_path::RelativePathBuf;
|
||||
use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot, RootEntry, Filter};
|
||||
use relative_path::{RelativePath, RelativePathBuf};
|
||||
use parking_lot::RwLock;
|
||||
use failure::format_err;
|
||||
|
||||
|
@ -33,6 +33,30 @@ pub struct ServerWorld {
|
|||
pub vfs: Arc<RwLock<Vfs>>,
|
||||
}
|
||||
|
||||
struct IncludeRustFiles;
|
||||
|
||||
impl IncludeRustFiles {
|
||||
fn to_entry(path: PathBuf) -> RootEntry {
|
||||
RootEntry::new(path, Box::new(Self {}))
|
||||
}
|
||||
}
|
||||
|
||||
impl Filter for IncludeRustFiles {
|
||||
fn include_dir(&self, dir_path: &RelativePath) -> bool {
|
||||
const IGNORED_FOLDERS: &[&str] = &["node_modules", "target", ".git"];
|
||||
|
||||
let is_ignored = dir_path.components().any(|c| IGNORED_FOLDERS.contains(&c.as_str()));
|
||||
|
||||
let hidden = dir_path.components().any(|c| c.as_str().starts_with("."));
|
||||
|
||||
!is_ignored && !hidden
|
||||
}
|
||||
|
||||
fn include_file(&self, file_path: &RelativePath) -> bool {
|
||||
file_path.extension() == Some("rs")
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerWorldState {
|
||||
pub fn new(root: PathBuf, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState {
|
||||
let mut change = AnalysisChange::new();
|
||||
|
@ -42,6 +66,8 @@ impl ServerWorldState {
|
|||
for ws in workspaces.iter() {
|
||||
roots.extend(ws.to_roots());
|
||||
}
|
||||
let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>();
|
||||
|
||||
let (mut vfs, roots) = Vfs::new(roots);
|
||||
let roots_to_scan = roots.len();
|
||||
for r in roots {
|
||||
|
|
Loading…
Reference in a new issue