diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 3 | ||||
-rw-r--r-- | crates/rust-analyzer/src/caps.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 10 |
6 files changed, 23 insertions, 30 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index d0912ddaa..2bc34d449 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -118,11 +118,12 @@ fn lower_enum( | |||
118 | module_id: ModuleId, | 118 | module_id: ModuleId, |
119 | ) { | 119 | ) { |
120 | let expander = CfgExpander::new(db, ast.file_id, module_id.krate); | 120 | let expander = CfgExpander::new(db, ast.file_id, module_id.krate); |
121 | let variants = | 121 | let variants = ast |
122 | ast.value.variant_list().into_iter().flat_map(|it| it.variants()).filter(|var| { | 122 | .value |
123 | let attrs = expander.parse_attrs(var); | 123 | .variant_list() |
124 | expander.is_cfg_enabled(&attrs) | 124 | .into_iter() |
125 | }); | 125 | .flat_map(|it| it.variants()) |
126 | .filter(|var| expander.is_cfg_enabled(var)); | ||
126 | for var in variants { | 127 | for var in variants { |
127 | trace.alloc( | 128 | trace.alloc( |
128 | || var.clone(), | 129 | || var.clone(), |
@@ -215,8 +216,7 @@ fn lower_struct( | |||
215 | match &ast.value { | 216 | match &ast.value { |
216 | ast::StructKind::Tuple(fl) => { | 217 | ast::StructKind::Tuple(fl) => { |
217 | for (i, fd) in fl.fields().enumerate() { | 218 | for (i, fd) in fl.fields().enumerate() { |
218 | let attrs = expander.parse_attrs(&fd); | 219 | if !expander.is_cfg_enabled(&fd) { |
219 | if !expander.is_cfg_enabled(&attrs) { | ||
220 | continue; | 220 | continue; |
221 | } | 221 | } |
222 | 222 | ||
@@ -233,8 +233,7 @@ fn lower_struct( | |||
233 | } | 233 | } |
234 | ast::StructKind::Record(fl) => { | 234 | ast::StructKind::Record(fl) => { |
235 | for fd in fl.fields() { | 235 | for fd in fl.fields() { |
236 | let attrs = expander.parse_attrs(&fd); | 236 | if !expander.is_cfg_enabled(&fd) { |
237 | if !expander.is_cfg_enabled(&attrs) { | ||
238 | continue; | 237 | continue; |
239 | } | 238 | } |
240 | 239 | ||
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 4edaad960..f5a7305dc 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -60,7 +60,8 @@ impl CfgExpander { | |||
60 | Attrs::new(owner, &self.hygiene) | 60 | Attrs::new(owner, &self.hygiene) |
61 | } | 61 | } |
62 | 62 | ||
63 | pub(crate) fn is_cfg_enabled(&self, attrs: &Attrs) -> bool { | 63 | pub(crate) fn is_cfg_enabled(&self, owner: &dyn ast::AttrsOwner) -> bool { |
64 | let attrs = self.parse_attrs(owner); | ||
64 | attrs.is_cfg_enabled(&self.cfg_options) | 65 | attrs.is_cfg_enabled(&self.cfg_options) |
65 | } | 66 | } |
66 | } | 67 | } |
@@ -141,12 +142,8 @@ impl Expander { | |||
141 | InFile { file_id: self.current_file_id, value } | 142 | InFile { file_id: self.current_file_id, value } |
142 | } | 143 | } |
143 | 144 | ||
144 | pub(crate) fn parse_attrs(&self, owner: &dyn ast::AttrsOwner) -> Attrs { | 145 | pub(crate) fn is_cfg_enabled(&self, owner: &dyn ast::AttrsOwner) -> bool { |
145 | self.cfg_expander.parse_attrs(owner) | 146 | self.cfg_expander.is_cfg_enabled(owner) |
146 | } | ||
147 | |||
148 | pub(crate) fn is_cfg_enabled(&self, attrs: &Attrs) -> bool { | ||
149 | self.cfg_expander.is_cfg_enabled(attrs) | ||
150 | } | 147 | } |
151 | 148 | ||
152 | fn parse_path(&mut self, path: ast::Path) -> Option<Path> { | 149 | fn parse_path(&mut self, path: ast::Path) -> Option<Path> { |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 687216dc3..8f5fa1b55 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -162,8 +162,7 @@ impl ExprCollector<'_> { | |||
162 | 162 | ||
163 | fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { | 163 | fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { |
164 | let syntax_ptr = AstPtr::new(&expr); | 164 | let syntax_ptr = AstPtr::new(&expr); |
165 | let attrs = self.expander.parse_attrs(&expr); | 165 | if !self.expander.is_cfg_enabled(&expr) { |
166 | if !self.expander.is_cfg_enabled(&attrs) { | ||
167 | return self.missing_expr(); | 166 | return self.missing_expr(); |
168 | } | 167 | } |
169 | match expr { | 168 | match expr { |
@@ -329,8 +328,7 @@ impl ExprCollector<'_> { | |||
329 | .fields() | 328 | .fields() |
330 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) | 329 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) |
331 | .filter_map(|field| { | 330 | .filter_map(|field| { |
332 | let attrs = self.expander.parse_attrs(&field); | 331 | if !self.expander.is_cfg_enabled(&field) { |
333 | if !self.expander.is_cfg_enabled(&attrs) { | ||
334 | return None; | 332 | return None; |
335 | } | 333 | } |
336 | let name = field.field_name()?.as_name(); | 334 | let name = field.field_name()?.as_name(); |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index d4cba4d05..2dbae04d3 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -335,8 +335,7 @@ fn collect_items( | |||
335 | .filter_map(|item_node| match item_node { | 335 | .filter_map(|item_node| match item_node { |
336 | ast::ImplItem::FnDef(it) => { | 336 | ast::ImplItem::FnDef(it) => { |
337 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); | 337 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); |
338 | let attrs = expander.parse_attrs(&it); | 338 | if !expander.is_cfg_enabled(&it) { |
339 | if !expander.is_cfg_enabled(&attrs) { | ||
340 | return None; | 339 | return None; |
341 | } | 340 | } |
342 | let def = FunctionLoc { container, ast_id: AstId::new(file_id, items.ast_id(&it)) } | 341 | let def = FunctionLoc { container, ast_id: AstId::new(file_id, items.ast_id(&it)) } |
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs index 680415cac..110c9a442 100644 --- a/crates/rust-analyzer/src/caps.rs +++ b/crates/rust-analyzer/src/caps.rs | |||
@@ -17,10 +17,10 @@ pub fn server_capabilities() -> ServerCapabilities { | |||
17 | ServerCapabilities { | 17 | ServerCapabilities { |
18 | text_document_sync: Some(TextDocumentSyncCapability::Options(TextDocumentSyncOptions { | 18 | text_document_sync: Some(TextDocumentSyncCapability::Options(TextDocumentSyncOptions { |
19 | open_close: Some(true), | 19 | open_close: Some(true), |
20 | change: Some(if env::var("RA_PROFILE").is_ok() { | 20 | change: Some(if env::var("RA_NO_INCREMENTAL_SYNC").is_ok() { |
21 | TextDocumentSyncKind::Incremental | ||
22 | } else { | ||
23 | TextDocumentSyncKind::Full | 21 | TextDocumentSyncKind::Full |
22 | } else { | ||
23 | TextDocumentSyncKind::Incremental | ||
24 | }), | 24 | }), |
25 | will_save: None, | 25 | will_save: None, |
26 | will_save_wait_until: None, | 26 | will_save_wait_until: None, |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 401fae755..b163ea848 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -676,13 +676,13 @@ fn apply_document_changes( | |||
676 | // remember the last valid line in the index and only rebuild it if needed. | 676 | // remember the last valid line in the index and only rebuild it if needed. |
677 | enum IndexValid { | 677 | enum IndexValid { |
678 | All, | 678 | All, |
679 | UpToLine(u64), | 679 | UpToLineExclusive(u64), |
680 | } | 680 | } |
681 | 681 | ||
682 | impl IndexValid { | 682 | impl IndexValid { |
683 | fn covers(&self, line: u64) -> bool { | 683 | fn covers(&self, line: u64) -> bool { |
684 | match *self { | 684 | match *self { |
685 | IndexValid::UpToLine(to) => to >= line, | 685 | IndexValid::UpToLineExclusive(to) => to > line, |
686 | _ => true, | 686 | _ => true, |
687 | } | 687 | } |
688 | } | 688 | } |
@@ -692,10 +692,10 @@ fn apply_document_changes( | |||
692 | for change in content_changes { | 692 | for change in content_changes { |
693 | match change.range { | 693 | match change.range { |
694 | Some(range) => { | 694 | Some(range) => { |
695 | if !index_valid.covers(range.start.line) { | 695 | if !index_valid.covers(range.end.line) { |
696 | line_index = Cow::Owned(LineIndex::new(&old_text)); | 696 | line_index = Cow::Owned(LineIndex::new(&old_text)); |
697 | } | 697 | } |
698 | index_valid = IndexValid::UpToLine(range.start.line); | 698 | index_valid = IndexValid::UpToLineExclusive(range.start.line); |
699 | let range = range.conv_with(&line_index); | 699 | let range = range.conv_with(&line_index); |
700 | let mut text = old_text.to_owned(); | 700 | let mut text = old_text.to_owned(); |
701 | match std::panic::catch_unwind(move || { | 701 | match std::panic::catch_unwind(move || { |
@@ -713,7 +713,7 @@ fn apply_document_changes( | |||
713 | } | 713 | } |
714 | None => { | 714 | None => { |
715 | *old_text = change.text; | 715 | *old_text = change.text; |
716 | index_valid = IndexValid::UpToLine(0); | 716 | index_valid = IndexValid::UpToLineExclusive(0); |
717 | } | 717 | } |
718 | } | 718 | } |
719 | } | 719 | } |