diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 34 | ||||
-rw-r--r-- | crates/ra_hir/src/from_id.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir/src/has_source.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/semantics.rs | 45 | ||||
-rw-r--r-- | crates/ra_hir/src/semantics/source_to_def.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 40 |
7 files changed, 75 insertions, 84 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 43f932e20..3f645a1dd 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -13,8 +13,8 @@ use hir_def::{ | |||
13 | resolver::{HasResolver, Resolver}, | 13 | resolver::{HasResolver, Resolver}, |
14 | type_ref::{Mutability, TypeRef}, | 14 | type_ref::{Mutability, TypeRef}, |
15 | AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, | 15 | AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, |
16 | ImplId, LocalEnumVariantId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, | 16 | ImplId, LocalEnumVariantId, LocalFieldId, LocalModuleId, Lookup, ModuleId, StaticId, StructId, |
17 | StructId, TraitId, TypeAliasId, TypeParamId, UnionId, | 17 | TraitId, TypeAliasId, TypeParamId, UnionId, |
18 | }; | 18 | }; |
19 | use hir_expand::{ | 19 | use hir_expand::{ |
20 | diagnostics::DiagnosticSink, | 20 | diagnostics::DiagnosticSink, |
@@ -294,9 +294,9 @@ impl Module { | |||
294 | } | 294 | } |
295 | 295 | ||
296 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 296 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
297 | pub struct StructField { | 297 | pub struct Field { |
298 | pub(crate) parent: VariantDef, | 298 | pub(crate) parent: VariantDef, |
299 | pub(crate) id: LocalStructFieldId, | 299 | pub(crate) id: LocalFieldId, |
300 | } | 300 | } |
301 | 301 | ||
302 | #[derive(Debug, PartialEq, Eq)] | 302 | #[derive(Debug, PartialEq, Eq)] |
@@ -305,7 +305,7 @@ pub enum FieldSource { | |||
305 | Pos(ast::TupleFieldDef), | 305 | Pos(ast::TupleFieldDef), |
306 | } | 306 | } |
307 | 307 | ||
308 | impl StructField { | 308 | impl Field { |
309 | pub fn name(&self, db: &dyn HirDatabase) -> Name { | 309 | pub fn name(&self, db: &dyn HirDatabase) -> Name { |
310 | self.parent.variant_data(db).fields()[self.id].name.clone() | 310 | self.parent.variant_data(db).fields()[self.id].name.clone() |
311 | } | 311 | } |
@@ -331,7 +331,7 @@ impl StructField { | |||
331 | } | 331 | } |
332 | } | 332 | } |
333 | 333 | ||
334 | impl HasVisibility for StructField { | 334 | impl HasVisibility for Field { |
335 | fn visibility(&self, db: &dyn HirDatabase) -> Visibility { | 335 | fn visibility(&self, db: &dyn HirDatabase) -> Visibility { |
336 | let variant_data = self.parent.variant_data(db); | 336 | let variant_data = self.parent.variant_data(db); |
337 | let visibility = &variant_data.fields()[self.id].visibility; | 337 | let visibility = &variant_data.fields()[self.id].visibility; |
@@ -358,12 +358,12 @@ impl Struct { | |||
358 | db.struct_data(self.id).name.clone() | 358 | db.struct_data(self.id).name.clone() |
359 | } | 359 | } |
360 | 360 | ||
361 | pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { | 361 | pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> { |
362 | db.struct_data(self.id) | 362 | db.struct_data(self.id) |
363 | .variant_data | 363 | .variant_data |
364 | .fields() | 364 | .fields() |
365 | .iter() | 365 | .iter() |
366 | .map(|(id, _)| StructField { parent: self.into(), id }) | 366 | .map(|(id, _)| Field { parent: self.into(), id }) |
367 | .collect() | 367 | .collect() |
368 | } | 368 | } |
369 | 369 | ||
@@ -394,12 +394,12 @@ impl Union { | |||
394 | Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id) | 394 | Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id) |
395 | } | 395 | } |
396 | 396 | ||
397 | pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { | 397 | pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> { |
398 | db.union_data(self.id) | 398 | db.union_data(self.id) |
399 | .variant_data | 399 | .variant_data |
400 | .fields() | 400 | .fields() |
401 | .iter() | 401 | .iter() |
402 | .map(|(id, _)| StructField { parent: self.into(), id }) | 402 | .map(|(id, _)| Field { parent: self.into(), id }) |
403 | .collect() | 403 | .collect() |
404 | } | 404 | } |
405 | 405 | ||
@@ -457,11 +457,11 @@ impl EnumVariant { | |||
457 | db.enum_data(self.parent.id).variants[self.id].name.clone() | 457 | db.enum_data(self.parent.id).variants[self.id].name.clone() |
458 | } | 458 | } |
459 | 459 | ||
460 | pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { | 460 | pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> { |
461 | self.variant_data(db) | 461 | self.variant_data(db) |
462 | .fields() | 462 | .fields() |
463 | .iter() | 463 | .iter() |
464 | .map(|(id, _)| StructField { parent: self.into(), id }) | 464 | .map(|(id, _)| Field { parent: self.into(), id }) |
465 | .collect() | 465 | .collect() |
466 | } | 466 | } |
467 | 467 | ||
@@ -527,7 +527,7 @@ pub enum VariantDef { | |||
527 | impl_froms!(VariantDef: Struct, Union, EnumVariant); | 527 | impl_froms!(VariantDef: Struct, Union, EnumVariant); |
528 | 528 | ||
529 | impl VariantDef { | 529 | impl VariantDef { |
530 | pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { | 530 | pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> { |
531 | match self { | 531 | match self { |
532 | VariantDef::Struct(it) => it.fields(db), | 532 | VariantDef::Struct(it) => it.fields(db), |
533 | VariantDef::Union(it) => it.fields(db), | 533 | VariantDef::Union(it) => it.fields(db), |
@@ -1148,7 +1148,7 @@ impl Type { | |||
1148 | } | 1148 | } |
1149 | } | 1149 | } |
1150 | 1150 | ||
1151 | pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(StructField, Type)> { | 1151 | pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> { |
1152 | if let Ty::Apply(a_ty) = &self.ty.value { | 1152 | if let Ty::Apply(a_ty) = &self.ty.value { |
1153 | if let TypeCtor::Adt(AdtId::StructId(s)) = a_ty.ctor { | 1153 | if let TypeCtor::Adt(AdtId::StructId(s)) = a_ty.ctor { |
1154 | let var_def = s.into(); | 1154 | let var_def = s.into(); |
@@ -1156,7 +1156,7 @@ impl Type { | |||
1156 | .field_types(var_def) | 1156 | .field_types(var_def) |
1157 | .iter() | 1157 | .iter() |
1158 | .map(|(local_id, ty)| { | 1158 | .map(|(local_id, ty)| { |
1159 | let def = StructField { parent: var_def.into(), id: local_id }; | 1159 | let def = Field { parent: var_def.into(), id: local_id }; |
1160 | let ty = ty.clone().subst(&a_ty.parameters); | 1160 | let ty = ty.clone().subst(&a_ty.parameters); |
1161 | (def, self.derived(ty)) | 1161 | (def, self.derived(ty)) |
1162 | }) | 1162 | }) |
@@ -1352,7 +1352,7 @@ impl ScopeDef { | |||
1352 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 1352 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
1353 | pub enum AttrDef { | 1353 | pub enum AttrDef { |
1354 | Module(Module), | 1354 | Module(Module), |
1355 | StructField(StructField), | 1355 | Field(Field), |
1356 | Adt(Adt), | 1356 | Adt(Adt), |
1357 | Function(Function), | 1357 | Function(Function), |
1358 | EnumVariant(EnumVariant), | 1358 | EnumVariant(EnumVariant), |
@@ -1365,7 +1365,7 @@ pub enum AttrDef { | |||
1365 | 1365 | ||
1366 | impl_froms!( | 1366 | impl_froms!( |
1367 | AttrDef: Module, | 1367 | AttrDef: Module, |
1368 | StructField, | 1368 | Field, |
1369 | Adt(Struct, Enum, Union), | 1369 | Adt(Struct, Enum, Union), |
1370 | EnumVariant, | 1370 | EnumVariant, |
1371 | Static, | 1371 | Static, |
diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index 62fb52e72..679ae8121 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs | |||
@@ -4,13 +4,13 @@ | |||
4 | //! are splitting the hir. | 4 | //! are splitting the hir. |
5 | 5 | ||
6 | use hir_def::{ | 6 | use hir_def::{ |
7 | expr::PatId, AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, GenericDefId, | 7 | expr::PatId, AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, FieldId, |
8 | ModuleDefId, StructFieldId, VariantId, | 8 | GenericDefId, ModuleDefId, VariantId, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, Local, | 12 | code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, Field, GenericDef, |
13 | MacroDef, ModuleDef, StructField, VariantDef, | 13 | Local, MacroDef, ModuleDef, VariantDef, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | macro_rules! from_id { | 16 | macro_rules! from_id { |
@@ -184,15 +184,15 @@ impl From<VariantDef> for VariantId { | |||
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | impl From<StructField> for StructFieldId { | 187 | impl From<Field> for FieldId { |
188 | fn from(def: StructField) -> Self { | 188 | fn from(def: Field) -> Self { |
189 | StructFieldId { parent: def.parent.into(), local_id: def.id } | 189 | FieldId { parent: def.parent.into(), local_id: def.id } |
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
193 | impl From<StructFieldId> for StructField { | 193 | impl From<FieldId> for Field { |
194 | fn from(def: StructFieldId) -> Self { | 194 | fn from(def: FieldId) -> Self { |
195 | StructField { parent: def.parent.into(), id: def.local_id } | 195 | Field { parent: def.parent.into(), id: def.local_id } |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
@@ -200,7 +200,7 @@ impl From<AttrDef> for AttrDefId { | |||
200 | fn from(def: AttrDef) -> Self { | 200 | fn from(def: AttrDef) -> Self { |
201 | match def { | 201 | match def { |
202 | AttrDef::Module(it) => AttrDefId::ModuleId(it.id), | 202 | AttrDef::Module(it) => AttrDefId::ModuleId(it.id), |
203 | AttrDef::StructField(it) => AttrDefId::StructFieldId(it.into()), | 203 | AttrDef::Field(it) => AttrDefId::FieldId(it.into()), |
204 | AttrDef::Adt(it) => AttrDefId::AdtId(it.into()), | 204 | AttrDef::Adt(it) => AttrDefId::AdtId(it.into()), |
205 | AttrDef::Function(it) => AttrDefId::FunctionId(it.id), | 205 | AttrDef::Function(it) => AttrDefId::FunctionId(it.id), |
206 | AttrDef::EnumVariant(it) => AttrDefId::EnumVariantId(it.into()), | 206 | AttrDef::EnumVariant(it) => AttrDefId::EnumVariantId(it.into()), |
diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs index 129764e0a..63b8fd369 100644 --- a/crates/ra_hir/src/has_source.rs +++ b/crates/ra_hir/src/has_source.rs | |||
@@ -9,8 +9,8 @@ use hir_def::{ | |||
9 | use ra_syntax::ast; | 9 | use ra_syntax::ast; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | db::HirDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplDef, MacroDef, Module, | 12 | db::HirDatabase, Const, Enum, EnumVariant, Field, FieldSource, Function, ImplDef, MacroDef, |
13 | Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, | 13 | Module, Static, Struct, Trait, TypeAlias, TypeParam, Union, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | pub use hir_expand::InFile; | 16 | pub use hir_expand::InFile; |
@@ -37,7 +37,7 @@ impl Module { | |||
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | impl HasSource for StructField { | 40 | impl HasSource for Field { |
41 | type Ast = FieldSource; | 41 | type Ast = FieldSource; |
42 | fn source(self, db: &dyn HirDatabase) -> InFile<FieldSource> { | 42 | fn source(self, db: &dyn HirDatabase) -> InFile<FieldSource> { |
43 | let var = VariantId::from(self.parent); | 43 | let var = VariantId::from(self.parent); |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 5af7e5d6d..312ef3814 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -52,9 +52,9 @@ mod has_source; | |||
52 | pub use crate::{ | 52 | pub use crate::{ |
53 | code_model::{ | 53 | code_model::{ |
54 | Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency, | 54 | Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency, |
55 | DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs, | 55 | DefWithBody, Docs, Enum, EnumVariant, Field, FieldSource, Function, GenericDef, HasAttrs, |
56 | HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, | 56 | HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, |
57 | StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, | 57 | Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, |
58 | }, | 58 | }, |
59 | has_source::HasSource, | 59 | has_source::HasSource, |
60 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, | 60 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, |
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 5d6edc45c..86bfb416c 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs | |||
@@ -14,7 +14,7 @@ use ra_db::{FileId, FileRange}; | |||
14 | use ra_prof::profile; | 14 | use ra_prof::profile; |
15 | use ra_syntax::{ | 15 | use ra_syntax::{ |
16 | algo::{find_node_at_offset, skip_trivia_token}, | 16 | algo::{find_node_at_offset, skip_trivia_token}, |
17 | ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextUnit, | 17 | ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize, |
18 | }; | 18 | }; |
19 | use rustc_hash::{FxHashMap, FxHashSet}; | 19 | use rustc_hash::{FxHashMap, FxHashSet}; |
20 | 20 | ||
@@ -23,8 +23,8 @@ use crate::{ | |||
23 | diagnostics::Diagnostic, | 23 | diagnostics::Diagnostic, |
24 | semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, | 24 | semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, |
25 | source_analyzer::{resolve_hir_path, SourceAnalyzer}, | 25 | source_analyzer::{resolve_hir_path, SourceAnalyzer}, |
26 | AssocItem, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, Name, | 26 | AssocItem, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, |
27 | Origin, Path, ScopeDef, StructField, Trait, Type, TypeParam, | 27 | Name, Origin, Path, ScopeDef, Trait, Type, TypeParam, |
28 | }; | 28 | }; |
29 | 29 | ||
30 | #[derive(Debug, Clone, PartialEq, Eq)] | 30 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -95,7 +95,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
95 | let token = successors(Some(parent.with_value(token)), |token| { | 95 | let token = successors(Some(parent.with_value(token)), |token| { |
96 | let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; | 96 | let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; |
97 | let tt = macro_call.token_tree()?; | 97 | let tt = macro_call.token_tree()?; |
98 | if !token.value.text_range().is_subrange(&tt.syntax().text_range()) { | 98 | if !tt.syntax().text_range().contains_range(token.value.text_range()) { |
99 | return None; | 99 | return None; |
100 | } | 100 | } |
101 | let file_id = sa.expand(self.db, token.with_value(¯o_call))?; | 101 | let file_id = sa.expand(self.db, token.with_value(¯o_call))?; |
@@ -114,7 +114,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
114 | pub fn descend_node_at_offset<N: ast::AstNode>( | 114 | pub fn descend_node_at_offset<N: ast::AstNode>( |
115 | &self, | 115 | &self, |
116 | node: &SyntaxNode, | 116 | node: &SyntaxNode, |
117 | offset: TextUnit, | 117 | offset: TextSize, |
118 | ) -> Option<N> { | 118 | ) -> Option<N> { |
119 | // Handle macro token cases | 119 | // Handle macro token cases |
120 | node.token_at_offset(offset) | 120 | node.token_at_offset(offset) |
@@ -142,7 +142,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
142 | pub fn ancestors_at_offset_with_macros( | 142 | pub fn ancestors_at_offset_with_macros( |
143 | &self, | 143 | &self, |
144 | node: &SyntaxNode, | 144 | node: &SyntaxNode, |
145 | offset: TextUnit, | 145 | offset: TextSize, |
146 | ) -> impl Iterator<Item = SyntaxNode> + '_ { | 146 | ) -> impl Iterator<Item = SyntaxNode> + '_ { |
147 | node.token_at_offset(offset) | 147 | node.token_at_offset(offset) |
148 | .map(|token| self.ancestors_with_macros(token.parent())) | 148 | .map(|token| self.ancestors_with_macros(token.parent())) |
@@ -154,7 +154,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
154 | pub fn find_node_at_offset_with_macros<N: AstNode>( | 154 | pub fn find_node_at_offset_with_macros<N: AstNode>( |
155 | &self, | 155 | &self, |
156 | node: &SyntaxNode, | 156 | node: &SyntaxNode, |
157 | offset: TextUnit, | 157 | offset: TextSize, |
158 | ) -> Option<N> { | 158 | ) -> Option<N> { |
159 | self.ancestors_at_offset_with_macros(node, offset).find_map(N::cast) | 159 | self.ancestors_at_offset_with_macros(node, offset).find_map(N::cast) |
160 | } | 160 | } |
@@ -164,7 +164,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
164 | pub fn find_node_at_offset_with_descend<N: AstNode>( | 164 | pub fn find_node_at_offset_with_descend<N: AstNode>( |
165 | &self, | 165 | &self, |
166 | node: &SyntaxNode, | 166 | node: &SyntaxNode, |
167 | offset: TextUnit, | 167 | offset: TextSize, |
168 | ) -> Option<N> { | 168 | ) -> Option<N> { |
169 | if let Some(it) = find_node_at_offset(&node, offset) { | 169 | if let Some(it) = find_node_at_offset(&node, offset) { |
170 | return Some(it); | 170 | return Some(it); |
@@ -184,18 +184,15 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
184 | self.analyze(call.syntax()).resolve_method_call(self.db, call) | 184 | self.analyze(call.syntax()).resolve_method_call(self.db, call) |
185 | } | 185 | } |
186 | 186 | ||
187 | pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<StructField> { | 187 | pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<Field> { |
188 | self.analyze(field.syntax()).resolve_field(self.db, field) | 188 | self.analyze(field.syntax()).resolve_field(self.db, field) |
189 | } | 189 | } |
190 | 190 | ||
191 | pub fn resolve_record_field( | 191 | pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option<Local>)> { |
192 | &self, | ||
193 | field: &ast::RecordField, | ||
194 | ) -> Option<(StructField, Option<Local>)> { | ||
195 | self.analyze(field.syntax()).resolve_record_field(self.db, field) | 192 | self.analyze(field.syntax()).resolve_record_field(self.db, field) |
196 | } | 193 | } |
197 | 194 | ||
198 | pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<StructField> { | 195 | pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> { |
199 | self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) | 196 | self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) |
200 | } | 197 | } |
201 | 198 | ||
@@ -216,19 +213,13 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
216 | // FIXME: use this instead? | 213 | // FIXME: use this instead? |
217 | // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>; | 214 | // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>; |
218 | 215 | ||
219 | pub fn record_literal_missing_fields( | 216 | pub fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> { |
220 | &self, | ||
221 | literal: &ast::RecordLit, | ||
222 | ) -> Vec<(StructField, Type)> { | ||
223 | self.analyze(literal.syntax()) | 217 | self.analyze(literal.syntax()) |
224 | .record_literal_missing_fields(self.db, literal) | 218 | .record_literal_missing_fields(self.db, literal) |
225 | .unwrap_or_default() | 219 | .unwrap_or_default() |
226 | } | 220 | } |
227 | 221 | ||
228 | pub fn record_pattern_missing_fields( | 222 | pub fn record_pattern_missing_fields(&self, pattern: &ast::RecordPat) -> Vec<(Field, Type)> { |
229 | &self, | ||
230 | pattern: &ast::RecordPat, | ||
231 | ) -> Vec<(StructField, Type)> { | ||
232 | self.analyze(pattern.syntax()) | 223 | self.analyze(pattern.syntax()) |
233 | .record_pattern_missing_fields(self.db, pattern) | 224 | .record_pattern_missing_fields(self.db, pattern) |
234 | .unwrap_or_default() | 225 | .unwrap_or_default() |
@@ -255,7 +246,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
255 | SemanticsScope { db: self.db, resolver } | 246 | SemanticsScope { db: self.db, resolver } |
256 | } | 247 | } |
257 | 248 | ||
258 | pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextUnit) -> SemanticsScope<'db, DB> { | 249 | pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db, DB> { |
259 | let node = self.find_file(node.clone()); | 250 | let node = self.find_file(node.clone()); |
260 | let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; | 251 | let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; |
261 | SemanticsScope { db: self.db, resolver } | 252 | SemanticsScope { db: self.db, resolver } |
@@ -271,7 +262,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
271 | self.analyze2(src.as_ref(), None) | 262 | self.analyze2(src.as_ref(), None) |
272 | } | 263 | } |
273 | 264 | ||
274 | fn analyze2(&self, src: InFile<&SyntaxNode>, offset: Option<TextUnit>) -> SourceAnalyzer { | 265 | fn analyze2(&self, src: InFile<&SyntaxNode>, offset: Option<TextSize>) -> SourceAnalyzer { |
275 | let _p = profile("Semantics::analyze2"); | 266 | let _p = profile("Semantics::analyze2"); |
276 | 267 | ||
277 | let container = match self.with_ctx(|ctx| ctx.find_container(src)) { | 268 | let container = match self.with_ctx(|ctx| ctx.find_container(src)) { |
@@ -359,8 +350,8 @@ to_def_impls![ | |||
359 | (crate::Const, ast::ConstDef, const_to_def), | 350 | (crate::Const, ast::ConstDef, const_to_def), |
360 | (crate::Static, ast::StaticDef, static_to_def), | 351 | (crate::Static, ast::StaticDef, static_to_def), |
361 | (crate::Function, ast::FnDef, fn_to_def), | 352 | (crate::Function, ast::FnDef, fn_to_def), |
362 | (crate::StructField, ast::RecordFieldDef, record_field_to_def), | 353 | (crate::Field, ast::RecordFieldDef, record_field_to_def), |
363 | (crate::StructField, ast::TupleFieldDef, tuple_field_to_def), | 354 | (crate::Field, ast::TupleFieldDef, tuple_field_to_def), |
364 | (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def), | 355 | (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def), |
365 | (crate::TypeParam, ast::TypeParam, type_param_to_def), | 356 | (crate::TypeParam, ast::TypeParam, type_param_to_def), |
366 | (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros | 357 | (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros |
@@ -463,7 +454,7 @@ fn original_range_opt( | |||
463 | return None; | 454 | return None; |
464 | } | 455 | } |
465 | 456 | ||
466 | Some(first.with_value(first.value.text_range().extend_to(&last.value.text_range()))) | 457 | Some(first.with_value(first.value.text_range().cover(last.value.text_range()))) |
467 | })?) | 458 | })?) |
468 | } | 459 | } |
469 | 460 | ||
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 66724919b..6f3b5b2da 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs | |||
@@ -5,8 +5,8 @@ use hir_def::{ | |||
5 | dyn_map::DynMap, | 5 | dyn_map::DynMap, |
6 | expr::PatId, | 6 | expr::PatId, |
7 | keys::{self, Key}, | 7 | keys::{self, Key}, |
8 | ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, ModuleId, | 8 | ConstId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId, GenericDefId, ImplId, |
9 | StaticId, StructFieldId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, | 9 | ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, |
10 | }; | 10 | }; |
11 | use hir_expand::{name::AsName, AstId, MacroDefKind}; | 11 | use hir_expand::{name::AsName, AstId, MacroDefKind}; |
12 | use ra_db::FileId; | 12 | use ra_db::FileId; |
@@ -97,13 +97,13 @@ impl SourceToDefCtx<'_, '_> { | |||
97 | pub(super) fn record_field_to_def( | 97 | pub(super) fn record_field_to_def( |
98 | &mut self, | 98 | &mut self, |
99 | src: InFile<ast::RecordFieldDef>, | 99 | src: InFile<ast::RecordFieldDef>, |
100 | ) -> Option<StructFieldId> { | 100 | ) -> Option<FieldId> { |
101 | self.to_def(src, keys::RECORD_FIELD) | 101 | self.to_def(src, keys::RECORD_FIELD) |
102 | } | 102 | } |
103 | pub(super) fn tuple_field_to_def( | 103 | pub(super) fn tuple_field_to_def( |
104 | &mut self, | 104 | &mut self, |
105 | src: InFile<ast::TupleFieldDef>, | 105 | src: InFile<ast::TupleFieldDef>, |
106 | ) -> Option<StructFieldId> { | 106 | ) -> Option<FieldId> { |
107 | self.to_def(src, keys::TUPLE_FIELD) | 107 | self.to_def(src, keys::TUPLE_FIELD) |
108 | } | 108 | } |
109 | pub(super) fn enum_variant_to_def( | 109 | pub(super) fn enum_variant_to_def( |
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()) |