Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Move vfs-racer impls to RLS #964

Merged
merged 1 commit into from
Jul 29, 2018
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
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 @@ -52,6 +52,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 @@ -237,7 +239,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 @@ -321,7 +323,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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is minor and a thing of preference, but personally I'd find it a lot easier to read with racer::FileCache::new(RacerVfs(vfs)) as this limits what I'd expect to need to know - here it'd just be a impl racer::FileLoader for RacerVfs/*(Arc<Vfs>)*/ that is hiding somewhere 😉

Super minor though!

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

let location = pos_to_racer_location(params.position);
Expand Down Expand Up @@ -904,6 +906,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