diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-02 18:21:42 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-02 18:21:42 +0100 |
commit | 6aa8d8b99da1641f1cbec6c767187dfdb7cee0dc (patch) | |
tree | 9da875edcdfe6e405073b4073e277e7928bcd36a /crates/ra_hir/src/ids.rs | |
parent | ae8fd982c05c4d825952c78d1b1d8a5cfba94e66 (diff) | |
parent | 8b7f58976b32ccc768e35151b77aa9ea004b7495 (diff) |
Merge #1369
1369: don't cache parses twice r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 79e32e579..a95561812 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -62,32 +62,35 @@ impl HirFileId { | |||
62 | file_id: HirFileId, | 62 | file_id: HirFileId, |
63 | ) -> Option<TreeArc<SyntaxNode>> { | 63 | ) -> Option<TreeArc<SyntaxNode>> { |
64 | db.check_canceled(); | 64 | db.check_canceled(); |
65 | let _p = profile("parse_or_expand_query"); | ||
66 | match file_id.0 { | 65 | match file_id.0 { |
67 | HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree.syntax().to_owned()), | 66 | HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree.syntax().to_owned()), |
68 | HirFileIdRepr::Macro(macro_file) => { | 67 | HirFileIdRepr::Macro(macro_file) => db.parse_macro(macro_file), |
69 | let macro_call_id = macro_file.macro_call_id; | 68 | } |
70 | let tt = db | 69 | } |
71 | .macro_expand(macro_call_id) | 70 | |
72 | .map_err(|err| { | 71 | pub(crate) fn parse_macro_query( |
73 | // Note: | 72 | db: &impl AstDatabase, |
74 | // The final goal we would like to make all parse_macro success, | 73 | macro_file: MacroFile, |
75 | // such that the following log will not call anyway. | 74 | ) -> Option<TreeArc<SyntaxNode>> { |
76 | log::warn!( | 75 | let _p = profile("parse_macro_query"); |
77 | "fail on macro_parse: (reason: {}) {}", | 76 | let macro_call_id = macro_file.macro_call_id; |
78 | err, | 77 | let tt = db |
79 | macro_call_id.debug_dump(db) | 78 | .macro_expand(macro_call_id) |
80 | ); | 79 | .map_err(|err| { |
81 | }) | 80 | // Note: |
82 | .ok()?; | 81 | // The final goal we would like to make all parse_macro success, |
83 | match macro_file.macro_file_kind { | 82 | // such that the following log will not call anyway. |
84 | MacroFileKind::Items => { | 83 | log::warn!( |
85 | Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned()) | 84 | "fail on macro_parse: (reason: {}) {}", |
86 | } | 85 | err, |
87 | MacroFileKind::Expr => { | 86 | macro_call_id.debug_dump(db) |
88 | mbe::token_tree_to_expr(&tt).ok().map(|it| it.syntax().to_owned()) | 87 | ); |
89 | } | 88 | }) |
90 | } | 89 | .ok()?; |
90 | match macro_file.macro_file_kind { | ||
91 | MacroFileKind::Items => Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned()), | ||
92 | MacroFileKind::Expr => { | ||
93 | mbe::token_tree_to_expr(&tt).ok().map(|it| it.syntax().to_owned()) | ||
91 | } | 94 | } |
92 | } | 95 | } |
93 | } | 96 | } |
@@ -100,7 +103,7 @@ enum HirFileIdRepr { | |||
100 | } | 103 | } |
101 | 104 | ||
102 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 105 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
103 | struct MacroFile { | 106 | pub struct MacroFile { |
104 | macro_call_id: MacroCallId, | 107 | macro_call_id: MacroCallId, |
105 | macro_file_kind: MacroFileKind, | 108 | macro_file_kind: MacroFileKind, |
106 | } | 109 | } |