aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/lib.rs20
-rw-r--r--crates/ra_hir/src/module.rs2
-rw-r--r--crates/ra_hir/src/module/nameres.rs4
-rw-r--r--crates/ra_hir/src/query_definitions.rs2
-rw-r--r--crates/ra_hir/src/source_binder.rs2
-rw-r--r--crates/ra_lsp_server/Cargo.toml1
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs15
7 files changed, 30 insertions, 16 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 983ce99cb..f50b922af 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -110,16 +110,32 @@ pub struct SourceItemId {
110} 110}
111 111
112/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back. 112/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back.
113#[derive(Debug, PartialEq, Eq, Default)] 113#[derive(Debug, PartialEq, Eq)]
114pub struct SourceFileItems { 114pub struct SourceFileItems {
115 file_id: FileId,
115 arena: Arena<SyntaxNode>, 116 arena: Arena<SyntaxNode>,
116} 117}
117 118
118impl SourceFileItems { 119impl SourceFileItems {
120 fn new(file_id: FileId) -> SourceFileItems {
121 SourceFileItems {
122 file_id,
123 arena: Arena::default(),
124 }
125 }
126
119 fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId { 127 fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId {
120 self.arena.alloc(item) 128 self.arena.alloc(item)
121 } 129 }
122 pub fn id_of(&self, item: SyntaxNodeRef) -> SourceFileItemId { 130 pub fn id_of(&self, file_id: FileId, item: SyntaxNodeRef) -> SourceFileItemId {
131 assert_eq!(
132 self.file_id, file_id,
133 "SourceFileItems: wrong file, expected {:?}, got {:?}",
134 self.file_id, file_id
135 );
136 self.id_of_unchecked(item)
137 }
138 fn id_of_unchecked(&self, item: SyntaxNodeRef) -> SourceFileItemId {
123 let (id, _item) = self 139 let (id, _item) = self
124 .arena 140 .arena
125 .iter() 141 .iter()
diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs
index 580c737c3..e7a49f83a 100644
--- a/crates/ra_hir/src/module.rs
+++ b/crates/ra_hir/src/module.rs
@@ -280,7 +280,7 @@ impl ModuleSource {
280 ) -> ModuleSource { 280 ) -> ModuleSource {
281 assert!(!m.has_semi()); 281 assert!(!m.has_semi());
282 let file_items = db.file_items(file_id); 282 let file_items = db.file_items(file_id);
283 let item_id = file_items.id_of(m.syntax()); 283 let item_id = file_items.id_of(file_id, m.syntax());
284 ModuleSource::new(file_id, item_id) 284 ModuleSource::new(file_id, item_id)
285 } 285 }
286 286
diff --git a/crates/ra_hir/src/module/nameres.rs b/crates/ra_hir/src/module/nameres.rs
index 61a1acfe6..6511359d0 100644
--- a/crates/ra_hir/src/module/nameres.rs
+++ b/crates/ra_hir/src/module/nameres.rs
@@ -168,7 +168,7 @@ impl InputModuleItems {
168 } 168 }
169 169
170 fn add_use_item(&mut self, file_items: &SourceFileItems, item: ast::UseItem) { 170 fn add_use_item(&mut self, file_items: &SourceFileItems, item: ast::UseItem) {
171 let file_item_id = file_items.id_of(item.syntax()); 171 let file_item_id = file_items.id_of_unchecked(item.syntax());
172 let start_offset = item.syntax().range().start(); 172 let start_offset = item.syntax().range().start();
173 Path::expand_use_item(item, |path, range| { 173 Path::expand_use_item(item, |path, range| {
174 let kind = match range { 174 let kind = match range {
@@ -188,7 +188,7 @@ impl ModuleItem {
188 let name = item.name()?.text(); 188 let name = item.name()?.text();
189 let kind = item.syntax().kind(); 189 let kind = item.syntax().kind();
190 let vis = Vis::Other; 190 let vis = Vis::Other;
191 let id = file_items.id_of(item.syntax()); 191 let id = file_items.id_of_unchecked(item.syntax());
192 let res = ModuleItem { 192 let res = ModuleItem {
193 id, 193 id,
194 name, 194 name,
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index e4d721601..bb4457d07 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -36,7 +36,7 @@ pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc<FnScopes> {
36} 36}
37 37
38pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> { 38pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> {
39 let mut res = SourceFileItems::default(); 39 let mut res = SourceFileItems::new(file_id);
40 let source_file = db.source_file(file_id); 40 let source_file = db.source_file(file_id);
41 res.alloc(source_file.syntax().owned()); 41 res.alloc(source_file.syntax().owned());
42 let source_file = source_file.borrowed(); 42 let source_file = source_file.borrowed();
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 479155805..0c16ccc24 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -75,7 +75,7 @@ pub fn function_from_source(
75) -> Cancelable<Option<Function>> { 75) -> Cancelable<Option<Function>> {
76 let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?); 76 let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?);
77 let file_items = db.file_items(file_id); 77 let file_items = db.file_items(file_id);
78 let item_id = file_items.id_of(fn_def.syntax()); 78 let item_id = file_items.id_of(file_id, fn_def.syntax());
79 let source_item_id = SourceItemId { file_id, item_id }; 79 let source_item_id = SourceItemId { file_id, item_id };
80 let def_loc = DefLoc { 80 let def_loc = DefLoc {
81 kind: DefKind::Function, 81 kind: DefKind::Function,
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index 79d86f9b2..5ee218b6b 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -6,6 +6,7 @@ authors = ["Aleksey Kladov <[email protected]>"]
6 6
7[dependencies] 7[dependencies]
8rayon = "1.0.2" 8rayon = "1.0.2"
9threadpool = "1.7.1"
9relative-path = "0.4.0" 10relative-path = "0.4.0"
10failure = "0.1.2" 11failure = "0.1.2"
11failure_derive = "0.1.2" 12failure_derive = "0.1.2"
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 0e1878906..a01eeff88 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -9,7 +9,8 @@ use gen_lsp_server::{
9}; 9};
10use languageserver_types::NumberOrString; 10use languageserver_types::NumberOrString;
11use ra_analysis::{Canceled, FileId, LibraryData}; 11use ra_analysis::{Canceled, FileId, LibraryData};
12use rayon::{self, ThreadPool}; 12use rayon;
13use threadpool::ThreadPool;
13use rustc_hash::FxHashSet; 14use rustc_hash::FxHashSet;
14use serde::{de::DeserializeOwned, Serialize}; 15use serde::{de::DeserializeOwned, Serialize};
15use failure::{format_err, bail}; 16use failure::{format_err, bail};
@@ -54,11 +55,7 @@ pub fn main_loop(
54 msg_receiver: &Receiver<RawMessage>, 55 msg_receiver: &Receiver<RawMessage>,
55 msg_sender: &Sender<RawMessage>, 56 msg_sender: &Sender<RawMessage>,
56) -> Result<()> { 57) -> Result<()> {
57 let pool = rayon::ThreadPoolBuilder::new() 58 let pool = ThreadPool::new(8);
58 .num_threads(4)
59 .panic_handler(|_| log::error!("thread panicked :("))
60 .build()
61 .unwrap();
62 let (task_sender, task_receiver) = unbounded::<Task>(); 59 let (task_sender, task_receiver) = unbounded::<Task>();
63 let (fs_worker, fs_watcher) = vfs::roots_loader(); 60 let (fs_worker, fs_watcher) = vfs::roots_loader();
64 let (ws_worker, ws_watcher) = workspace_loader(); 61 let (ws_worker, ws_watcher) = workspace_loader();
@@ -155,7 +152,7 @@ fn main_loop_inner(
155 } else { 152 } else {
156 let (files, resolver) = state.events_to_files(events); 153 let (files, resolver) = state.events_to_files(events);
157 let sender = libdata_sender.clone(); 154 let sender = libdata_sender.clone();
158 pool.spawn(move || { 155 pool.execute(move || {
159 let start = ::std::time::Instant::now(); 156 let start = ::std::time::Instant::now();
160 log::info!("indexing {} ... ", root.display()); 157 log::info!("indexing {} ... ", root.display());
161 let data = LibraryData::prepare(files, resolver); 158 let data = LibraryData::prepare(files, resolver);
@@ -402,7 +399,7 @@ impl<'a> PoolDispatcher<'a> {
402 Ok((id, params)) => { 399 Ok((id, params)) => {
403 let world = self.world.snapshot(); 400 let world = self.world.snapshot();
404 let sender = self.sender.clone(); 401 let sender = self.sender.clone();
405 self.pool.spawn(move || { 402 self.pool.execute(move || {
406 let resp = match f(world, params) { 403 let resp = match f(world, params) {
407 Ok(resp) => RawResponse::ok::<R>(id, &resp), 404 Ok(resp) => RawResponse::ok::<R>(id, &resp),
408 Err(e) => match e.downcast::<LspError>() { 405 Err(e) => match e.downcast::<LspError>() {
@@ -452,7 +449,7 @@ fn update_file_notifications_on_threadpool(
452 sender: Sender<Task>, 449 sender: Sender<Task>,
453 subscriptions: Vec<FileId>, 450 subscriptions: Vec<FileId>,
454) { 451) {
455 pool.spawn(move || { 452 pool.execute(move || {
456 for file_id in subscriptions { 453 for file_id in subscriptions {
457 match handlers::publish_diagnostics(&world, file_id) { 454 match handlers::publish_diagnostics(&world, file_id) {
458 Err(e) => { 455 Err(e) => {