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

Commit a528e2f

Browse files
authored
Merge pull request #964 from matklad/racer-vfs
Move vfs-racer impls to RLS
2 parents 41feb3f + 10cd410 commit a528e2f

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ rls-blacklist = "0.1.2"
3131
rls-data = { version = "0.16", features = ["serialize-serde"] }
3232
rls-rustc = "0.4.0"
3333
rls-span = { version = "0.4", features = ["serialize-serde"] }
34-
rls-vfs = { version = "0.4.6", features = ["racer-impls"] }
34+
rls-vfs = { version = "0.4.6" }
3535
rustfmt-nightly = { git = "https://github.com/rust-lang-nursery/rustfmt", rev = "7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b" }
3636
serde = "1.0"
3737
serde_json = "1.0"

src/actions/requests.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use crate::actions::InitActionContext;
1414
use rls_data as data;
1515
use url::Url;
16-
use rls_vfs::FileContents;
16+
use rls_vfs::{self, Vfs, FileContents};
1717
use racer;
1818
use rustfmt_nightly::{Session, FileLines, FileName, Input as FmtInput, Range as RustfmtRange};
1919
use serde_json;
@@ -54,6 +54,8 @@ pub use crate::lsp_data::request::{
5454
use std::collections::HashMap;
5555
use std::path::Path;
5656
use std::sync::atomic::Ordering;
57+
use std::sync::Arc;
58+
use std::io;
5759

5860

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

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

326-
let cache = racer::FileCache::new(vfs);
328+
let cache = racer_cache(vfs);
327329
let session = racer::Session::new(&cache);
328330

329331
let location = pos_to_racer_location(params.position);
@@ -906,6 +908,23 @@ impl RequestAction for CodeLensRequest {
906908
}
907909
}
908910

911+
fn racer_cache(vfs: Arc<Vfs>) -> racer::FileCache {
912+
struct RacerVfs(Arc<Vfs>);
913+
impl racer::FileLoader for RacerVfs {
914+
fn load_file(&self, path: &Path) -> io::Result<String> {
915+
match self.0.load_file(path) {
916+
Ok(FileContents::Text(t)) => Ok(t),
917+
Ok(FileContents::Binary(_)) => Err(
918+
io::Error::new(io::ErrorKind::Other, rls_vfs::Error::BadFileKind),
919+
),
920+
Err(err) => Err(io::Error::new(io::ErrorKind::Other, err)),
921+
}
922+
}
923+
}
924+
racer::FileCache::new(RacerVfs(vfs))
925+
}
926+
927+
909928
#[cfg(test)]
910929
mod test {
911930
use super::*;

0 commit comments

Comments
 (0)