aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock8
-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
-rw-r--r--editors/code/package.json12
-rw-r--r--editors/code/src/client.ts1
-rw-r--r--editors/code/src/snippets.ts4
-rw-r--r--xtask/tests/tidy.rs1
14 files changed, 87 insertions, 45 deletions
diff --git a/Cargo.lock b/Cargo.lock
index af7062815..029698808 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1077,7 +1077,7 @@ dependencies = [
1077 "ra_text_edit", 1077 "ra_text_edit",
1078 "rayon", 1078 "rayon",
1079 "rustc-hash", 1079 "rustc-hash",
1080 "superslice", 1080 "stdx",
1081 "test_utils", 1081 "test_utils",
1082] 1082]
1083 1083
@@ -1584,12 +1584,6 @@ name = "stdx"
1584version = "0.1.0" 1584version = "0.1.0"
1585 1585
1586[[package]] 1586[[package]]
1587name = "superslice"
1588version = "1.0.0"
1589source = "registry+https://github.com/rust-lang/crates.io-index"
1590checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f"
1591
1592[[package]]
1593name = "syn" 1587name = "syn"
1594version = "1.0.35" 1588version = "1.0.35"
1595source = "registry+https://github.com/rust-lang/crates.io-index" 1589source = "registry+https://github.com/rust-lang/crates.io-index"
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::*;
diff --git a/editors/code/package.json b/editors/code/package.json
index aac4ba94f..448e2269f 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -655,24 +655,30 @@
655 "problemMatchers": [ 655 "problemMatchers": [
656 { 656 {
657 "name": "rustc", 657 "name": "rustc",
658 "owner": "rustc",
659 "source": "rustc",
658 "fileLocation": [ 660 "fileLocation": [
659 "relative", 661 "autoDetect",
660 "${workspaceRoot}" 662 "${workspaceRoot}"
661 ], 663 ],
662 "pattern": "$rustc" 664 "pattern": "$rustc"
663 }, 665 },
664 { 666 {
665 "name": "rustc-json", 667 "name": "rustc-json",
668 "owner": "rustc",
669 "source": "rustc",
666 "fileLocation": [ 670 "fileLocation": [
667 "relative", 671 "autoDetect",
668 "${workspaceRoot}" 672 "${workspaceRoot}"
669 ], 673 ],
670 "pattern": "$rustc-json" 674 "pattern": "$rustc-json"
671 }, 675 },
672 { 676 {
673 "name": "rustc-watch", 677 "name": "rustc-watch",
678 "owner": "rustc",
679 "source": "rustc",
674 "fileLocation": [ 680 "fileLocation": [
675 "relative", 681 "autoDetect",
676 "${workspaceRoot}" 682 "${workspaceRoot}"
677 ], 683 ],
678 "background": { 684 "background": {
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 41ffac7b3..18948cb3c 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -41,6 +41,7 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient
41 const clientOptions: lc.LanguageClientOptions = { 41 const clientOptions: lc.LanguageClientOptions = {
42 documentSelector: [{ scheme: 'file', language: 'rust' }], 42 documentSelector: [{ scheme: 'file', language: 'rust' }],
43 initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"), 43 initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
44 diagnosticCollectionName: "rustc",
44 traceOutputChannel, 45 traceOutputChannel,
45 middleware: { 46 middleware: {
46 // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576 47 // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
diff --git a/editors/code/src/snippets.ts b/editors/code/src/snippets.ts
index bcb3f2cc7..258b49982 100644
--- a/editors/code/src/snippets.ts
+++ b/editors/code/src/snippets.ts
@@ -6,6 +6,10 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
6 assert(edit.entries().length === 1, `bad ws edit: ${JSON.stringify(edit)}`); 6 assert(edit.entries().length === 1, `bad ws edit: ${JSON.stringify(edit)}`);
7 const [uri, edits] = edit.entries()[0]; 7 const [uri, edits] = edit.entries()[0];
8 8
9 if (vscode.window.activeTextEditor?.document.uri !== uri) {
10 // `vscode.window.visibleTextEditors` only contains editors whose contents are being displayed
11 await vscode.window.showTextDocument(uri, {});
12 }
9 const editor = vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString()); 13 const editor = vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString());
10 if (!editor) return; 14 if (!editor) return;
11 await applySnippetTextEdits(editor, edits); 15 await applySnippetTextEdits(editor, edits);
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs
index ca14e8ac1..adadffc53 100644
--- a/xtask/tests/tidy.rs
+++ b/xtask/tests/tidy.rs
@@ -53,7 +53,6 @@ fn rust_files_are_tidy() {
53fn check_licenses() { 53fn check_licenses() {
54 let expected = " 54 let expected = "
550BSD OR MIT OR Apache-2.0 550BSD OR MIT OR Apache-2.0
56Apache-2.0
57Apache-2.0 OR BSL-1.0 56Apache-2.0 OR BSL-1.0
58Apache-2.0 OR MIT 57Apache-2.0 OR MIT
59Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT 58Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT