|
13 | 13 | use crate::actions::InitActionContext;
|
14 | 14 | use rls_data as data;
|
15 | 15 | use url::Url;
|
16 |
| -use rls_vfs::FileContents; |
| 16 | +use rls_vfs::{self, Vfs, FileContents}; |
17 | 17 | use racer;
|
18 | 18 | use rustfmt_nightly::{Session, FileLines, FileName, Input as FmtInput, Range as RustfmtRange};
|
19 | 19 | use serde_json;
|
@@ -54,6 +54,8 @@ pub use crate::lsp_data::request::{
|
54 | 54 | use std::collections::HashMap;
|
55 | 55 | use std::path::Path;
|
56 | 56 | use std::sync::atomic::Ordering;
|
| 57 | +use std::sync::Arc; |
| 58 | +use std::io; |
57 | 59 |
|
58 | 60 |
|
59 | 61 | /// Represent the result of a deglob action for a single wildcard import.
|
@@ -239,7 +241,7 @@ impl RequestAction for Definition {
|
239 | 241 | let racer_receiver = {
|
240 | 242 | if ctx.config.lock().unwrap().goto_def_racer_fallback {
|
241 | 243 | Some(work_pool::receive_from_thread(move || {
|
242 |
| - let cache = racer::FileCache::new(vfs); |
| 244 | + let cache = racer_cache(vfs); |
243 | 245 | let session = racer::Session::new(&cache);
|
244 | 246 | let location = pos_to_racer_location(params.position);
|
245 | 247 |
|
@@ -323,7 +325,7 @@ impl RequestAction for Completion {
|
323 | 325 | let vfs = ctx.vfs;
|
324 | 326 | let file_path = parse_file_path!(¶ms.text_document.uri, "complete")?;
|
325 | 327 |
|
326 |
| - let cache = racer::FileCache::new(vfs); |
| 328 | + let cache = racer_cache(vfs); |
327 | 329 | let session = racer::Session::new(&cache);
|
328 | 330 |
|
329 | 331 | let location = pos_to_racer_location(params.position);
|
@@ -906,6 +908,23 @@ impl RequestAction for CodeLensRequest {
|
906 | 908 | }
|
907 | 909 | }
|
908 | 910 |
|
| 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 | + |
909 | 928 | #[cfg(test)]
|
910 | 929 | mod test {
|
911 | 930 | use super::*;
|
|
0 commit comments