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 <jonas.schievink@ferrous-systems.com>
This commit is contained in:
bors[bot] 2022-03-18 19:30:52 +00:00 committed by GitHub
commit 85311a8627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 27 deletions

View File

@ -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<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.

View File

@ -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<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 @@ 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<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 @@ 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 {

View File

@ -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))
}

View File

@ -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 {