mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
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 <jonas.schievink@ferrous-systems.com>
This commit is contained in:
commit
85311a8627
@ -24,7 +24,7 @@ mod navigation_target;
|
|||||||
|
|
||||||
mod annotations;
|
mod annotations;
|
||||||
mod call_hierarchy;
|
mod call_hierarchy;
|
||||||
mod call_info;
|
mod signature_help;
|
||||||
mod doc_links;
|
mod doc_links;
|
||||||
mod highlight_related;
|
mod highlight_related;
|
||||||
mod expand_macro;
|
mod expand_macro;
|
||||||
@ -75,7 +75,6 @@ use crate::navigation_target::{ToNav, TryToNav};
|
|||||||
pub use crate::{
|
pub use crate::{
|
||||||
annotations::{Annotation, AnnotationConfig, AnnotationKind},
|
annotations::{Annotation, AnnotationConfig, AnnotationKind},
|
||||||
call_hierarchy::CallItem,
|
call_hierarchy::CallItem,
|
||||||
call_info::CallInfo,
|
|
||||||
expand_macro::ExpandedMacro,
|
expand_macro::ExpandedMacro,
|
||||||
file_structure::{StructureNode, StructureNodeKind},
|
file_structure::{StructureNode, StructureNodeKind},
|
||||||
folding_ranges::{Fold, FoldKind},
|
folding_ranges::{Fold, FoldKind},
|
||||||
@ -91,6 +90,7 @@ pub use crate::{
|
|||||||
references::ReferenceSearchResult,
|
references::ReferenceSearchResult,
|
||||||
rename::RenameError,
|
rename::RenameError,
|
||||||
runnables::{Runnable, RunnableKind, TestId},
|
runnables::{Runnable, RunnableKind, TestId},
|
||||||
|
signature_help::SignatureHelp,
|
||||||
static_index::{StaticIndex, StaticIndexedFile, TokenId, TokenStaticData},
|
static_index::{StaticIndex, StaticIndexedFile, TokenId, TokenStaticData},
|
||||||
syntax_highlighting::{
|
syntax_highlighting::{
|
||||||
tags::{Highlight, HlMod, HlMods, HlOperator, HlPunct, HlTag},
|
tags::{Highlight, HlMod, HlMods, HlOperator, HlPunct, HlTag},
|
||||||
@ -450,9 +450,9 @@ impl Analysis {
|
|||||||
self.with_db(|db| doc_links::external_docs(db, &position))
|
self.with_db(|db| doc_links::external_docs(db, &position))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes parameter information for the given call expression.
|
/// Computes parameter information at the given position.
|
||||||
pub fn call_info(&self, position: FilePosition) -> Cancellable<Option<CallInfo>> {
|
pub fn signature_help(&self, position: FilePosition) -> Cancellable<Option<SignatureHelp>> {
|
||||||
self.with_db(|db| call_info::call_info(db, position))
|
self.with_db(|db| signature_help::signature_help(db, position))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes call hierarchy candidates for the given file position.
|
/// Computes call hierarchy candidates for the given file position.
|
||||||
|
@ -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 either::Either;
|
||||||
use hir::{HasAttrs, HirDisplay, Semantics};
|
use hir::{HasAttrs, HirDisplay, Semantics};
|
||||||
@ -11,17 +12,19 @@ use syntax::{algo, AstNode, Direction, TextRange, TextSize};
|
|||||||
|
|
||||||
use crate::RootDatabase;
|
use crate::RootDatabase;
|
||||||
|
|
||||||
/// Contains information about a call site. Specifically the
|
/// Contains information about an item signature as seen from a use site.
|
||||||
/// `FunctionSignature`and current parameter.
|
///
|
||||||
|
/// This includes the "active parameter", which is the parameter whose value is currently being
|
||||||
|
/// edited.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CallInfo {
|
pub struct SignatureHelp {
|
||||||
pub doc: Option<String>,
|
pub doc: Option<String>,
|
||||||
pub signature: String,
|
pub signature: String,
|
||||||
pub active_parameter: Option<usize>,
|
pub active_parameter: Option<usize>,
|
||||||
parameters: Vec<TextRange>,
|
parameters: Vec<TextRange>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallInfo {
|
impl SignatureHelp {
|
||||||
pub fn parameter_labels(&self) -> impl Iterator<Item = &str> + '_ {
|
pub fn parameter_labels(&self) -> impl Iterator<Item = &str> + '_ {
|
||||||
self.parameters.iter().map(move |&it| &self.signature[it])
|
self.parameters.iter().map(move |&it| &self.signature[it])
|
||||||
}
|
}
|
||||||
@ -49,8 +52,8 @@ impl CallInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes parameter information for the given call expression.
|
/// Computes parameter information for the given position.
|
||||||
pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> {
|
pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Option<SignatureHelp> {
|
||||||
let sema = Semantics::new(db);
|
let sema = Semantics::new(db);
|
||||||
let file = sema.parse(position.file_id);
|
let file = sema.parse(position.file_id);
|
||||||
let file = file.syntax();
|
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);
|
let token = sema.descend_into_macros_single(token);
|
||||||
|
|
||||||
if let Some((callable, active_parameter)) = callable_for_token(&sema, token.clone()) {
|
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()) {
|
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
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_info_for_callable(
|
fn signature_help_for_callable(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
callable: hir::Callable,
|
callable: hir::Callable,
|
||||||
active_parameter: Option<usize>,
|
active_parameter: Option<usize>,
|
||||||
) -> CallInfo {
|
) -> SignatureHelp {
|
||||||
let mut res =
|
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() {
|
match callable.kind() {
|
||||||
hir::CallableKind::Function(func) => {
|
hir::CallableKind::Function(func) => {
|
||||||
@ -134,12 +137,12 @@ fn call_info_for_callable(
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_info_for_generics(
|
fn signature_help_for_generics(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
mut generics_def: hir::GenericDef,
|
mut generics_def: hir::GenericDef,
|
||||||
active_parameter: usize,
|
active_parameter: usize,
|
||||||
) -> Option<CallInfo> {
|
) -> Option<SignatureHelp> {
|
||||||
let mut res = CallInfo {
|
let mut res = SignatureHelp {
|
||||||
doc: None,
|
doc: None,
|
||||||
signature: String::new(),
|
signature: String::new(),
|
||||||
parameters: vec![],
|
parameters: vec![],
|
||||||
@ -230,7 +233,7 @@ mod tests {
|
|||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
let (db, position) = position(&fixture);
|
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 {
|
let actual = match call_info {
|
||||||
Some(call_info) => {
|
Some(call_info) => {
|
||||||
let docs = match &call_info.doc {
|
let docs = match &call_info.doc {
|
@ -895,13 +895,12 @@ pub(crate) fn handle_signature_help(
|
|||||||
) -> Result<Option<lsp_types::SignatureHelp>> {
|
) -> Result<Option<lsp_types::SignatureHelp>> {
|
||||||
let _p = profile::span("handle_signature_help");
|
let _p = profile::span("handle_signature_help");
|
||||||
let position = from_proto::file_position(&snap, params.text_document_position_params)?;
|
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,
|
Some(it) => it,
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
};
|
};
|
||||||
let concise = !snap.config.call_info_full();
|
let concise = !snap.config.call_info_full();
|
||||||
let res =
|
let res = to_proto::signature_help(help, concise, snap.config.signature_help_label_offsets());
|
||||||
to_proto::signature_help(call_info, concise, snap.config.signature_help_label_offsets());
|
|
||||||
Ok(Some(res))
|
Ok(Some(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,11 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use ide::{
|
use ide::{
|
||||||
Annotation, AnnotationKind, Assist, AssistKind, CallInfo, Cancellable, CompletionItem,
|
Annotation, AnnotationKind, Assist, AssistKind, Cancellable, CompletionItem,
|
||||||
CompletionItemKind, CompletionRelevance, Documentation, FileId, FileRange, FileSystemEdit,
|
CompletionItemKind, CompletionRelevance, Documentation, FileId, FileRange, FileSystemEdit,
|
||||||
Fold, FoldKind, Highlight, HlMod, HlOperator, HlPunct, HlRange, HlTag, Indel, InlayHint,
|
Fold, FoldKind, Highlight, HlMod, HlOperator, HlPunct, HlRange, HlTag, Indel, InlayHint,
|
||||||
InlayKind, Markup, NavigationTarget, ReferenceCategory, RenameError, Runnable, Severity,
|
InlayKind, Markup, NavigationTarget, ReferenceCategory, RenameError, Runnable, Severity,
|
||||||
SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize,
|
SignatureHelp, SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde_json::to_value;
|
use serde_json::to_value;
|
||||||
@ -336,7 +336,7 @@ fn completion_item(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn signature_help(
|
pub(crate) fn signature_help(
|
||||||
call_info: CallInfo,
|
call_info: SignatureHelp,
|
||||||
concise: bool,
|
concise: bool,
|
||||||
label_offsets: bool,
|
label_offsets: bool,
|
||||||
) -> lsp_types::SignatureHelp {
|
) -> lsp_types::SignatureHelp {
|
||||||
|
Loading…
Reference in New Issue
Block a user