call_info_for_token(&sema, token)
}
-pub(crate) fn call_info_for_token(
- sema: &Semantics<RootDatabase>,
- token: SyntaxToken,
-) -> Option<CallInfo> {
+#[derive(Debug)]
+pub(crate) struct ActiveParameter {
+ /// FIXME: should be `Type` and `Name
+ pub(crate) ty: String,
+ pub(crate) name: String,
+}
+
+impl ActiveParameter {
+ pub(crate) fn at(db: &RootDatabase, position: FilePosition) -> Option<Self> {
+ call_info(db, position)?.into_active_parameter()
+ }
+
+ pub(crate) fn at_token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Option<Self> {
+ call_info_for_token(sema, token)?.into_active_parameter()
+ }
+}
+
+fn call_info_for_token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Option<CallInfo> {
// Find the calling expression and it's NameRef
let calling_node = FnCallNode::with_node(&token.parent())?;
}
impl CallInfo {
+ fn into_active_parameter(self) -> Option<ActiveParameter> {
+ let idx = self.active_parameter?;
+ let ty = self.signature.parameter_types.get(idx)?.clone();
+ let name = self.signature.parameter_names.get(idx)?.clone();
+ let res = ActiveParameter { ty, name };
+ Some(res)
+ }
+
fn with_fn(db: &RootDatabase, function: hir::Function) -> Self {
let signature = FunctionSignature::from_hir(db, function);
};
use ra_text_edit::AtomTextEdit;
-use crate::{completion::CompletionConfig, FilePosition};
+use crate::{call_info::ActiveParameter, completion::CompletionConfig, FilePosition};
/// `CompletionContext` is created early during completion to figure out, where
/// exactly is the cursor, syntax-wise.
pub(super) db: &'a RootDatabase,
pub(super) config: &'a CompletionConfig,
pub(super) offset: TextUnit,
- pub(super) file_position: FilePosition,
/// The token before the cursor, in the original file.
pub(super) original_token: SyntaxToken,
/// The token before the cursor, in the macro-expanded file.
pub(super) record_pat_syntax: Option<ast::RecordPat>,
pub(super) record_field_syntax: Option<ast::RecordField>,
pub(super) impl_def: Option<ast::ImplDef>,
+ /// FIXME: `ActiveParameter` is string-based, which is very wrong
+ pub(super) active_parameter: Option<ActiveParameter>,
pub(super) is_param: bool,
/// If a name-binding or reference to a const in a pattern.
/// Irrefutable patterns (like let) are excluded.
original_token,
token,
offset: position.offset,
- file_position: position,
krate,
name_ref_syntax: None,
function_syntax: None,
record_pat_syntax: None,
record_field_syntax: None,
impl_def: None,
+ active_parameter: ActiveParameter::at(db, position),
is_param: false,
is_pat_binding_or_const: false,
is_trivial_path: false,
use test_utils::tested_by;
use crate::{
- call_info::call_info,
completion::{
completion_item::Builder, CompletionContext, CompletionItem, CompletionItemKind,
CompletionKind, Completions,
struct_field.name(ctx.db).to_string(),
struct_field.signature_ty(ctx.db).display(ctx.db).to_string(),
)
- } else if let Some(call_info) = call_info(ctx.db, ctx.file_position) {
- (call_info.active_parameter_name()?, call_info.active_parameter_type()?)
+ } else if let Some(active_parameter) = &ctx.active_parameter {
+ (active_parameter.name.clone(), active_parameter.ty.clone())
} else {
return None;
};
pub active_parameter: Option<usize>,
}
-impl CallInfo {
- pub fn active_parameter_type(&self) -> Option<String> {
- if let Some(id) = self.active_parameter {
- return self.signature.parameter_types.get(id).map(|param_ty| param_ty.clone());
- }
- None
- }
- pub fn active_parameter_name(&self) -> Option<String> {
- if let Some(id) = self.active_parameter {
- return self.signature.parameter_names.get(id).map(|param_ty| param_ty.clone());
- }
- None
- }
-}
-
/// `AnalysisHost` stores the current state of the world.
#[derive(Debug)]
pub struct AnalysisHost {
};
use rustc_hash::FxHashMap;
-use crate::{call_info::call_info_for_token, Analysis, FileId};
+use crate::{call_info::ActiveParameter, Analysis, FileId};
pub(crate) use html::highlight_as_html;
pub use tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag};
literal: ast::RawString,
expanded: SyntaxToken,
) -> Option<()> {
- let call_info = call_info_for_token(&sema, expanded)?;
- let idx = call_info.active_parameter?;
- let name = call_info.signature.parameter_names.get(idx)?;
- if !name.starts_with("ra_fixture") {
+ let active_parameter = ActiveParameter::at_token(&sema, expanded)?;
+ if !active_parameter.name.starts_with("ra_fixture") {
return None;
}
let value = literal.value()?;