Skip to content

Commit

Permalink
Upgrade ra_vfs to use new Filtering
Browse files Browse the repository at this point in the history
Currently this matches the previous filtering, meaning all roots are filtered
using the same rules.
  • Loading branch information
vipentti committed Mar 18, 2019
1 parent 1cd18f9 commit c058887
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ incremental = true
debug = true

[patch.'crates-io']
ra_vfs = { git="https://github.com/vipentti/ra_vfs.git", rev = "d7e2fa6"}
29 changes: 27 additions & 2 deletions crates/ra_batch/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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>;

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 28 additions & 2 deletions crates/ra_lsp_server/src/server_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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 {
Expand Down

0 comments on commit c058887

Please sign in to comment.