Unnamed repository; edit this file 'description' to name the repository.
Merge #11761
11761: internal: Rename call info to "signature help" r=jonas-schievink a=jonas-schievink It is no longer limited to just calls bors r+ Co-authored-by: Jonas Schievink <[email protected]>
bors[bot] 2022-03-19
parent 8c16b07 · parent 55d2a25 · commit 85311a8
-rw-r--r--crates/ide/src/lib.rs10
-rw-r--r--crates/ide/src/signature_help.rs (renamed from crates/ide/src/call_info.rs)35
-rw-r--r--crates/rust-analyzer/src/handlers.rs5
-rw-r--r--crates/rust-analyzer/src/to_proto.rs6
4 files changed, 29 insertions, 27 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 20a5886c89..3e411e236b 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -24,7 +24,7 @@ mod navigation_target;
mod annotations;
mod call_hierarchy;
-mod call_info;
+mod signature_help;
mod doc_links;
mod highlight_related;
mod expand_macro;
@@ -75,7 +75,6 @@ use crate::navigation_target::{ToNav, TryToNav};
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 @@ pub use crate::{
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 @@ impl Analysis {
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<Option<CallInfo>> {
- 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<Option<SignatureHelp>> {
+ 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
index ad831f0f94..e13abe2d87 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 syntax::{algo, AstNode, Direction, TextRange, TextSize};
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<String>,
pub signature: String,
pub active_parameter: Option<usize>,
parameters: Vec<TextRange>,
}
-impl CallInfo {
+impl SignatureHelp {
pub fn parameter_labels(&self) -> impl Iterator<Item = &str> + '_ {
self.parameters.iter().map(move |&it| &self.signature[it])
}
@@ -49,8 +52,8 @@ impl CallInfo {
}
}
-/// Computes parameter information for the given call expression.
-pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> {
+/// Computes parameter information for the given position.
+pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Option<SignatureHelp> {
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<Cal
let token = sema.descend_into_macros_single(token);
if let Some((callable, active_parameter)) = callable_for_token(&sema, token.clone()) {
- return Some(call_info_for_callable(db, callable, active_parameter));
+ return Some(signature_help_for_callable(db, callable, active_parameter));
}
if let Some((generic_def, active_parameter)) = generics_for_token(&sema, token.clone()) {
- return call_info_for_generics(db, generic_def, active_parameter);
+ return signature_help_for_generics(db, generic_def, active_parameter);
}
None
}
-fn call_info_for_callable(
+fn signature_help_for_callable(
db: &RootDatabase,
callable: hir::Callable,
active_parameter: Option<usize>,
-) -> 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<CallInfo> {
- let mut res = CallInfo {
+) -> Option<SignatureHelp> {
+ let mut res = SignatureHelp {
doc: None,
signature: String::new(),
parameters: vec![],
@@ -230,7 +233,7 @@ mod tests {
"#
);
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 e63b6f490b..8f91f64a69 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<Option<lsp_types::SignatureHelp>> {
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 e9e8bdb6c5..7ea0eae053 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -6,11 +6,11 @@ use std::{
};
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 completion_item(
}
pub(crate) fn signature_help(
- call_info: CallInfo,
+ call_info: SignatureHelp,
concise: bool,
label_offsets: bool,
) -> lsp_types::SignatureHelp {