aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/nameres.rs1
-rw-r--r--crates/ra_hir/src/nameres/collector.rs1
-rw-r--r--crates/ra_hir/src/ty/traits.rs1
-rw-r--r--crates/ra_ide_api/src/db.rs5
-rw-r--r--crates/ra_ide_api/src/snapshots/highlighting.html8
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs89
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs2
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs2
8 files changed, 65 insertions, 44 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 9b9212bfc..42dcac332 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -222,6 +222,7 @@ fn or(left: ItemOrMacro, right: ItemOrMacro) -> ItemOrMacro {
222 222
223impl CrateDefMap { 223impl CrateDefMap {
224 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: Crate) -> Arc<CrateDefMap> { 224 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: Crate) -> Arc<CrateDefMap> {
225 db.check_canceled();
225 let _p = profile("crate_def_map_query"); 226 let _p = profile("crate_def_map_query");
226 let def_map = { 227 let def_map = {
227 let edition = krate.edition(db); 228 let edition = krate.edition(db);
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index ba7ea0017..af8ac064c 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -112,6 +112,7 @@ where
112 // main name resolution fixed-point loop. 112 // main name resolution fixed-point loop.
113 let mut i = 0; 113 let mut i = 0;
114 loop { 114 loop {
115 self.db.check_canceled();
115 match (self.resolve_imports(), self.resolve_macros()) { 116 match (self.resolve_imports(), self.resolve_macros()) {
116 (ReachedFixedPoint::Yes, ReachedFixedPoint::Yes) => break, 117 (ReachedFixedPoint::Yes, ReachedFixedPoint::Yes) => break,
117 _ => i += 1, 118 _ => i += 1,
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs
index e6c78c0d4..fc90f56d5 100644
--- a/crates/ra_hir/src/ty/traits.rs
+++ b/crates/ra_hir/src/ty/traits.rs
@@ -82,6 +82,7 @@ pub(crate) fn implements_query(
82 krate: Crate, 82 krate: Crate,
83 trait_ref: Canonical<TraitRef>, 83 trait_ref: Canonical<TraitRef>,
84) -> Option<Solution> { 84) -> Option<Solution> {
85 db.check_canceled();
85 let _p = profile("implements_query"); 86 let _p = profile("implements_query");
86 let goal: chalk_ir::Goal = trait_ref.value.to_chalk(db).cast(); 87 let goal: chalk_ir::Goal = trait_ref.value.to_chalk(db).cast();
87 debug!("goal: {:?}", goal); 88 debug!("goal: {:?}", goal);
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index 33d3903bb..d84a0e7be 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -31,6 +31,11 @@ impl salsa::Database for RootDatabase {
31 fn on_propagated_panic(&self) -> ! { 31 fn on_propagated_panic(&self) -> ! {
32 Canceled::throw() 32 Canceled::throw()
33 } 33 }
34 fn salsa_event(&self, event: impl Fn() -> salsa::Event<RootDatabase>) {
35 if let salsa::EventKind::DidValidateMemoizedValue { .. } = event().kind {
36 self.check_canceled();
37 }
38 }
34} 39}
35 40
36impl Default for RootDatabase { 41impl Default for RootDatabase {
diff --git a/crates/ra_ide_api/src/snapshots/highlighting.html b/crates/ra_ide_api/src/snapshots/highlighting.html
index 2a32b3241..d79d35bf3 100644
--- a/crates/ra_ide_api/src/snapshots/highlighting.html
+++ b/crates/ra_ide_api/src/snapshots/highlighting.html
@@ -19,13 +19,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4e
19</style> 19</style>
20<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span> 20<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
21<span class="keyword">struct</span> <span class="type">Foo</span> { 21<span class="keyword">struct</span> <span class="type">Foo</span> {
22 <span class="keyword">pub</span> <span class="function">x</span>: <span class="text">i32</span>, 22 <span class="keyword">pub</span> <span class="function">x</span>: <span class="type">i32</span>,
23 <span class="keyword">pub</span> <span class="function">y</span>: <span class="text">i32</span>, 23 <span class="keyword">pub</span> <span class="function">y</span>: <span class="type">i32</span>,
24} 24}
25 25
26<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type type">T</span>&gt;() -&gt; <span class="type">T</span> { 26<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type">T</span>&gt;() -&gt; <span class="type">T</span> {
27 <span class="macro">unimplemented</span><span class="macro">!</span>(); 27 <span class="macro">unimplemented</span><span class="macro">!</span>();
28 <span class="function">foo</span>::&lt;<span class="type text">i32</span>&gt;(); 28 <span class="function">foo</span>::&lt;<span class="type">i32</span>&gt;();
29} 29}
30 30
31<span class="comment">// comment</span> 31<span class="comment">// comment</span>
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index bf4e9c9d1..4b24754a8 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -30,6 +30,14 @@ fn is_control_keyword(kind: SyntaxKind) -> bool {
30 } 30 }
31} 31}
32 32
33fn is_prim_type(node: &ast::NameRef) -> bool {
34 match node.text().as_str() {
35 "u8" | "i8" | "u16" | "i16" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "usize"
36 | "isize" | "f32" | "f64" | "bool" | "char" | "str" => true,
37 _ => false,
38 }
39}
40
33pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { 41pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
34 let _p = profile("highlight"); 42 let _p = profile("highlight");
35 let source_file = db.parse(file_id).tree; 43 let source_file = db.parse(file_id).tree;
@@ -62,46 +70,52 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
62 ATTR => "attribute", 70 ATTR => "attribute",
63 NAME_REF => { 71 NAME_REF => {
64 if let Some(name_ref) = node.as_node().and_then(ast::NameRef::cast) { 72 if let Some(name_ref) = node.as_node().and_then(ast::NameRef::cast) {
65 use crate::name_ref_kind::{classify_name_ref, NameRefKind::*}; 73 // FIXME: revisit this after #1340
66 use hir::{ModuleDef, ImplItem}; 74 if is_prim_type(name_ref) {
75 "type"
76 } else {
77 use crate::name_ref_kind::{classify_name_ref, NameRefKind::*};
78 use hir::{ModuleDef, ImplItem};
67 79
68 // FIXME: try to reuse the SourceAnalyzers 80 // FIXME: try to reuse the SourceAnalyzers
69 let analyzer = hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None); 81 let analyzer =
70 match classify_name_ref(db, &analyzer, name_ref) { 82 hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None);
71 Some(Method(_)) => "function", 83 match classify_name_ref(db, &analyzer, name_ref) {
72 Some(Macro(_)) => "macro", 84 Some(Method(_)) => "function",
73 Some(FieldAccess(_)) => "field", 85 Some(Macro(_)) => "macro",
74 Some(AssocItem(ImplItem::Method(_))) => "function", 86 Some(FieldAccess(_)) => "field",
75 Some(AssocItem(ImplItem::Const(_))) => "constant", 87 Some(AssocItem(ImplItem::Method(_))) => "function",
76 Some(AssocItem(ImplItem::TypeAlias(_))) => "type", 88 Some(AssocItem(ImplItem::Const(_))) => "constant",
77 Some(Def(ModuleDef::Module(_))) => "module", 89 Some(AssocItem(ImplItem::TypeAlias(_))) => "type",
78 Some(Def(ModuleDef::Function(_))) => "function", 90 Some(Def(ModuleDef::Module(_))) => "module",
79 Some(Def(ModuleDef::Struct(_))) => "type", 91 Some(Def(ModuleDef::Function(_))) => "function",
80 Some(Def(ModuleDef::Union(_))) => "type", 92 Some(Def(ModuleDef::Struct(_))) => "type",
81 Some(Def(ModuleDef::Enum(_))) => "type", 93 Some(Def(ModuleDef::Union(_))) => "type",
82 Some(Def(ModuleDef::EnumVariant(_))) => "constant", 94 Some(Def(ModuleDef::Enum(_))) => "type",
83 Some(Def(ModuleDef::Const(_))) => "constant", 95 Some(Def(ModuleDef::EnumVariant(_))) => "constant",
84 Some(Def(ModuleDef::Static(_))) => "constant", 96 Some(Def(ModuleDef::Const(_))) => "constant",
85 Some(Def(ModuleDef::Trait(_))) => "type", 97 Some(Def(ModuleDef::Static(_))) => "constant",
86 Some(Def(ModuleDef::TypeAlias(_))) => "type", 98 Some(Def(ModuleDef::Trait(_))) => "type",
87 Some(SelfType(_)) => "type", 99 Some(Def(ModuleDef::TypeAlias(_))) => "type",
88 Some(Pat(ptr)) => { 100 Some(SelfType(_)) => "type",
89 binding_hash = Some({ 101 Some(Pat(ptr)) => {
90 let text = ptr 102 binding_hash = Some({
91 .syntax_node_ptr() 103 let text = ptr
92 .to_node(&source_file.syntax()) 104 .syntax_node_ptr()
93 .text() 105 .to_node(&source_file.syntax())
94 .to_smol_string(); 106 .text()
95 let shadow_count = 107 .to_smol_string();
96 bindings_shadow_count.entry(text.clone()).or_default(); 108 let shadow_count =
97 calc_binding_hash(file_id, &text, *shadow_count) 109 bindings_shadow_count.entry(text.clone()).or_default();
98 }); 110 calc_binding_hash(file_id, &text, *shadow_count)
111 });
99 112
100 "variable" 113 "variable"
114 }
115 Some(SelfParam(_)) => "type",
116 Some(GenericParam(_)) => "type",
117 None => "text",
101 } 118 }
102 Some(SelfParam(_)) => "type",
103 Some(GenericParam(_)) => "type",
104 None => "text",
105 } 119 }
106 } else { 120 } else {
107 "text" 121 "text"
@@ -138,7 +152,6 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
138 "text" 152 "text"
139 } 153 }
140 } 154 }
141 TYPE_ALIAS_DEF | TYPE_ARG | TYPE_PARAM => "type",
142 INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", 155 INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal",
143 LIFETIME => "parameter", 156 LIFETIME => "parameter",
144 T![unsafe] => "keyword.unsafe", 157 T![unsafe] => "keyword.unsafe",
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index dc817f2d9..0ebfd641d 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -34,7 +34,7 @@ pub fn handle_analyzer_status(world: ServerWorld, _: ()) -> Result<String> {
34 let requests = world.latest_completed_requests.read(); 34 let requests = world.latest_completed_requests.read();
35 for (idx, r) in requests.iter().enumerate() { 35 for (idx, r) in requests.iter().enumerate() {
36 let current = if idx == world.request_idx { "*" } else { " " }; 36 let current = if idx == world.request_idx { "*" } else { " " };
37 writeln!(buf, "{:4}{}{:<36}: {:?}", r.id, current, r.method, r.duration).unwrap(); 37 writeln!(buf, "{:4}{}{:<36}{}ms", r.id, current, r.method, r.duration.as_millis()).unwrap();
38 } 38 }
39 Ok(buf) 39 Ok(buf)
40} 40}
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index 729067395..f952a03a3 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -227,7 +227,7 @@ impl Drop for Server {
227} 227}
228 228
229fn recv_timeout(receiver: &Receiver<RawMessage>) -> Option<RawMessage> { 229fn recv_timeout(receiver: &Receiver<RawMessage>) -> Option<RawMessage> {
230 let timeout = Duration::from_secs(50); 230 let timeout = Duration::from_secs(120);
231 select! { 231 select! {
232 recv(receiver) -> msg => msg.ok(), 232 recv(receiver) -> msg => msg.ok(),
233 recv(after(timeout)) -> _ => panic!("timed out"), 233 recv(after(timeout)) -> _ => panic!("timed out"),