mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
complete fields in struct literals
This commit is contained in:
parent
65a2be4953
commit
6285fcc39b
1 changed files with 16 additions and 7 deletions
|
@ -3,7 +3,7 @@ use hir::{Ty, AdtDef, Docs};
|
||||||
use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind};
|
use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind};
|
||||||
use crate::completion::completion_item::CompletionKind;
|
use crate::completion::completion_item::CompletionKind;
|
||||||
|
|
||||||
/// Complete dot accesses, i.e. fields or methods (currently only fields).
|
/// Complete fields in fields literals.
|
||||||
pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
let (function, struct_lit) = match (&ctx.function, ctx.struct_lit_syntax) {
|
let (function, struct_lit) = match (&ctx.function, ctx.struct_lit_syntax) {
|
||||||
(Some(function), Some(struct_lit)) => (function, struct_lit),
|
(Some(function), Some(struct_lit)) => (function, struct_lit),
|
||||||
|
@ -42,17 +42,16 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::completion::*;
|
use insta::assert_debug_snapshot_matches;
|
||||||
use crate::completion::completion_item::check_completion;
|
use crate::completion::{CompletionItem, CompletionKind};
|
||||||
|
|
||||||
fn check_ref_completion(name: &str, code: &str) {
|
fn complete(code: &str) -> Vec<CompletionItem> {
|
||||||
check_completion(name, code, CompletionKind::Reference);
|
crate::completion::completion_item::do_completion(code, CompletionKind::Reference)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_literal_field() {
|
fn test_struct_literal_field() {
|
||||||
check_ref_completion(
|
let completions = complete(
|
||||||
"test_struct_literal_field",
|
|
||||||
r"
|
r"
|
||||||
struct A { the_field: u32 }
|
struct A { the_field: u32 }
|
||||||
fn foo() {
|
fn foo() {
|
||||||
|
@ -60,5 +59,15 @@ mod tests {
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
assert_debug_snapshot_matches!(completions, @r###"[
|
||||||
|
CompletionItem {
|
||||||
|
label: "the_field",
|
||||||
|
source_range: [83; 86),
|
||||||
|
delete: [83; 86),
|
||||||
|
insert: "the_field",
|
||||||
|
kind: Field,
|
||||||
|
detail: "u32"
|
||||||
|
}
|
||||||
|
]"###);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue