Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade ra_vfs to use new Filtering #994

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 1 addition & 1 deletion crates/ra_batch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
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
2 changes: 1 addition & 1 deletion crates/ra_lsp_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
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