aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/db.rs2
-rw-r--r--crates/ra_hir_expand/src/db.rs19
-rw-r--r--crates/ra_ide_db/Cargo.toml3
-rw-r--r--crates/ra_ide_db/src/change.rs4
-rw-r--r--crates/ra_ide_db/src/line_index.rs8
-rw-r--r--crates/ra_syntax/src/lib.rs4
-rw-r--r--crates/ra_syntax/src/syntax_node.rs4
-rw-r--r--crates/rust-analyzer/src/main_loop.rs32
-rw-r--r--crates/stdx/src/lib.rs30
9 files changed, 72 insertions, 34 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 1ad92a1f8..a2b9f3e35 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -11,7 +11,7 @@ pub use hir_def::db::{
11}; 11};
12pub use hir_expand::db::{ 12pub use hir_expand::db::{
13 AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery, 13 AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
14 MacroArgQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery, 14 MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery,
15}; 15};
16pub use hir_ty::db::{ 16pub use hir_ty::db::{
17 AssociatedTyDataQuery, AssociatedTyValueQuery, CallableItemSignatureQuery, FieldTypesQuery, 17 AssociatedTyDataQuery, AssociatedTyValueQuery, CallableItemSignatureQuery, FieldTypesQuery,
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs
index bf30d7151..e0ad1567f 100644
--- a/crates/ra_hir_expand/src/db.rs
+++ b/crates/ra_hir_expand/src/db.rs
@@ -6,7 +6,7 @@ use mbe::{ExpandResult, MacroRules};
6use ra_db::{salsa, SourceDatabase}; 6use ra_db::{salsa, SourceDatabase};
7use ra_parser::FragmentKind; 7use ra_parser::FragmentKind;
8use ra_prof::profile; 8use ra_prof::profile;
9use ra_syntax::{algo::diff, AstNode, Parse, SyntaxKind::*, SyntaxNode}; 9use ra_syntax::{algo::diff, AstNode, GreenNode, Parse, SyntaxKind::*, SyntaxNode};
10 10
11use crate::{ 11use crate::{
12 ast_id_map::AstIdMap, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallLoc, EagerMacroId, 12 ast_id_map::AstIdMap, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallLoc, EagerMacroId,
@@ -72,6 +72,8 @@ pub trait AstDatabase: SourceDatabase {
72 72
73 #[salsa::interned] 73 #[salsa::interned]
74 fn intern_macro(&self, macro_call: MacroCallLoc) -> LazyMacroId; 74 fn intern_macro(&self, macro_call: MacroCallLoc) -> LazyMacroId;
75 fn macro_arg_text(&self, id: MacroCallId) -> Option<GreenNode>;
76 #[salsa::transparent]
75 fn macro_arg(&self, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>>; 77 fn macro_arg(&self, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>>;
76 fn macro_def(&self, id: MacroDefId) -> Option<Arc<(TokenExpander, mbe::TokenMap)>>; 78 fn macro_def(&self, id: MacroDefId) -> Option<Arc<(TokenExpander, mbe::TokenMap)>>;
77 fn parse_macro(&self, macro_file: MacroFile) 79 fn parse_macro(&self, macro_file: MacroFile)
@@ -148,10 +150,7 @@ pub(crate) fn macro_def(
148 } 150 }
149} 151}
150 152
151pub(crate) fn macro_arg( 153pub(crate) fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
152 db: &dyn AstDatabase,
153 id: MacroCallId,
154) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
155 let id = match id { 154 let id = match id {
156 MacroCallId::LazyMacro(id) => id, 155 MacroCallId::LazyMacro(id) => id,
157 MacroCallId::EagerMacro(_id) => { 156 MacroCallId::EagerMacro(_id) => {
@@ -161,7 +160,15 @@ pub(crate) fn macro_arg(
161 }; 160 };
162 let loc = db.lookup_intern_macro(id); 161 let loc = db.lookup_intern_macro(id);
163 let arg = loc.kind.arg(db)?; 162 let arg = loc.kind.arg(db)?;
164 let (tt, tmap) = mbe::syntax_node_to_token_tree(&arg)?; 163 Some(arg.green().clone())
164}
165
166pub(crate) fn macro_arg(
167 db: &dyn AstDatabase,
168 id: MacroCallId,
169) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
170 let arg = db.macro_arg_text(id)?;
171 let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg))?;
165 Some(Arc::new((tt, tmap))) 172 Some(Arc::new((tt, tmap)))
166} 173}
167 174
diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml
index bcddad60c..2716a38cc 100644
--- a/crates/ra_ide_db/Cargo.toml
+++ b/crates/ra_ide_db/Cargo.toml
@@ -16,10 +16,11 @@ log = "0.4.8"
16rayon = "1.3.0" 16rayon = "1.3.0"
17fst = { version = "0.4", default-features = false } 17fst = { version = "0.4", default-features = false }
18rustc-hash = "1.1.0" 18rustc-hash = "1.1.0"
19superslice = "1.0.0"
20once_cell = "1.3.1" 19once_cell = "1.3.1"
21either = "1.5.3" 20either = "1.5.3"
22 21
22stdx = { path = "../stdx" }
23
23ra_syntax = { path = "../ra_syntax" } 24ra_syntax = { path = "../ra_syntax" }
24ra_text_edit = { path = "../ra_text_edit" } 25ra_text_edit = { path = "../ra_text_edit" }
25ra_db = { path = "../ra_db" } 26ra_db = { path = "../ra_db" }
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs
index a1bb3043b..32d9a8d1f 100644
--- a/crates/ra_ide_db/src/change.rs
+++ b/crates/ra_ide_db/src/change.rs
@@ -151,7 +151,7 @@ impl RootDatabase {
151 151
152 // Macros do take significant space, but less then the syntax trees 152 // Macros do take significant space, but less then the syntax trees
153 // self.query(hir::db::MacroDefQuery).sweep(sweep); 153 // self.query(hir::db::MacroDefQuery).sweep(sweep);
154 // self.query(hir::db::MacroArgQuery).sweep(sweep); 154 // self.query(hir::db::MacroArgTextQuery).sweep(sweep);
155 // self.query(hir::db::MacroExpandQuery).sweep(sweep); 155 // self.query(hir::db::MacroExpandQuery).sweep(sweep);
156 156
157 hir::db::AstIdMapQuery.in_db(self).sweep(sweep); 157 hir::db::AstIdMapQuery.in_db(self).sweep(sweep);
@@ -199,7 +199,7 @@ impl RootDatabase {
199 199
200 // AstDatabase 200 // AstDatabase
201 hir::db::AstIdMapQuery 201 hir::db::AstIdMapQuery
202 hir::db::MacroArgQuery 202 hir::db::MacroArgTextQuery
203 hir::db::MacroDefQuery 203 hir::db::MacroDefQuery
204 hir::db::ParseMacroQuery 204 hir::db::ParseMacroQuery
205 hir::db::MacroExpandQuery 205 hir::db::MacroExpandQuery
diff --git a/crates/ra_ide_db/src/line_index.rs b/crates/ra_ide_db/src/line_index.rs
index c7c744fce..2ab662098 100644
--- a/crates/ra_ide_db/src/line_index.rs
+++ b/crates/ra_ide_db/src/line_index.rs
@@ -4,7 +4,7 @@ use std::iter;
4 4
5use ra_syntax::{TextRange, TextSize}; 5use ra_syntax::{TextRange, TextSize};
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7use superslice::Ext; 7use stdx::partition_point;
8 8
9#[derive(Clone, Debug, PartialEq, Eq)] 9#[derive(Clone, Debug, PartialEq, Eq)]
10pub struct LineIndex { 10pub struct LineIndex {
@@ -89,7 +89,7 @@ impl LineIndex {
89 } 89 }
90 90
91 pub fn line_col(&self, offset: TextSize) -> LineCol { 91 pub fn line_col(&self, offset: TextSize) -> LineCol {
92 let line = self.newlines.upper_bound(&offset) - 1; 92 let line = partition_point(&self.newlines, |&it| it <= offset) - 1;
93 let line_start_offset = self.newlines[line]; 93 let line_start_offset = self.newlines[line];
94 let col = offset - line_start_offset; 94 let col = offset - line_start_offset;
95 95
@@ -103,8 +103,8 @@ impl LineIndex {
103 } 103 }
104 104
105 pub fn lines(&self, range: TextRange) -> impl Iterator<Item = TextRange> + '_ { 105 pub fn lines(&self, range: TextRange) -> impl Iterator<Item = TextRange> + '_ {
106 let lo = self.newlines.lower_bound(&range.start()); 106 let lo = partition_point(&self.newlines, |&it| it < range.start());
107 let hi = self.newlines.upper_bound(&range.end()); 107 let hi = partition_point(&self.newlines, |&it| it <= range.end());
108 let all = iter::once(range.start()) 108 let all = iter::once(range.start())
109 .chain(self.newlines[lo..hi].iter().copied()) 109 .chain(self.newlines[lo..hi].iter().copied())
110 .chain(iter::once(range.end())); 110 .chain(iter::once(range.end()));
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 9b7664576..ac59455e7 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -42,8 +42,6 @@ use std::{marker::PhantomData, sync::Arc};
42use ra_text_edit::Indel; 42use ra_text_edit::Indel;
43use stdx::format_to; 43use stdx::format_to;
44 44
45use crate::syntax_node::GreenNode;
46
47pub use crate::{ 45pub use crate::{
48 algo::InsertPosition, 46 algo::InsertPosition,
49 ast::{AstNode, AstToken}, 47 ast::{AstNode, AstToken},
@@ -51,7 +49,7 @@ pub use crate::{
51 ptr::{AstPtr, SyntaxNodePtr}, 49 ptr::{AstPtr, SyntaxNodePtr},
52 syntax_error::SyntaxError, 50 syntax_error::SyntaxError,
53 syntax_node::{ 51 syntax_node::{
54 Direction, NodeOrToken, SyntaxElement, SyntaxElementChildren, SyntaxNode, 52 Direction, GreenNode, NodeOrToken, SyntaxElement, SyntaxElementChildren, SyntaxNode,
55 SyntaxNodeChildren, SyntaxToken, SyntaxTreeBuilder, 53 SyntaxNodeChildren, SyntaxToken, SyntaxTreeBuilder,
56 }, 54 },
57}; 55};
diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs
index 9650b8781..a7dbdba7b 100644
--- a/crates/ra_syntax/src/syntax_node.rs
+++ b/crates/ra_syntax/src/syntax_node.rs
@@ -10,7 +10,9 @@ use rowan::{GreenNodeBuilder, Language};
10 10
11use crate::{Parse, SmolStr, SyntaxError, SyntaxKind, TextSize}; 11use crate::{Parse, SmolStr, SyntaxError, SyntaxKind, TextSize};
12 12
13pub(crate) use rowan::{GreenNode, GreenToken}; 13pub use rowan::GreenNode;
14
15pub(crate) use rowan::GreenToken;
14 16
15#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 17#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
16pub enum RustLanguage {} 18pub enum RustLanguage {}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index f6d8daeed..ac95e428e 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -97,22 +97,6 @@ impl fmt::Debug for Event {
97} 97}
98 98
99impl GlobalState { 99impl GlobalState {
100 fn next_event(&self, inbox: &Receiver<lsp_server::Message>) -> Option<Event> {
101 select! {
102 recv(inbox) -> msg =>
103 msg.ok().map(Event::Lsp),
104
105 recv(self.task_pool.receiver) -> task =>
106 Some(Event::Task(task.unwrap())),
107
108 recv(self.loader.receiver) -> task =>
109 Some(Event::Vfs(task.unwrap())),
110
111 recv(self.flycheck_receiver) -> task =>
112 Some(Event::Flycheck(task.unwrap())),
113 }
114 }
115
116 fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> { 100 fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> {
117 if self.config.linked_projects.is_empty() && self.config.notifications.cargo_toml_not_found 101 if self.config.linked_projects.is_empty() && self.config.notifications.cargo_toml_not_found
118 { 102 {
@@ -169,6 +153,22 @@ impl GlobalState {
169 Err("client exited without proper shutdown sequence")? 153 Err("client exited without proper shutdown sequence")?
170 } 154 }
171 155
156 fn next_event(&self, inbox: &Receiver<lsp_server::Message>) -> Option<Event> {
157 select! {
158 recv(inbox) -> msg =>
159 msg.ok().map(Event::Lsp),
160
161 recv(self.task_pool.receiver) -> task =>
162 Some(Event::Task(task.unwrap())),
163
164 recv(self.loader.receiver) -> task =>
165 Some(Event::Vfs(task.unwrap())),
166
167 recv(self.flycheck_receiver) -> task =>
168 Some(Event::Flycheck(task.unwrap())),
169 }
170 }
171
172 fn handle_event(&mut self, event: Event) -> Result<()> { 172 fn handle_event(&mut self, event: Event) -> Result<()> {
173 let loop_start = Instant::now(); 173 let loop_start = Instant::now();
174 // NOTE: don't count blocking select! call as a loop-turn time 174 // NOTE: don't count blocking select! call as a loop-turn time
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index 988853ed2..ea0e6b949 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -158,6 +158,36 @@ impl<'a> Iterator for LinesWithEnds<'a> {
158 } 158 }
159} 159}
160 160
161// https://github.com/rust-lang/rust/issues/73831
162pub fn partition_point<T, P>(slice: &[T], mut pred: P) -> usize
163where
164 P: FnMut(&T) -> bool,
165{
166 let mut left = 0;
167 let mut right = slice.len();
168
169 while left != right {
170 let mid = left + (right - left) / 2;
171 // SAFETY:
172 // When left < right, left <= mid < right.
173 // Therefore left always increases and right always decreases,
174 // and either of them is selected.
175 // In both cases left <= right is satisfied.
176 // Therefore if left < right in a step,
177 // left <= right is satisfied in the next step.
178 // Therefore as long as left != right, 0 <= left < right <= len is satisfied
179 // and if this case 0 <= mid < len is satisfied too.
180 let value = unsafe { slice.get_unchecked(mid) };
181 if pred(value) {
182 left = mid + 1;
183 } else {
184 right = mid;
185 }
186 }
187
188 left
189}
190
161#[cfg(test)] 191#[cfg(test)]
162mod tests { 192mod tests {
163 use super::*; 193 use super::*;