1
- use cargo:: core:: Resolve ;
2
1
use rls_span;
3
2
use syntax:: codemap;
4
3
use std:: fs:: File ;
@@ -7,14 +6,15 @@ use std::{vec, fmt};
7
6
use std:: { str, path} ;
8
7
use std:: io;
9
8
use std:: cell:: RefCell ;
10
- use std:: collections:: { hash_map , HashMap } ;
9
+ use std:: collections:: HashMap ;
11
10
use std:: ops:: { Deref , Range } ;
12
11
use std:: slice;
13
12
use std:: cmp:: { min, max, Ordering } ;
14
13
use std:: iter:: { Fuse , Iterator } ;
15
14
use std:: rc:: Rc ;
16
15
use codeiter:: StmtIndicesIter ;
17
16
use matchers:: ImportInfo ;
17
+ use project_model:: ProjectModelProvider ;
18
18
19
19
use scopes;
20
20
use nameres;
@@ -261,7 +261,7 @@ impl Match {
261
261
/// but in the interest of minimizing the crate's public API surface it's exposed
262
262
/// as a private method for now.
263
263
fn is_same_as ( & self , other : & Match ) -> bool {
264
- self . point == other. point
264
+ self . point == other. point
265
265
&& self . matchstr == other. matchstr
266
266
&& self . filepath == other. filepath
267
267
}
@@ -560,7 +560,7 @@ impl IndexedSource {
560
560
lines : RefCell :: new ( Vec :: new ( ) )
561
561
}
562
562
}
563
-
563
+
564
564
pub fn with_src ( & self , new_src : String ) -> IndexedSource {
565
565
IndexedSource {
566
566
code : new_src,
@@ -704,7 +704,7 @@ impl<'c> Src<'c> {
704
704
pub fn end ( & self ) -> BytePos {
705
705
self . range . end
706
706
}
707
-
707
+
708
708
pub fn iter_stmts ( & self ) -> Fuse < StmtIndicesIter < CodeChunkIter > > {
709
709
StmtIndicesIter :: from_parts ( self , self . chunk_indices ( ) )
710
710
}
@@ -796,7 +796,7 @@ pub struct FileCache {
796
796
masked_map : RefCell < HashMap < path:: PathBuf , Rc < IndexedSource > > > ,
797
797
798
798
/// The file loader
799
- loader : Box < FileLoader > ,
799
+ pub ( crate ) loader : Box < FileLoader > ,
800
800
}
801
801
802
802
/// Used by the FileCache for loading files
@@ -920,23 +920,6 @@ pub trait SessionExt {
920
920
fn load_file_and_mask_comments ( & self , & path:: Path ) -> Rc < IndexedSource > ;
921
921
}
922
922
923
- /// dependencies info of a package
924
- #[ derive( Clone , Debug , Default ) ]
925
- pub struct Dependencies {
926
- /// dependencies of a package(library name -> src_path)
927
- inner : HashMap < String , path:: PathBuf > ,
928
- }
929
-
930
- impl Dependencies {
931
- /// Get src path from a library name.
932
- /// e.g. from query string `bit_set` it returns
933
- /// `~/.cargo/registry/src/github.1485827954.workers.dev-1ecc6299db9ec823/bit-set-0.4.0`
934
- pub fn get_src_path ( & self , query : & str ) -> Option < path:: PathBuf > {
935
- let p = self . inner . get ( query) ?;
936
- Some ( p. to_owned ( ) )
937
- }
938
- }
939
-
940
923
/// Context for a Racer operation
941
924
pub struct Session < ' c > {
942
925
/// Cache for files
@@ -948,10 +931,7 @@ pub struct Session<'c> {
948
931
pub generic_impls : RefCell < HashMap < ( path:: PathBuf , BytePos ) ,
949
932
Rc < Vec < ( BytePos , String ,
950
933
ast:: GenericsArgs , ast:: ImplVisitor ) > > > > ,
951
- /// Cached dependencie (path to Cargo.toml -> Depedencies)
952
- cached_deps : RefCell < HashMap < path:: PathBuf , Rc < Dependencies > > > ,
953
- /// Cached lockfiles (path to Cargo.lock -> Resolve)
954
- cached_lockfile : RefCell < HashMap < path:: PathBuf , Rc < Resolve > > > ,
934
+ pub project_model : Box < ProjectModelProvider + ' c > ,
955
935
}
956
936
957
937
impl < ' c > fmt:: Debug for Session < ' c > {
@@ -976,15 +956,19 @@ impl<'c> Session<'c> {
976
956
/// ```
977
957
///
978
958
/// [`FileCache`]: struct.FileCache.html
959
+ #[ cfg( feature = "cargo" ) ]
979
960
pub fn new ( cache : & ' c FileCache ) -> Session < ' c > {
961
+ let project_model = :: project_model:: cargo:: cargo_project_model ( cache) ;
962
+ Session :: with_project_model ( cache, project_model)
963
+ }
964
+
965
+ pub fn with_project_model ( cache : & ' c FileCache , project_model : Box < ProjectModelProvider + ' c > ) -> Session < ' c > {
980
966
Session {
981
967
cache,
982
968
generic_impls : Default :: default ( ) ,
983
- cached_deps : Default :: default ( ) ,
984
- cached_lockfile : Default :: default ( ) ,
969
+ project_model,
985
970
}
986
971
}
987
-
988
972
/// Specify the contents of a file to be used in completion operations
989
973
///
990
974
/// The path to the file and the file's contents must both be specified.
@@ -1012,54 +996,6 @@ impl<'c> Session<'c> {
1012
996
let masked = self . cache . masked_map . borrow ( ) ;
1013
997
raw. contains_key ( path) && masked. contains_key ( path)
1014
998
}
1015
-
1016
- /// Get cached dependencies from manifest path(abs path of Cargo.toml) if they exist.
1017
- pub ( crate ) fn get_deps < P : AsRef < path:: Path > > ( & self , manifest : P ) -> Option < Rc < Dependencies > > {
1018
- let manifest = manifest. as_ref ( ) ;
1019
- let deps = self . cached_deps . borrow ( ) ;
1020
- deps. get ( manifest) . map ( |rc| Rc :: clone ( & rc) )
1021
- }
1022
-
1023
- /// Cache dependencies into session.
1024
- pub ( crate ) fn cache_deps < P : AsRef < path:: Path > > (
1025
- & self ,
1026
- manifest : P ,
1027
- cache : HashMap < String , path:: PathBuf > ,
1028
- ) {
1029
- let manifest = manifest. as_ref ( ) . to_owned ( ) ;
1030
- let deps = Dependencies {
1031
- inner : cache,
1032
- } ;
1033
- self . cached_deps . borrow_mut ( ) . insert ( manifest, Rc :: new ( deps) ) ;
1034
- }
1035
-
1036
- /// load `Cargo.lock` file using fileloader
1037
- // TODO: use result
1038
- pub ( crate ) fn load_lockfile < P , F > ( & self , path : P , resolver : F ) -> Option < Rc < Resolve > >
1039
- where
1040
- P : AsRef < path:: Path > ,
1041
- F : FnOnce ( & str ) -> Option < Resolve >
1042
- {
1043
- let pathbuf = path. as_ref ( ) . to_owned ( ) ;
1044
- match self . cached_lockfile . borrow_mut ( ) . entry ( pathbuf) {
1045
- hash_map:: Entry :: Occupied ( occupied) => Some ( Rc :: clone ( occupied. get ( ) ) ) ,
1046
- hash_map:: Entry :: Vacant ( vacant) => {
1047
- let contents = match self . cache . loader . load_file ( path. as_ref ( ) ) {
1048
- Ok ( f) => f,
1049
- Err ( e) => {
1050
- debug ! (
1051
- "[Session::load_lock_file] Failed to load {:?}: {}" ,
1052
- path. as_ref( ) ,
1053
- e
1054
- ) ;
1055
- return None ;
1056
- }
1057
- } ;
1058
- resolver ( & contents)
1059
- . map ( |res| Rc :: clone ( vacant. insert ( Rc :: new ( res) ) ) )
1060
- }
1061
- }
1062
- }
1063
999
}
1064
1000
1065
1001
impl < ' c > SessionExt for Session < ' c > {
@@ -1257,10 +1193,10 @@ fn complete_from_file_(
1257
1193
trace ! ( "Path is in fn declaration: `{}`" , expr) ;
1258
1194
1259
1195
return nameres:: resolve_method (
1260
- pos,
1261
- src. as_src ( ) ,
1262
- expr,
1263
- filepath,
1196
+ pos,
1197
+ src. as_src ( ) ,
1198
+ expr,
1199
+ filepath,
1264
1200
SearchType :: StartsWith ,
1265
1201
session,
1266
1202
& ImportInfo :: default ( ) ,
0 commit comments