diff options
Diffstat (limited to 'crates/ra_hir/src/source_analyzer.rs')
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 0ed6d0958..74d64c97d 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -14,7 +14,7 @@ use hir_def::{ | |||
14 | }, | 14 | }, |
15 | expr::{ExprId, Pat, PatId}, | 15 | expr::{ExprId, Pat, PatId}, |
16 | resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs}, | 16 | resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs}, |
17 | AsMacroCall, DefWithBodyId, LocalStructFieldId, StructFieldId, VariantId, | 17 | AsMacroCall, DefWithBodyId, FieldId, LocalFieldId, VariantId, |
18 | }; | 18 | }; |
19 | use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; | 19 | use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; |
20 | use hir_ty::{ | 20 | use hir_ty::{ |
@@ -23,12 +23,12 @@ use hir_ty::{ | |||
23 | }; | 23 | }; |
24 | use ra_syntax::{ | 24 | use ra_syntax::{ |
25 | ast::{self, AstNode}, | 25 | ast::{self, AstNode}, |
26 | SyntaxNode, TextRange, TextUnit, | 26 | SyntaxNode, TextRange, TextSize, |
27 | }; | 27 | }; |
28 | 28 | ||
29 | use crate::{ | 29 | use crate::{ |
30 | db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Function, Local, MacroDef, | 30 | db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Field, Function, Local, |
31 | ModPath, ModuleDef, Path, PathKind, Static, Struct, StructField, Trait, Type, TypeAlias, | 31 | MacroDef, ModPath, ModuleDef, Path, PathKind, Static, Struct, Trait, Type, TypeAlias, |
32 | TypeParam, | 32 | TypeParam, |
33 | }; | 33 | }; |
34 | use ra_db::CrateId; | 34 | use ra_db::CrateId; |
@@ -50,7 +50,7 @@ impl SourceAnalyzer { | |||
50 | db: &dyn HirDatabase, | 50 | db: &dyn HirDatabase, |
51 | def: DefWithBodyId, | 51 | def: DefWithBodyId, |
52 | node: InFile<&SyntaxNode>, | 52 | node: InFile<&SyntaxNode>, |
53 | offset: Option<TextUnit>, | 53 | offset: Option<TextSize>, |
54 | ) -> SourceAnalyzer { | 54 | ) -> SourceAnalyzer { |
55 | let (body, source_map) = db.body_with_source_map(def); | 55 | let (body, source_map) = db.body_with_source_map(def); |
56 | let scopes = db.expr_scopes(def); | 56 | let scopes = db.expr_scopes(def); |
@@ -140,7 +140,7 @@ impl SourceAnalyzer { | |||
140 | &self, | 140 | &self, |
141 | db: &dyn HirDatabase, | 141 | db: &dyn HirDatabase, |
142 | field: &ast::FieldExpr, | 142 | field: &ast::FieldExpr, |
143 | ) -> Option<StructField> { | 143 | ) -> Option<Field> { |
144 | let expr_id = self.expr_id(db, &field.clone().into())?; | 144 | let expr_id = self.expr_id(db, &field.clone().into())?; |
145 | self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into()) | 145 | self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into()) |
146 | } | 146 | } |
@@ -149,7 +149,7 @@ impl SourceAnalyzer { | |||
149 | &self, | 149 | &self, |
150 | db: &dyn HirDatabase, | 150 | db: &dyn HirDatabase, |
151 | field: &ast::RecordField, | 151 | field: &ast::RecordField, |
152 | ) -> Option<(StructField, Option<Local>)> { | 152 | ) -> Option<(Field, Option<Local>)> { |
153 | let expr = field.expr()?; | 153 | let expr = field.expr()?; |
154 | let expr_id = self.expr_id(db, &expr)?; | 154 | let expr_id = self.expr_id(db, &expr)?; |
155 | let local = if field.name_ref().is_some() { | 155 | let local = if field.name_ref().is_some() { |
@@ -172,7 +172,7 @@ impl SourceAnalyzer { | |||
172 | &self, | 172 | &self, |
173 | _db: &dyn HirDatabase, | 173 | _db: &dyn HirDatabase, |
174 | field: &ast::RecordFieldPat, | 174 | field: &ast::RecordFieldPat, |
175 | ) -> Option<StructField> { | 175 | ) -> Option<Field> { |
176 | let pat_id = self.pat_id(&field.pat()?)?; | 176 | let pat_id = self.pat_id(&field.pat()?)?; |
177 | let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; | 177 | let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; |
178 | Some(struct_field.into()) | 178 | Some(struct_field.into()) |
@@ -232,7 +232,7 @@ impl SourceAnalyzer { | |||
232 | &self, | 232 | &self, |
233 | db: &dyn HirDatabase, | 233 | db: &dyn HirDatabase, |
234 | literal: &ast::RecordLit, | 234 | literal: &ast::RecordLit, |
235 | ) -> Option<Vec<(StructField, Type)>> { | 235 | ) -> Option<Vec<(Field, Type)>> { |
236 | let krate = self.resolver.krate()?; | 236 | let krate = self.resolver.krate()?; |
237 | let body = self.body.as_ref()?; | 237 | let body = self.body.as_ref()?; |
238 | let infer = self.infer.as_ref()?; | 238 | let infer = self.infer.as_ref()?; |
@@ -253,7 +253,7 @@ impl SourceAnalyzer { | |||
253 | &self, | 253 | &self, |
254 | db: &dyn HirDatabase, | 254 | db: &dyn HirDatabase, |
255 | pattern: &ast::RecordPat, | 255 | pattern: &ast::RecordPat, |
256 | ) -> Option<Vec<(StructField, Type)>> { | 256 | ) -> Option<Vec<(Field, Type)>> { |
257 | let krate = self.resolver.krate()?; | 257 | let krate = self.resolver.krate()?; |
258 | let body = self.body.as_ref()?; | 258 | let body = self.body.as_ref()?; |
259 | let infer = self.infer.as_ref()?; | 259 | let infer = self.infer.as_ref()?; |
@@ -276,14 +276,14 @@ impl SourceAnalyzer { | |||
276 | krate: CrateId, | 276 | krate: CrateId, |
277 | substs: &Substs, | 277 | substs: &Substs, |
278 | variant: VariantId, | 278 | variant: VariantId, |
279 | missing_fields: Vec<LocalStructFieldId>, | 279 | missing_fields: Vec<LocalFieldId>, |
280 | ) -> Vec<(StructField, Type)> { | 280 | ) -> Vec<(Field, Type)> { |
281 | let field_types = db.field_types(variant); | 281 | let field_types = db.field_types(variant); |
282 | 282 | ||
283 | missing_fields | 283 | missing_fields |
284 | .into_iter() | 284 | .into_iter() |
285 | .map(|local_id| { | 285 | .map(|local_id| { |
286 | let field = StructFieldId { parent: variant, local_id }; | 286 | let field = FieldId { parent: variant, local_id }; |
287 | let ty = field_types[local_id].clone().subst(substs); | 287 | let ty = field_types[local_id].clone().subst(substs); |
288 | (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty)) | 288 | (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty)) |
289 | }) | 289 | }) |
@@ -318,7 +318,7 @@ fn scope_for_offset( | |||
318 | db: &dyn HirDatabase, | 318 | db: &dyn HirDatabase, |
319 | scopes: &ExprScopes, | 319 | scopes: &ExprScopes, |
320 | source_map: &BodySourceMap, | 320 | source_map: &BodySourceMap, |
321 | offset: InFile<TextUnit>, | 321 | offset: InFile<TextSize>, |
322 | ) -> Option<ScopeId> { | 322 | ) -> Option<ScopeId> { |
323 | scopes | 323 | scopes |
324 | .scope_by_expr() | 324 | .scope_by_expr() |
@@ -354,7 +354,7 @@ fn adjust( | |||
354 | source_map: &BodySourceMap, | 354 | source_map: &BodySourceMap, |
355 | expr_range: TextRange, | 355 | expr_range: TextRange, |
356 | file_id: HirFileId, | 356 | file_id: HirFileId, |
357 | offset: TextUnit, | 357 | offset: TextSize, |
358 | ) -> Option<ScopeId> { | 358 | ) -> Option<ScopeId> { |
359 | let child_scopes = scopes | 359 | let child_scopes = scopes |
360 | .scope_by_expr() | 360 | .scope_by_expr() |
@@ -369,15 +369,15 @@ fn adjust( | |||
369 | let node = source.value.to_node(&root); | 369 | let node = source.value.to_node(&root); |
370 | Some((node.syntax().text_range(), scope)) | 370 | Some((node.syntax().text_range(), scope)) |
371 | }) | 371 | }) |
372 | .filter(|(range, _)| { | 372 | .filter(|&(range, _)| { |
373 | range.start() <= offset && range.is_subrange(&expr_range) && *range != expr_range | 373 | range.start() <= offset && expr_range.contains_range(range) && range != expr_range |
374 | }); | 374 | }); |
375 | 375 | ||
376 | child_scopes | 376 | child_scopes |
377 | .max_by(|(r1, _), (r2, _)| { | 377 | .max_by(|&(r1, _), &(r2, _)| { |
378 | if r2.is_subrange(&r1) { | 378 | if r1.contains_range(r2) { |
379 | std::cmp::Ordering::Greater | 379 | std::cmp::Ordering::Greater |
380 | } else if r1.is_subrange(&r2) { | 380 | } else if r2.contains_range(r1) { |
381 | std::cmp::Ordering::Less | 381 | std::cmp::Ordering::Less |
382 | } else { | 382 | } else { |
383 | r1.start().cmp(&r2.start()) | 383 | r1.start().cmp(&r2.start()) |