Skip to content

Commit

Permalink
Merge pull request rust-lang#964 from matklad/racer-vfs
Browse files Browse the repository at this point in the history
Move vfs-racer impls to RLS
  • Loading branch information
nrc authored Jul 29, 2018
2 parents 41feb3f + 10cd410 commit a528e2f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 0 additions & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rls-blacklist = "0.1.2"
rls-data = { version = "0.16", features = ["serialize-serde"] }
rls-rustc = "0.4.0"
rls-span = { version = "0.4", features = ["serialize-serde"] }
rls-vfs = { version = "0.4.6", features = ["racer-impls"] }
rls-vfs = { version = "0.4.6" }
rustfmt-nightly = { git = "https://github.com/rust-lang-nursery/rustfmt", rev = "7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b" }
serde = "1.0"
serde_json = "1.0"
Expand Down
25 changes: 22 additions & 3 deletions src/actions/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use crate::actions::InitActionContext;
use rls_data as data;
use url::Url;
use rls_vfs::FileContents;
use rls_vfs::{self, Vfs, FileContents};
use racer;
use rustfmt_nightly::{Session, FileLines, FileName, Input as FmtInput, Range as RustfmtRange};
use serde_json;
Expand Down Expand Up @@ -54,6 +54,8 @@ pub use crate::lsp_data::request::{
use std::collections::HashMap;
use std::path::Path;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::io;


/// Represent the result of a deglob action for a single wildcard import.
Expand Down Expand Up @@ -239,7 +241,7 @@ impl RequestAction for Definition {
let racer_receiver = {
if ctx.config.lock().unwrap().goto_def_racer_fallback {
Some(work_pool::receive_from_thread(move || {
let cache = racer::FileCache::new(vfs);
let cache = racer_cache(vfs);
let session = racer::Session::new(&cache);
let location = pos_to_racer_location(params.position);

Expand Down Expand Up @@ -323,7 +325,7 @@ impl RequestAction for Completion {
let vfs = ctx.vfs;
let file_path = parse_file_path!(&params.text_document.uri, "complete")?;

let cache = racer::FileCache::new(vfs);
let cache = racer_cache(vfs);
let session = racer::Session::new(&cache);

let location = pos_to_racer_location(params.position);
Expand Down Expand Up @@ -906,6 +908,23 @@ impl RequestAction for CodeLensRequest {
}
}

fn racer_cache(vfs: Arc<Vfs>) -> racer::FileCache {
struct RacerVfs(Arc<Vfs>);
impl racer::FileLoader for RacerVfs {
fn load_file(&self, path: &Path) -> io::Result<String> {
match self.0.load_file(path) {
Ok(FileContents::Text(t)) => Ok(t),
Ok(FileContents::Binary(_)) => Err(
io::Error::new(io::ErrorKind::Other, rls_vfs::Error::BadFileKind),
),
Err(err) => Err(io::Error::new(io::ErrorKind::Other, err)),
}
}
}
racer::FileCache::new(RacerVfs(vfs))
}


#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit a528e2f

Please sign in to comment.