diff options
author | Paul Daniel Faria <[email protected]> | 2020-06-28 21:04:00 +0100 |
---|---|---|
committer | Paul Daniel Faria <[email protected]> | 2020-08-10 13:44:54 +0100 |
commit | c5cc24cb312c70159e63315ea49769b575e8cb65 (patch) | |
tree | fc2f5fe712e5776e0356c8e4f09135692a5ccc20 | |
parent | aca3d6c57ec2c668cdb51eca34d6f7bc8fa7412b (diff) |
Revert function structs back to using bool to track self param, use first param for self information in syntax highlighting instead
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_dot.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_trait_impl.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 11 |
10 files changed, 22 insertions, 27 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index a880fa671..0007d7fa8 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -11,7 +11,6 @@ use hir_def::{ | |||
11 | docs::Documentation, | 11 | docs::Documentation, |
12 | expr::{BindingAnnotation, Pat, PatId}, | 12 | expr::{BindingAnnotation, Pat, PatId}, |
13 | import_map, | 13 | import_map, |
14 | item_tree::SelfParam, | ||
15 | per_ns::PerNs, | 14 | per_ns::PerNs, |
16 | resolver::{HasResolver, Resolver}, | 15 | resolver::{HasResolver, Resolver}, |
17 | src::HasSource as _, | 16 | src::HasSource as _, |
@@ -671,8 +670,8 @@ impl Function { | |||
671 | db.function_data(self.id).name.clone() | 670 | db.function_data(self.id).name.clone() |
672 | } | 671 | } |
673 | 672 | ||
674 | pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> { | 673 | pub fn has_self_param(self, db: &dyn HirDatabase) -> bool { |
675 | db.function_data(self.id).self_param | 674 | db.function_data(self.id).has_self_param |
676 | } | 675 | } |
677 | 676 | ||
678 | pub fn params(self, db: &dyn HirDatabase) -> Vec<TypeRef> { | 677 | pub fn params(self, db: &dyn HirDatabase) -> Vec<TypeRef> { |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 31f3241c9..34b02c536 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -49,7 +49,7 @@ pub use hir_def::{ | |||
49 | docs::Documentation, | 49 | docs::Documentation, |
50 | nameres::ModuleSource, | 50 | nameres::ModuleSource, |
51 | path::{ModPath, Path, PathKind}, | 51 | path::{ModPath, Path, PathKind}, |
52 | type_ref::Mutability, | 52 | type_ref::{Mutability, TypeRef}, |
53 | }; | 53 | }; |
54 | pub use hir_expand::{ | 54 | pub use hir_expand::{ |
55 | hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, | 55 | hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 2a26b0183..88a8ef9bf 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -10,7 +10,7 @@ use crate::{ | |||
10 | attr::Attrs, | 10 | attr::Attrs, |
11 | body::Expander, | 11 | body::Expander, |
12 | db::DefDatabase, | 12 | db::DefDatabase, |
13 | item_tree::{AssocItem, ItemTreeId, ModItem, SelfParam}, | 13 | item_tree::{AssocItem, ItemTreeId, ModItem}, |
14 | type_ref::{TypeBound, TypeRef}, | 14 | type_ref::{TypeBound, TypeRef}, |
15 | visibility::RawVisibility, | 15 | visibility::RawVisibility, |
16 | AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId, | 16 | AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId, |
@@ -25,7 +25,7 @@ pub struct FunctionData { | |||
25 | pub attrs: Attrs, | 25 | pub attrs: Attrs, |
26 | /// True if the first param is `self`. This is relevant to decide whether this | 26 | /// True if the first param is `self`. This is relevant to decide whether this |
27 | /// can be called as a method. | 27 | /// can be called as a method. |
28 | pub self_param: Option<SelfParam>, | 28 | pub has_self_param: bool, |
29 | pub is_unsafe: bool, | 29 | pub is_unsafe: bool, |
30 | pub is_varargs: bool, | 30 | pub is_varargs: bool, |
31 | pub visibility: RawVisibility, | 31 | pub visibility: RawVisibility, |
@@ -42,7 +42,7 @@ impl FunctionData { | |||
42 | params: func.params.to_vec(), | 42 | params: func.params.to_vec(), |
43 | ret_type: func.ret_type.clone(), | 43 | ret_type: func.ret_type.clone(), |
44 | attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), | 44 | attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), |
45 | self_param: func.self_param, | 45 | has_self_param: func.has_self_param, |
46 | is_unsafe: func.is_unsafe, | 46 | is_unsafe: func.is_unsafe, |
47 | is_varargs: func.is_varargs, | 47 | is_varargs: func.is_varargs, |
48 | visibility: item_tree[func.visibility].clone(), | 48 | visibility: item_tree[func.visibility].clone(), |
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 1eaea66e4..a67e75dac 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs | |||
@@ -500,7 +500,7 @@ pub struct Function { | |||
500 | pub name: Name, | 500 | pub name: Name, |
501 | pub visibility: RawVisibilityId, | 501 | pub visibility: RawVisibilityId, |
502 | pub generic_params: GenericParamsId, | 502 | pub generic_params: GenericParamsId, |
503 | pub self_param: Option<SelfParam>, | 503 | pub has_self_param: bool, |
504 | pub is_unsafe: bool, | 504 | pub is_unsafe: bool, |
505 | pub params: Box<[TypeRef]>, | 505 | pub params: Box<[TypeRef]>, |
506 | pub is_varargs: bool, | 506 | pub is_varargs: bool, |
@@ -508,12 +508,6 @@ pub struct Function { | |||
508 | pub ast_id: FileAstId<ast::Fn>, | 508 | pub ast_id: FileAstId<ast::Fn>, |
509 | } | 509 | } |
510 | 510 | ||
511 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
512 | pub struct SelfParam { | ||
513 | pub is_ref: bool, | ||
514 | pub is_mut: bool, | ||
515 | } | ||
516 | |||
517 | #[derive(Debug, Clone, Eq, PartialEq)] | 511 | #[derive(Debug, Clone, Eq, PartialEq)] |
518 | pub struct Struct { | 512 | pub struct Struct { |
519 | pub name: Name, | 513 | pub name: Name, |
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index 89ad91d37..450ef8798 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs | |||
@@ -283,7 +283,7 @@ impl Ctx { | |||
283 | let name = func.name()?.as_name(); | 283 | let name = func.name()?.as_name(); |
284 | 284 | ||
285 | let mut params = Vec::new(); | 285 | let mut params = Vec::new(); |
286 | let mut func_self_param = None; | 286 | let mut has_self_param = false; |
287 | if let Some(param_list) = func.param_list() { | 287 | if let Some(param_list) = func.param_list() { |
288 | if let Some(self_param) = param_list.self_param() { | 288 | if let Some(self_param) = param_list.self_param() { |
289 | let self_type = match self_param.ty() { | 289 | let self_type = match self_param.ty() { |
@@ -302,10 +302,7 @@ impl Ctx { | |||
302 | } | 302 | } |
303 | }; | 303 | }; |
304 | params.push(self_type); | 304 | params.push(self_type); |
305 | func_self_param = Some(SelfParam { | 305 | has_self_param = true; |
306 | is_ref: self_param.amp_token().is_some(), | ||
307 | is_mut: self_param.mut_token().is_some(), | ||
308 | }); | ||
309 | } | 306 | } |
310 | for param in param_list.params() { | 307 | for param in param_list.params() { |
311 | let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); | 308 | let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); |
@@ -338,7 +335,7 @@ impl Ctx { | |||
338 | name, | 335 | name, |
339 | visibility, | 336 | visibility, |
340 | generic_params: GenericParamsId::EMPTY, | 337 | generic_params: GenericParamsId::EMPTY, |
341 | self_param: func_self_param, | 338 | has_self_param, |
342 | is_unsafe: func.unsafe_token().is_some(), | 339 | is_unsafe: func.unsafe_token().is_some(), |
343 | params: params.into_boxed_slice(), | 340 | params: params.into_boxed_slice(), |
344 | is_varargs, | 341 | is_varargs, |
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 79c5adf0f..fb4b30a13 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -640,7 +640,7 @@ fn is_valid_candidate( | |||
640 | } | 640 | } |
641 | } | 641 | } |
642 | if let Some(receiver_ty) = receiver_ty { | 642 | if let Some(receiver_ty) = receiver_ty { |
643 | if data.self_param.is_none() { | 643 | if !data.has_self_param { |
644 | return false; | 644 | return false; |
645 | } | 645 | } |
646 | let transformed_receiver_ty = match transform_receiver_ty(db, m, self_ty) { | 646 | let transformed_receiver_ty = match transform_receiver_ty(db, m, self_ty) { |
diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs index 5488db43f..532665285 100644 --- a/crates/ra_ide/src/completion/complete_dot.rs +++ b/crates/ra_ide/src/completion/complete_dot.rs | |||
@@ -48,7 +48,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &T | |||
48 | let mut seen_methods = FxHashSet::default(); | 48 | let mut seen_methods = FxHashSet::default(); |
49 | let traits_in_scope = ctx.scope.traits_in_scope(); | 49 | let traits_in_scope = ctx.scope.traits_in_scope(); |
50 | receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| { | 50 | receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| { |
51 | if func.self_param(ctx.db).is_some() | 51 | if func.has_self_param(ctx.db) |
52 | && ctx.scope.module().map_or(true, |m| func.is_visible_from(ctx.db, m)) | 52 | && ctx.scope.module().map_or(true, |m| func.is_visible_from(ctx.db, m)) |
53 | && seen_methods.insert(func.name(ctx.db)) | 53 | && seen_methods.insert(func.name(ctx.db)) |
54 | { | 54 | { |
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index e3ba7ebc4..d9a0ef167 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs | |||
@@ -136,7 +136,7 @@ fn add_function_impl( | |||
136 | .lookup_by(fn_name) | 136 | .lookup_by(fn_name) |
137 | .set_documentation(func.docs(ctx.db)); | 137 | .set_documentation(func.docs(ctx.db)); |
138 | 138 | ||
139 | let completion_kind = if func.self_param(ctx.db).is_some() { | 139 | let completion_kind = if func.has_self_param(ctx.db) { |
140 | CompletionItemKind::Method | 140 | CompletionItemKind::Method |
141 | } else { | 141 | } else { |
142 | CompletionItemKind::Function | 142 | CompletionItemKind::Function |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index fc3d1a4bd..9a94ff476 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -191,7 +191,7 @@ impl Completions { | |||
191 | func: hir::Function, | 191 | func: hir::Function, |
192 | local_name: Option<String>, | 192 | local_name: Option<String>, |
193 | ) { | 193 | ) { |
194 | let has_self_param = func.self_param(ctx.db).is_some(); | 194 | let has_self_param = func.has_self_param(ctx.db); |
195 | 195 | ||
196 | let name = local_name.unwrap_or_else(|| func.name(ctx.db).to_string()); | 196 | let name = local_name.unwrap_or_else(|| func.name(ctx.db).to_string()); |
197 | let ast_node = func.source(ctx.db).value; | 197 | let ast_node = func.source(ctx.db).value; |
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 02b16b13c..d5a5f69cc 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -4,7 +4,7 @@ mod injection; | |||
4 | #[cfg(test)] | 4 | #[cfg(test)] |
5 | mod tests; | 5 | mod tests; |
6 | 6 | ||
7 | use hir::{Name, Semantics, VariantDef}; | 7 | use hir::{Name, Semantics, TypeRef, VariantDef}; |
8 | use ra_ide_db::{ | 8 | use ra_ide_db::{ |
9 | defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, | 9 | defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, |
10 | RootDatabase, | 10 | RootDatabase, |
@@ -756,8 +756,13 @@ fn is_method_call_unsafe( | |||
756 | } | 756 | } |
757 | 757 | ||
758 | let func = sema.resolve_method_call(&method_call_expr)?; | 758 | let func = sema.resolve_method_call(&method_call_expr)?; |
759 | if func.self_param(sema.db)?.is_ref { | 759 | if func.has_self_param(sema.db) { |
760 | Some(()) | 760 | let params = func.params(sema.db); |
761 | if matches!(params.into_iter().next(), Some(TypeRef::Reference(..))) { | ||
762 | Some(()) | ||
763 | } else { | ||
764 | None | ||
765 | } | ||
761 | } else { | 766 | } else { |
762 | None | 767 | None |
763 | } | 768 | } |