diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 20a5886c892..3e411e236b7 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -24,7 +24,7 @@ macro_rules! eprintln { mod annotations; mod call_hierarchy; -mod call_info; +mod signature_help; mod doc_links; mod highlight_related; mod expand_macro; @@ -75,7 +75,6 @@ macro_rules! eprintln { pub use crate::{ annotations::{Annotation, AnnotationConfig, AnnotationKind}, call_hierarchy::CallItem, - call_info::CallInfo, expand_macro::ExpandedMacro, file_structure::{StructureNode, StructureNodeKind}, folding_ranges::{Fold, FoldKind}, @@ -91,6 +90,7 @@ macro_rules! eprintln { references::ReferenceSearchResult, rename::RenameError, runnables::{Runnable, RunnableKind, TestId}, + signature_help::SignatureHelp, static_index::{StaticIndex, StaticIndexedFile, TokenId, TokenStaticData}, syntax_highlighting::{ tags::{Highlight, HlMod, HlMods, HlOperator, HlPunct, HlTag}, @@ -450,9 +450,9 @@ pub fn external_docs( self.with_db(|db| doc_links::external_docs(db, &position)) } - /// Computes parameter information for the given call expression. - pub fn call_info(&self, position: FilePosition) -> Cancellable> { - self.with_db(|db| call_info::call_info(db, position)) + /// Computes parameter information at the given position. + pub fn signature_help(&self, position: FilePosition) -> Cancellable> { + self.with_db(|db| signature_help::signature_help(db, position)) } /// Computes call hierarchy candidates for the given file position. diff --git a/crates/ide/src/call_info.rs b/crates/ide/src/signature_help.rs similarity index 95% rename from crates/ide/src/call_info.rs rename to crates/ide/src/signature_help.rs index ad831f0f949..e13abe2d876 100644 --- a/crates/ide/src/call_info.rs +++ b/crates/ide/src/signature_help.rs @@ -1,4 +1,5 @@ -//! This module provides primitives for tracking the information about a call site. +//! This module provides primitives for showing type and function parameter information when editing +//! a call or use-site. use either::Either; use hir::{HasAttrs, HirDisplay, Semantics}; @@ -11,17 +12,19 @@ use crate::RootDatabase; -/// Contains information about a call site. Specifically the -/// `FunctionSignature`and current parameter. +/// Contains information about an item signature as seen from a use site. +/// +/// This includes the "active parameter", which is the parameter whose value is currently being +/// edited. #[derive(Debug)] -pub struct CallInfo { +pub struct SignatureHelp { pub doc: Option, pub signature: String, pub active_parameter: Option, parameters: Vec, } -impl CallInfo { +impl SignatureHelp { pub fn parameter_labels(&self) -> impl Iterator + '_ { self.parameters.iter().map(move |&it| &self.signature[it]) } @@ -49,8 +52,8 @@ fn push_param(&mut self, opening_delim: char, param: &str) { } } -/// Computes parameter information for the given call expression. -pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option { +/// Computes parameter information for the given position. +pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Option { let sema = Semantics::new(db); let file = sema.parse(position.file_id); let file = file.syntax(); @@ -63,23 +66,23 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option, -) -> CallInfo { +) -> SignatureHelp { let mut res = - CallInfo { doc: None, signature: String::new(), parameters: vec![], active_parameter }; + SignatureHelp { doc: None, signature: String::new(), parameters: vec![], active_parameter }; match callable.kind() { hir::CallableKind::Function(func) => { @@ -134,12 +137,12 @@ fn call_info_for_callable( res } -fn call_info_for_generics( +fn signature_help_for_generics( db: &RootDatabase, mut generics_def: hir::GenericDef, active_parameter: usize, -) -> Option { - let mut res = CallInfo { +) -> Option { + let mut res = SignatureHelp { doc: None, signature: String::new(), parameters: vec![], @@ -230,7 +233,7 @@ fn check(ra_fixture: &str, expect: Expect) { "# ); let (db, position) = position(&fixture); - let call_info = crate::call_info::call_info(&db, position); + let call_info = crate::signature_help::signature_help(&db, position); let actual = match call_info { Some(call_info) => { let docs = match &call_info.doc { diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index e63b6f490ba..8f91f64a69a 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -895,13 +895,12 @@ pub(crate) fn handle_signature_help( ) -> Result> { let _p = profile::span("handle_signature_help"); let position = from_proto::file_position(&snap, params.text_document_position_params)?; - let call_info = match snap.analysis.call_info(position)? { + let help = match snap.analysis.signature_help(position)? { Some(it) => it, None => return Ok(None), }; let concise = !snap.config.call_info_full(); - let res = - to_proto::signature_help(call_info, concise, snap.config.signature_help_label_offsets()); + let res = to_proto::signature_help(help, concise, snap.config.signature_help_label_offsets()); Ok(Some(res)) } diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index e9e8bdb6c5f..7ea0eae053c 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -6,11 +6,11 @@ }; use ide::{ - Annotation, AnnotationKind, Assist, AssistKind, CallInfo, Cancellable, CompletionItem, + Annotation, AnnotationKind, Assist, AssistKind, Cancellable, CompletionItem, CompletionItemKind, CompletionRelevance, Documentation, FileId, FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlOperator, HlPunct, HlRange, HlTag, Indel, InlayHint, InlayKind, Markup, NavigationTarget, ReferenceCategory, RenameError, Runnable, Severity, - SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize, + SignatureHelp, SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize, }; use itertools::Itertools; use serde_json::to_value; @@ -336,7 +336,7 @@ fn set_score( } pub(crate) fn signature_help( - call_info: CallInfo, + call_info: SignatureHelp, concise: bool, label_offsets: bool, ) -> lsp_types::SignatureHelp {