aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/call_info.rs30
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs7
-rw-r--r--crates/ra_ide/src/completion/presentation.rs5
-rw-r--r--crates/ra_ide/src/lib.rs15
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs8
5 files changed, 35 insertions, 30 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index f95b6baf3..5da254a6e 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -19,10 +19,24 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
19 call_info_for_token(&sema, token) 19 call_info_for_token(&sema, token)
20} 20}
21 21
22pub(crate) fn call_info_for_token( 22#[derive(Debug)]
23 sema: &Semantics<RootDatabase>, 23pub(crate) struct ActiveParameter {
24 token: SyntaxToken, 24 /// FIXME: should be `Type` and `Name
25) -> Option<CallInfo> { 25 pub(crate) ty: String,
26 pub(crate) name: String,
27}
28
29impl ActiveParameter {
30 pub(crate) fn at(db: &RootDatabase, position: FilePosition) -> Option<Self> {
31 call_info(db, position)?.into_active_parameter()
32 }
33
34 pub(crate) fn at_token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Option<Self> {
35 call_info_for_token(sema, token)?.into_active_parameter()
36 }
37}
38
39fn call_info_for_token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Option<CallInfo> {
26 // Find the calling expression and it's NameRef 40 // Find the calling expression and it's NameRef
27 let calling_node = FnCallNode::with_node(&token.parent())?; 41 let calling_node = FnCallNode::with_node(&token.parent())?;
28 42
@@ -160,6 +174,14 @@ impl FnCallNode {
160} 174}
161 175
162impl CallInfo { 176impl CallInfo {
177 fn into_active_parameter(self) -> Option<ActiveParameter> {
178 let idx = self.active_parameter?;
179 let ty = self.signature.parameter_types.get(idx)?.clone();
180 let name = self.signature.parameter_names.get(idx)?.clone();
181 let res = ActiveParameter { ty, name };
182 Some(res)
183 }
184
163 fn with_fn(db: &RootDatabase, function: hir::Function) -> Self { 185 fn with_fn(db: &RootDatabase, function: hir::Function) -> Self {
164 let signature = FunctionSignature::from_hir(db, function); 186 let signature = FunctionSignature::from_hir(db, function);
165 187
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index dd7c8a873..a76d1ce45 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -11,7 +11,7 @@ use ra_syntax::{
11}; 11};
12use ra_text_edit::AtomTextEdit; 12use ra_text_edit::AtomTextEdit;
13 13
14use crate::{completion::CompletionConfig, FilePosition}; 14use crate::{call_info::ActiveParameter, completion::CompletionConfig, FilePosition};
15 15
16/// `CompletionContext` is created early during completion to figure out, where 16/// `CompletionContext` is created early during completion to figure out, where
17/// exactly is the cursor, syntax-wise. 17/// exactly is the cursor, syntax-wise.
@@ -21,7 +21,6 @@ pub(crate) struct CompletionContext<'a> {
21 pub(super) db: &'a RootDatabase, 21 pub(super) db: &'a RootDatabase,
22 pub(super) config: &'a CompletionConfig, 22 pub(super) config: &'a CompletionConfig,
23 pub(super) offset: TextUnit, 23 pub(super) offset: TextUnit,
24 pub(super) file_position: FilePosition,
25 /// The token before the cursor, in the original file. 24 /// The token before the cursor, in the original file.
26 pub(super) original_token: SyntaxToken, 25 pub(super) original_token: SyntaxToken,
27 /// The token before the cursor, in the macro-expanded file. 26 /// The token before the cursor, in the macro-expanded file.
@@ -34,6 +33,8 @@ pub(crate) struct CompletionContext<'a> {
34 pub(super) record_pat_syntax: Option<ast::RecordPat>, 33 pub(super) record_pat_syntax: Option<ast::RecordPat>,
35 pub(super) record_field_syntax: Option<ast::RecordField>, 34 pub(super) record_field_syntax: Option<ast::RecordField>,
36 pub(super) impl_def: Option<ast::ImplDef>, 35 pub(super) impl_def: Option<ast::ImplDef>,
36 /// FIXME: `ActiveParameter` is string-based, which is very wrong
37 pub(super) active_parameter: Option<ActiveParameter>,
37 pub(super) is_param: bool, 38 pub(super) is_param: bool,
38 /// If a name-binding or reference to a const in a pattern. 39 /// If a name-binding or reference to a const in a pattern.
39 /// Irrefutable patterns (like let) are excluded. 40 /// Irrefutable patterns (like let) are excluded.
@@ -90,7 +91,6 @@ impl<'a> CompletionContext<'a> {
90 original_token, 91 original_token,
91 token, 92 token,
92 offset: position.offset, 93 offset: position.offset,
93 file_position: position,
94 krate, 94 krate,
95 name_ref_syntax: None, 95 name_ref_syntax: None,
96 function_syntax: None, 96 function_syntax: None,
@@ -99,6 +99,7 @@ impl<'a> CompletionContext<'a> {
99 record_pat_syntax: None, 99 record_pat_syntax: None,
100 record_field_syntax: None, 100 record_field_syntax: None,
101 impl_def: None, 101 impl_def: None,
102 active_parameter: ActiveParameter::at(db, position),
102 is_param: false, 103 is_param: false,
103 is_pat_binding_or_const: false, 104 is_pat_binding_or_const: false,
104 is_trivial_path: false, 105 is_trivial_path: false,
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index ae15f91de..6c0e32408 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -6,7 +6,6 @@ use stdx::SepBy;
6use test_utils::tested_by; 6use test_utils::tested_by;
7 7
8use crate::{ 8use crate::{
9 call_info::call_info,
10 completion::{ 9 completion::{
11 completion_item::Builder, CompletionContext, CompletionItem, CompletionItemKind, 10 completion_item::Builder, CompletionContext, CompletionItem, CompletionItemKind,
12 CompletionKind, Completions, 11 CompletionKind, Completions,
@@ -317,8 +316,8 @@ pub(crate) fn compute_score(
317 struct_field.name(ctx.db).to_string(), 316 struct_field.name(ctx.db).to_string(),
318 struct_field.signature_ty(ctx.db).display(ctx.db).to_string(), 317 struct_field.signature_ty(ctx.db).display(ctx.db).to_string(),
319 ) 318 )
320 } else if let Some(call_info) = call_info(ctx.db, ctx.file_position) { 319 } else if let Some(active_parameter) = &ctx.active_parameter {
321 (call_info.active_parameter_name()?, call_info.active_parameter_type()?) 320 (active_parameter.name.clone(), active_parameter.ty.clone())
322 } else { 321 } else {
323 return None; 322 return None;
324 }; 323 };
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index ddaa30a16..f692fbaa2 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -129,21 +129,6 @@ pub struct CallInfo {
129 pub active_parameter: Option<usize>, 129 pub active_parameter: Option<usize>,
130} 130}
131 131
132impl CallInfo {
133 pub fn active_parameter_type(&self) -> Option<String> {
134 if let Some(id) = self.active_parameter {
135 return self.signature.parameter_types.get(id).map(|param_ty| param_ty.clone());
136 }
137 None
138 }
139 pub fn active_parameter_name(&self) -> Option<String> {
140 if let Some(id) = self.active_parameter {
141 return self.signature.parameter_names.get(id).map(|param_ty| param_ty.clone());
142 }
143 None
144 }
145}
146
147/// `AnalysisHost` stores the current state of the world. 132/// `AnalysisHost` stores the current state of the world.
148#[derive(Debug)] 133#[derive(Debug)]
149pub struct AnalysisHost { 134pub struct AnalysisHost {
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 93d502875..d9912155b 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -19,7 +19,7 @@ use ra_syntax::{
19}; 19};
20use rustc_hash::FxHashMap; 20use rustc_hash::FxHashMap;
21 21
22use crate::{call_info::call_info_for_token, Analysis, FileId}; 22use crate::{call_info::ActiveParameter, Analysis, FileId};
23 23
24pub(crate) use html::highlight_as_html; 24pub(crate) use html::highlight_as_html;
25pub use tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag}; 25pub use tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag};
@@ -364,10 +364,8 @@ fn highlight_injection(
364 literal: ast::RawString, 364 literal: ast::RawString,
365 expanded: SyntaxToken, 365 expanded: SyntaxToken,
366) -> Option<()> { 366) -> Option<()> {
367 let call_info = call_info_for_token(&sema, expanded)?; 367 let active_parameter = ActiveParameter::at_token(&sema, expanded)?;
368 let idx = call_info.active_parameter?; 368 if !active_parameter.name.starts_with("ra_fixture") {
369 let name = call_info.signature.parameter_names.get(idx)?;
370 if !name.starts_with("ra_fixture") {
371 return None; 369 return None;
372 } 370 }
373 let value = literal.value()?; 371 let value = literal.value()?;