aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-17 10:38:51 +0100
committerAleksey Kladov <[email protected]>2020-04-17 11:25:41 +0100
commit302bf97bbf1855e3c7def9ab4f9f3d338be5e3b7 (patch)
treef26fcf569dea4fa40ca3814d30e340572a66374b /crates
parent69f0cb6cd77c2dc93f2eed180a6c16fd8c3fca5a (diff)
Don't expose impl details of SyntaxPtr
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/body.rs4
-rw-r--r--crates/ra_hir_def/src/body/lower.rs3
-rw-r--r--crates/ra_hir_def/src/diagnostics.rs6
-rw-r--r--crates/ra_hir_def/src/nameres.rs3
-rw-r--r--crates/ra_hir_expand/src/diagnostics.rs4
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs24
-rw-r--r--crates/ra_hir_ty/src/expr.rs14
-rw-r--r--crates/ra_hir_ty/src/infer.rs11
8 files changed, 55 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index eafaf48c1..3b169440a 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -210,7 +210,7 @@ pub struct BodySourceMap {
210 expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>, 210 expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>,
211 pat_map: FxHashMap<PatSource, PatId>, 211 pat_map: FxHashMap<PatSource, PatId>,
212 pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>, 212 pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>,
213 field_map: FxHashMap<(ExprId, usize), AstPtr<ast::RecordField>>, 213 field_map: FxHashMap<(ExprId, usize), InFile<AstPtr<ast::RecordField>>>,
214 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>, 214 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>,
215} 215}
216 216
@@ -303,7 +303,7 @@ impl BodySourceMap {
303 self.pat_map.get(&src).cloned() 303 self.pat_map.get(&src).cloned()
304 } 304 }
305 305
306 pub fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> { 306 pub fn field_syntax(&self, expr: ExprId, field: usize) -> InFile<AstPtr<ast::RecordField>> {
307 self.field_map[&(expr, field)].clone() 307 self.field_map[&(expr, field)].clone()
308 } 308 }
309} 309}
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 79abe55ce..10a1ba714 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -320,7 +320,8 @@ impl ExprCollector<'_> {
320 320
321 let res = self.alloc_expr(record_lit, syntax_ptr); 321 let res = self.alloc_expr(record_lit, syntax_ptr);
322 for (i, ptr) in field_ptrs.into_iter().enumerate() { 322 for (i, ptr) in field_ptrs.into_iter().enumerate() {
323 self.source_map.field_map.insert((res, i), ptr); 323 let src = self.expander.to_source(ptr);
324 self.source_map.field_map.insert((res, i), src);
324 } 325 }
325 res 326 res
326 } 327 }
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs
index cfa0f2f76..dbaf4deef 100644
--- a/crates/ra_hir_def/src/diagnostics.rs
+++ b/crates/ra_hir_def/src/diagnostics.rs
@@ -4,7 +4,7 @@ use std::any::Any;
4 4
5use hir_expand::diagnostics::Diagnostic; 5use hir_expand::diagnostics::Diagnostic;
6use ra_db::RelativePathBuf; 6use ra_db::RelativePathBuf;
7use ra_syntax::{ast, AstPtr, SyntaxNodePtr}; 7use ra_syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
8 8
9use hir_expand::{HirFileId, InFile}; 9use hir_expand::{HirFileId, InFile};
10 10
@@ -12,6 +12,7 @@ use hir_expand::{HirFileId, InFile};
12pub struct UnresolvedModule { 12pub struct UnresolvedModule {
13 pub file: HirFileId, 13 pub file: HirFileId,
14 pub decl: AstPtr<ast::Module>, 14 pub decl: AstPtr<ast::Module>,
15 pub highlight_range: TextRange,
15 pub candidate: RelativePathBuf, 16 pub candidate: RelativePathBuf,
16} 17}
17 18
@@ -19,6 +20,9 @@ impl Diagnostic for UnresolvedModule {
19 fn message(&self) -> String { 20 fn message(&self) -> String {
20 "unresolved module".to_string() 21 "unresolved module".to_string()
21 } 22 }
23 fn highlight_range(&self) -> TextRange {
24 self.highlight_range
25 }
22 fn source(&self) -> InFile<SyntaxNodePtr> { 26 fn source(&self) -> InFile<SyntaxNodePtr> {
23 InFile { file_id: self.file, value: self.decl.clone().into() } 27 InFile { file_id: self.file, value: self.decl.clone().into() }
24 } 28 }
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index f279c2ad4..4a5a93dad 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -297,7 +297,7 @@ pub enum ModuleSource {
297mod diagnostics { 297mod diagnostics {
298 use hir_expand::diagnostics::DiagnosticSink; 298 use hir_expand::diagnostics::DiagnosticSink;
299 use ra_db::RelativePathBuf; 299 use ra_db::RelativePathBuf;
300 use ra_syntax::{ast, AstPtr}; 300 use ra_syntax::{ast, AstNode, AstPtr};
301 301
302 use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::LocalModuleId, AstId}; 302 use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::LocalModuleId, AstId};
303 303
@@ -326,6 +326,7 @@ mod diagnostics {
326 sink.push(UnresolvedModule { 326 sink.push(UnresolvedModule {
327 file: declaration.file_id, 327 file: declaration.file_id,
328 decl: AstPtr::new(&decl), 328 decl: AstPtr::new(&decl),
329 highlight_range: decl.syntax().text_range(),
329 candidate: candidate.clone(), 330 candidate: candidate.clone(),
330 }) 331 })
331 } 332 }
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs
index 108c1e38c..714e700f7 100644
--- a/crates/ra_hir_expand/src/diagnostics.rs
+++ b/crates/ra_hir_expand/src/diagnostics.rs
@@ -22,10 +22,8 @@ use crate::{db::AstDatabase, InFile};
22 22
23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { 23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
24 fn message(&self) -> String; 24 fn message(&self) -> String;
25 fn highlight_range(&self) -> TextRange;
25 fn source(&self) -> InFile<SyntaxNodePtr>; 26 fn source(&self) -> InFile<SyntaxNodePtr>;
26 fn highlight_range(&self) -> TextRange {
27 self.source().value.range()
28 }
29 fn as_any(&self) -> &(dyn Any + Send + 'static); 27 fn as_any(&self) -> &(dyn Any + Send + 'static);
30} 28}
31 29
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 927896d6f..da85bd082 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -3,7 +3,7 @@
3use std::any::Any; 3use std::any::Any;
4 4
5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; 5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; 6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr, TextRange};
7use stdx::format_to; 7use stdx::format_to;
8 8
9pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm}; 9pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm};
@@ -13,6 +13,7 @@ pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
13pub struct NoSuchField { 13pub struct NoSuchField {
14 pub file: HirFileId, 14 pub file: HirFileId,
15 pub field: AstPtr<ast::RecordField>, 15 pub field: AstPtr<ast::RecordField>,
16 pub highlight_range: TextRange,
16} 17}
17 18
18impl Diagnostic for NoSuchField { 19impl Diagnostic for NoSuchField {
@@ -20,6 +21,10 @@ impl Diagnostic for NoSuchField {
20 "no such field".to_string() 21 "no such field".to_string()
21 } 22 }
22 23
24 fn highlight_range(&self) -> TextRange {
25 self.highlight_range
26 }
27
23 fn source(&self) -> InFile<SyntaxNodePtr> { 28 fn source(&self) -> InFile<SyntaxNodePtr> {
24 InFile { file_id: self.file, value: self.field.clone().into() } 29 InFile { file_id: self.file, value: self.field.clone().into() }
25 } 30 }
@@ -33,6 +38,7 @@ impl Diagnostic for NoSuchField {
33pub struct MissingFields { 38pub struct MissingFields {
34 pub file: HirFileId, 39 pub file: HirFileId,
35 pub field_list: AstPtr<ast::RecordFieldList>, 40 pub field_list: AstPtr<ast::RecordFieldList>,
41 pub highlight_range: TextRange,
36 pub missed_fields: Vec<Name>, 42 pub missed_fields: Vec<Name>,
37} 43}
38 44
@@ -44,6 +50,10 @@ impl Diagnostic for MissingFields {
44 } 50 }
45 buf 51 buf
46 } 52 }
53 fn highlight_range(&self) -> TextRange {
54 self.highlight_range
55 }
56
47 fn source(&self) -> InFile<SyntaxNodePtr> { 57 fn source(&self) -> InFile<SyntaxNodePtr> {
48 InFile { file_id: self.file, value: self.field_list.clone().into() } 58 InFile { file_id: self.file, value: self.field_list.clone().into() }
49 } 59 }
@@ -66,6 +76,7 @@ impl AstDiagnostic for MissingFields {
66pub struct MissingPatFields { 76pub struct MissingPatFields {
67 pub file: HirFileId, 77 pub file: HirFileId,
68 pub field_list: AstPtr<ast::RecordFieldPatList>, 78 pub field_list: AstPtr<ast::RecordFieldPatList>,
79 pub highlight_range: TextRange,
69 pub missed_fields: Vec<Name>, 80 pub missed_fields: Vec<Name>,
70} 81}
71 82
@@ -77,6 +88,9 @@ impl Diagnostic for MissingPatFields {
77 } 88 }
78 buf 89 buf
79 } 90 }
91 fn highlight_range(&self) -> TextRange {
92 self.highlight_range
93 }
80 fn source(&self) -> InFile<SyntaxNodePtr> { 94 fn source(&self) -> InFile<SyntaxNodePtr> {
81 InFile { file_id: self.file, value: self.field_list.clone().into() } 95 InFile { file_id: self.file, value: self.field_list.clone().into() }
82 } 96 }
@@ -90,12 +104,16 @@ pub struct MissingMatchArms {
90 pub file: HirFileId, 104 pub file: HirFileId,
91 pub match_expr: AstPtr<ast::Expr>, 105 pub match_expr: AstPtr<ast::Expr>,
92 pub arms: AstPtr<ast::MatchArmList>, 106 pub arms: AstPtr<ast::MatchArmList>,
107 pub highlight_range: TextRange,
93} 108}
94 109
95impl Diagnostic for MissingMatchArms { 110impl Diagnostic for MissingMatchArms {
96 fn message(&self) -> String { 111 fn message(&self) -> String {
97 String::from("Missing match arm") 112 String::from("Missing match arm")
98 } 113 }
114 fn highlight_range(&self) -> TextRange {
115 self.highlight_range
116 }
99 fn source(&self) -> InFile<SyntaxNodePtr> { 117 fn source(&self) -> InFile<SyntaxNodePtr> {
100 InFile { file_id: self.file, value: self.match_expr.clone().into() } 118 InFile { file_id: self.file, value: self.match_expr.clone().into() }
101 } 119 }
@@ -108,12 +126,16 @@ impl Diagnostic for MissingMatchArms {
108pub struct MissingOkInTailExpr { 126pub struct MissingOkInTailExpr {
109 pub file: HirFileId, 127 pub file: HirFileId,
110 pub expr: AstPtr<ast::Expr>, 128 pub expr: AstPtr<ast::Expr>,
129 pub highlight_range: TextRange,
111} 130}
112 131
113impl Diagnostic for MissingOkInTailExpr { 132impl Diagnostic for MissingOkInTailExpr {
114 fn message(&self) -> String { 133 fn message(&self) -> String {
115 "wrap return expression in Ok".to_string() 134 "wrap return expression in Ok".to_string()
116 } 135 }
136 fn highlight_range(&self) -> TextRange {
137 self.highlight_range
138 }
117 fn source(&self) -> InFile<SyntaxNodePtr> { 139 fn source(&self) -> InFile<SyntaxNodePtr> {
118 InFile { file_id: self.file, value: self.expr.clone().into() } 140 InFile { file_id: self.file, value: self.expr.clone().into() }
119 } 141 }
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index fd59f4320..1d3950b70 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -4,7 +4,7 @@ use std::sync::Arc;
4 4
5use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId}; 5use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId};
6use hir_expand::diagnostics::DiagnosticSink; 6use hir_expand::diagnostics::DiagnosticSink;
7use ra_syntax::{ast, AstPtr}; 7use ra_syntax::{ast, AstNode, AstPtr};
8use rustc_hash::FxHashSet; 8use rustc_hash::FxHashSet;
9 9
10use crate::{ 10use crate::{
@@ -100,6 +100,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
100 self.sink.push(MissingFields { 100 self.sink.push(MissingFields {
101 file: source_ptr.file_id, 101 file: source_ptr.file_id,
102 field_list: AstPtr::new(&field_list), 102 field_list: AstPtr::new(&field_list),
103 highlight_range: field_list.syntax().text_range(),
103 missed_fields, 104 missed_fields,
104 }) 105 })
105 } 106 }
@@ -130,6 +131,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
130 self.sink.push(MissingPatFields { 131 self.sink.push(MissingPatFields {
131 file: source_ptr.file_id, 132 file: source_ptr.file_id,
132 field_list: AstPtr::new(&field_list), 133 field_list: AstPtr::new(&field_list),
134 highlight_range: field_list.syntax().text_range(),
133 missed_fields, 135 missed_fields,
134 }) 136 })
135 } 137 }
@@ -213,6 +215,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
213 file: source_ptr.file_id, 215 file: source_ptr.file_id,
214 match_expr: AstPtr::new(&match_expr), 216 match_expr: AstPtr::new(&match_expr),
215 arms: AstPtr::new(&arms), 217 arms: AstPtr::new(&arms),
218 highlight_range: match_expr.syntax().text_range(),
216 }) 219 })
217 } 220 }
218 } 221 }
@@ -244,8 +247,13 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
244 let (_, source_map) = db.body_with_source_map(self.func.into()); 247 let (_, source_map) = db.body_with_source_map(self.func.into());
245 248
246 if let Ok(source_ptr) = source_map.expr_syntax(id) { 249 if let Ok(source_ptr) = source_map.expr_syntax(id) {
247 self.sink 250 let root = source_ptr.file_syntax(db.upcast());
248 .push(MissingOkInTailExpr { file: source_ptr.file_id, expr: source_ptr.value }); 251 let highlight_range = source_ptr.value.to_node(&root).syntax().text_range();
252 self.sink.push(MissingOkInTailExpr {
253 file: source_ptr.file_id,
254 expr: source_ptr.value,
255 highlight_range,
256 });
249 } 257 }
250 } 258 }
251 } 259 }
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index 246b0e9be..7e6cdefe4 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -665,6 +665,7 @@ impl Expectation {
665mod diagnostics { 665mod diagnostics {
666 use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup}; 666 use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup};
667 use hir_expand::diagnostics::DiagnosticSink; 667 use hir_expand::diagnostics::DiagnosticSink;
668 use ra_syntax::AstNode;
668 669
669 use crate::{db::HirDatabase, diagnostics::NoSuchField}; 670 use crate::{db::HirDatabase, diagnostics::NoSuchField};
670 671
@@ -682,10 +683,16 @@ mod diagnostics {
682 ) { 683 ) {
683 match self { 684 match self {
684 InferenceDiagnostic::NoSuchField { expr, field } => { 685 InferenceDiagnostic::NoSuchField { expr, field } => {
685 let file = owner.lookup(db.upcast()).source(db.upcast()).file_id; 686 let source = owner.lookup(db.upcast()).source(db.upcast());
686 let (_, source_map) = db.body_with_source_map(owner.into()); 687 let (_, source_map) = db.body_with_source_map(owner.into());
687 let field = source_map.field_syntax(*expr, *field); 688 let field = source_map.field_syntax(*expr, *field);
688 sink.push(NoSuchField { file, field }) 689 let root = field.file_syntax(db.upcast());
690 let highlight_range = field.value.to_node(&root).syntax().text_range();
691 sink.push(NoSuchField {
692 file: source.file_id,
693 field: field.value,
694 highlight_range,
695 })
689 } 696 }
690 } 697 }
691 } 698 }