aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-19 14:17:05 +0100
committerGitHub <[email protected]>2020-08-19 14:17:05 +0100
commite8d266fa6dd7ee883d1bba52eb6a37c5e473978f (patch)
tree5ef5dceeeafb7105f41b6fe12bb1563f424f2e87 /crates/ide
parent422856d70f934b49f5b35043f3b51b6da08a61fa (diff)
parentb9b4693ce3bf0229ea40f09e6404fad3e7823321 (diff)
Merge #5814
5814: Add SelfParam to code_model r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/completion/complete_dot.rs2
-rw-r--r--crates/ide/src/completion/complete_trait_impl.rs2
-rw-r--r--crates/ide/src/completion/presentation.rs4
-rw-r--r--crates/ide/src/syntax_highlighting.rs20
4 files changed, 11 insertions, 17 deletions
diff --git a/crates/ide/src/completion/complete_dot.rs b/crates/ide/src/completion/complete_dot.rs
index 532665285..5488db43f 100644
--- a/crates/ide/src/completion/complete_dot.rs
+++ b/crates/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.has_self_param(ctx.db) 51 if func.self_param(ctx.db).is_some()
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/ide/src/completion/complete_trait_impl.rs b/crates/ide/src/completion/complete_trait_impl.rs
index d69b6b468..d0d3a9f34 100644
--- a/crates/ide/src/completion/complete_trait_impl.rs
+++ b/crates/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.has_self_param(ctx.db) { 139 let completion_kind = if func.self_param(ctx.db).is_some() {
140 CompletionItemKind::Method 140 CompletionItemKind::Method
141 } else { 141 } else {
142 CompletionItemKind::Function 142 CompletionItemKind::Function
diff --git a/crates/ide/src/completion/presentation.rs b/crates/ide/src/completion/presentation.rs
index e1b1ea4ce..a73f8ab0b 100644
--- a/crates/ide/src/completion/presentation.rs
+++ b/crates/ide/src/completion/presentation.rs
@@ -191,14 +191,12 @@ 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.has_self_param(ctx.db);
195
196 let name = local_name.unwrap_or_else(|| func.name(ctx.db).to_string()); 194 let name = local_name.unwrap_or_else(|| func.name(ctx.db).to_string());
197 let ast_node = func.source(ctx.db).value; 195 let ast_node = func.source(ctx.db).value;
198 196
199 let mut builder = 197 let mut builder =
200 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) 198 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone())
201 .kind(if has_self_param { 199 .kind(if func.self_param(ctx.db).is_some() {
202 CompletionItemKind::Method 200 CompletionItemKind::Method
203 } else { 201 } else {
204 CompletionItemKind::Function 202 CompletionItemKind::Function
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 9827c68af..fc4f56550 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -4,7 +4,7 @@ mod injection;
4#[cfg(test)] 4#[cfg(test)]
5mod tests; 5mod tests;
6 6
7use hir::{Mutability, Name, SelfKind, Semantics, VariantDef}; 7use hir::{Name, SelfKind, Semantics, VariantDef};
8use ide_db::{ 8use 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,
@@ -761,17 +761,13 @@ fn highlight_name(
761 h |= HighlightModifier::Unsafe; 761 h |= HighlightModifier::Unsafe;
762 } 762 }
763 763
764 return if func.has_self_param(db) { 764 match func.self_param(db) {
765 match func.mutability_of_self_param(db) { 765 None => h,
766 Some(mutability) => match mutability { 766 Some(self_param) => match self_param.access(db) {
767 Mutability::Mut => h | HighlightModifier::Mutable, 767 hir::Access::Exclusive => h | HighlightModifier::Mutable,
768 Mutability::Shared => h, 768 hir::Access::Shared | hir::Access::Owned => h,
769 }, 769 },
770 None => h, 770 }
771 }
772 } else {
773 h
774 };
775 }); 771 });
776 } 772 }
777 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, 773 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct,