mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 01:38:13 +00:00
Added some documentation to the complete_trait_impl
completion.
This commit is contained in:
parent
3ffc84fd15
commit
52c4324e31
1 changed files with 48 additions and 1 deletions
|
@ -7,6 +7,45 @@ use hir::{self, Docs, HasSource};
|
|||
|
||||
use ra_assists::utils::get_missing_impl_items;
|
||||
|
||||
/// Analyzes the specified `CompletionContext` and provides magic completions
|
||||
/// if the context falls within a `impl Trait for` block.
|
||||
///
|
||||
/// # Completion Activation
|
||||
/// The completion will activate when a user begins to type a function
|
||||
/// definition, an associated type, or an associated constant.
|
||||
///
|
||||
/// ### Functions
|
||||
/// ```ignore
|
||||
/// trait SomeTrait {
|
||||
/// fn foo(&self);
|
||||
/// }
|
||||
///
|
||||
/// impl SomeTrait for () {
|
||||
/// fn <|>
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ### Associated Types
|
||||
/// ```ignore
|
||||
/// trait SomeTrait {
|
||||
/// type SomeType;
|
||||
/// }
|
||||
///
|
||||
/// impl SomeTrait for () {
|
||||
/// type <|>
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ### Associated Constants
|
||||
/// ```ignore
|
||||
/// trait SomeTrait {
|
||||
/// const SOME_CONST: u16;
|
||||
/// }
|
||||
///
|
||||
/// impl SomeTrait for () {
|
||||
/// const <|>
|
||||
/// }
|
||||
/// ```
|
||||
pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
|
||||
// it is possible to have a parent `fn` and `impl` block. Ignore completion
|
||||
|
@ -86,9 +125,17 @@ fn add_const_impl(
|
|||
.add_to(acc);
|
||||
}
|
||||
|
||||
/// Using a `ConstDef` `SyntaxNode` to create a `String` that represents
|
||||
/// the output of the magic completion.
|
||||
///
|
||||
/// There isn't a whole lot of information about a `hir::Const` or
|
||||
/// `ast::ConstDef` to prove useful when creating the magic completion for the
|
||||
/// associated constant. This method simply copies the syntax tree of the
|
||||
/// target trait up until a `;` or `=` is found. From the sliced syntax tree
|
||||
/// it formulates the magic completion string.
|
||||
fn make_const_compl_syntax(const_: &ast::ConstDef) -> String {
|
||||
let const_ = edit::strip_attrs_and_docs(const_);
|
||||
|
||||
|
||||
let const_start = const_.syntax().text_range().start();
|
||||
let const_end = const_.syntax().text_range().end();
|
||||
|
||||
|
|
Loading…
Reference in a new issue