aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/db.rs12
-rw-r--r--crates/ra_ide_api/src/lib.rs11
-rw-r--r--crates/ra_lsp_server/src/init.rs14
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs2
-rw-r--r--crates/ra_lsp_server/src/world.rs8
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/config.ts4
-rw-r--r--editors/code/src/server.ts3
8 files changed, 48 insertions, 11 deletions
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index cccf0ada4..b3f395502 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -41,6 +41,12 @@ impl salsa::Database for RootDatabase {
41 41
42impl Default for RootDatabase { 42impl Default for RootDatabase {
43 fn default() -> RootDatabase { 43 fn default() -> RootDatabase {
44 RootDatabase::new(None)
45 }
46}
47
48impl RootDatabase {
49 pub fn new(lru_capacity: Option<usize>) -> RootDatabase {
44 let mut db = RootDatabase { 50 let mut db = RootDatabase {
45 runtime: salsa::Runtime::default(), 51 runtime: salsa::Runtime::default(),
46 last_gc: time::Instant::now(), 52 last_gc: time::Instant::now(),
@@ -49,9 +55,9 @@ impl Default for RootDatabase {
49 db.set_crate_graph(Default::default()); 55 db.set_crate_graph(Default::default());
50 db.set_local_roots(Default::default()); 56 db.set_local_roots(Default::default());
51 db.set_library_roots(Default::default()); 57 db.set_library_roots(Default::default());
52 let lru_cap = ra_db::DEFAULT_LRU_CAP; 58 let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP);
53 db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_cap); 59 db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity);
54 db.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_cap); 60 db.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity);
55 db 61 db
56 } 62 }
57} 63}
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index dbebf50a6..8741e736f 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -242,12 +242,21 @@ pub struct CallInfo {
242} 242}
243 243
244/// `AnalysisHost` stores the current state of the world. 244/// `AnalysisHost` stores the current state of the world.
245#[derive(Debug, Default)] 245#[derive(Debug)]
246pub struct AnalysisHost { 246pub struct AnalysisHost {
247 db: db::RootDatabase, 247 db: db::RootDatabase,
248} 248}
249 249
250impl Default for AnalysisHost {
251 fn default() -> AnalysisHost {
252 AnalysisHost::new(None)
253 }
254}
255
250impl AnalysisHost { 256impl AnalysisHost {
257 pub fn new(lru_capcity: Option<usize>) -> AnalysisHost {
258 AnalysisHost { db: db::RootDatabase::new(lru_capcity) }
259 }
251 /// Returns a snapshot of the current state, which you can query for 260 /// Returns a snapshot of the current state, which you can query for
252 /// semantic information. 261 /// semantic information.
253 pub fn analysis(&self) -> Analysis { 262 pub fn analysis(&self) -> Analysis {
diff --git a/crates/ra_lsp_server/src/init.rs b/crates/ra_lsp_server/src/init.rs
index 1b77e0312..b894b449d 100644
--- a/crates/ra_lsp_server/src/init.rs
+++ b/crates/ra_lsp_server/src/init.rs
@@ -17,11 +17,17 @@ pub struct InitializationOptions {
17 /// Defaults to `true` 17 /// Defaults to `true`
18 #[serde(deserialize_with = "nullable_bool_true")] 18 #[serde(deserialize_with = "nullable_bool_true")]
19 pub show_workspace_loaded: bool, 19 pub show_workspace_loaded: bool,
20
21 pub lru_capacity: Option<usize>,
20} 22}
21 23
22impl Default for InitializationOptions { 24impl Default for InitializationOptions {
23 fn default() -> InitializationOptions { 25 fn default() -> InitializationOptions {
24 InitializationOptions { publish_decorations: false, show_workspace_loaded: true } 26 InitializationOptions {
27 publish_decorations: false,
28 show_workspace_loaded: true,
29 lru_capacity: None,
30 }
25 } 31 }
26} 32}
27 33
@@ -54,8 +60,10 @@ mod test {
54 assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap()); 60 assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap());
55 assert_eq!( 61 assert_eq!(
56 default, 62 default,
57 serde_json::from_str(r#"{"publishDecorations":null, "showWorkspaceLoaded":null}"#) 63 serde_json::from_str(
58 .unwrap() 64 r#"{"publishDecorations":null, "showWorkspaceLoaded":null, "lruCapacity":null}"#
65 )
66 .unwrap()
59 ); 67 );
60 } 68 }
61} 69}
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 090fb9b1b..0790ea472 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -73,7 +73,7 @@ pub fn main_loop(
73 loaded_workspaces 73 loaded_workspaces
74 }; 74 };
75 75
76 let mut state = WorldState::new(ws_roots, workspaces); 76 let mut state = WorldState::new(ws_roots, workspaces, options.lru_capacity);
77 77
78 let pool = ThreadPool::new(THREADPOOL_SIZE); 78 let pool = ThreadPool::new(THREADPOOL_SIZE);
79 let (task_sender, task_receiver) = unbounded::<Task>(); 79 let (task_sender, task_receiver) = unbounded::<Task>();
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs
index cd8df4fdb..f9ce570ca 100644
--- a/crates/ra_lsp_server/src/world.rs
+++ b/crates/ra_lsp_server/src/world.rs
@@ -46,7 +46,11 @@ pub struct WorldSnapshot {
46} 46}
47 47
48impl WorldState { 48impl WorldState {
49 pub fn new(folder_roots: Vec<PathBuf>, workspaces: Vec<ProjectWorkspace>) -> WorldState { 49 pub fn new(
50 folder_roots: Vec<PathBuf>,
51 workspaces: Vec<ProjectWorkspace>,
52 lru_capacity: Option<usize>,
53 ) -> WorldState {
50 let mut change = AnalysisChange::new(); 54 let mut change = AnalysisChange::new();
51 55
52 let mut roots = Vec::new(); 56 let mut roots = Vec::new();
@@ -74,7 +78,7 @@ impl WorldState {
74 } 78 }
75 change.set_crate_graph(crate_graph); 79 change.set_crate_graph(crate_graph);
76 80
77 let mut analysis_host = AnalysisHost::default(); 81 let mut analysis_host = AnalysisHost::new(lru_capacity);
78 analysis_host.apply_change(change); 82 analysis_host.apply_change(change);
79 WorldState { 83 WorldState {
80 roots_to_scan, 84 roots_to_scan,
diff --git a/editors/code/package.json b/editors/code/package.json
index 05c808394..c2ed8d126 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -232,6 +232,11 @@
232 ], 232 ],
233 "default": "off", 233 "default": "off",
234 "description": "Trace output of cargo-watch" 234 "description": "Trace output of cargo-watch"
235 },
236 "rust-analyzer.lruCapacity": {
237 "type": "number",
238 "default": null,
239 "description": "Number of syntax trees rust-analyzer keeps in memory"
235 } 240 }
236 } 241 }
237 }, 242 },
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 8d73a6b34..3024546d2 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -19,6 +19,7 @@ export class Config {
19 public enableEnhancedTyping = true; 19 public enableEnhancedTyping = true;
20 public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; 20 public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
21 public showWorkspaceLoadedNotification = true; 21 public showWorkspaceLoadedNotification = true;
22 public lruCapacity: null | number = null;
22 public cargoWatchOptions: CargoWatchOptions = { 23 public cargoWatchOptions: CargoWatchOptions = {
23 enableOnStartup: 'ask', 24 enableOnStartup: 'ask',
24 trace: 'off', 25 trace: 'off',
@@ -109,5 +110,8 @@ export class Config {
109 '' 110 ''
110 ); 111 );
111 } 112 }
113 if (config.has('lruCapacity')) {
114 this.lruCapacity = config.get('lruCapacity') as number;
115 }
112 } 116 }
113} 117}
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts
index 81c2b3fff..7029142fd 100644
--- a/editors/code/src/server.ts
+++ b/editors/code/src/server.ts
@@ -35,7 +35,8 @@ export class Server {
35 initializationOptions: { 35 initializationOptions: {
36 publishDecorations: true, 36 publishDecorations: true,
37 showWorkspaceLoaded: 37 showWorkspaceLoaded:
38 Server.config.showWorkspaceLoadedNotification 38 Server.config.showWorkspaceLoadedNotification,
39 lruCapacity: Server.config.lruCapacity
39 }, 40 },
40 traceOutputChannel 41 traceOutputChannel
41 }; 42 };