mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
Split out complete_macro_in_item_position
This commit is contained in:
parent
c033d18700
commit
6353b1621f
3 changed files with 52 additions and 37 deletions
|
@ -12,6 +12,7 @@ mod complete_snippet;
|
|||
mod complete_path;
|
||||
mod complete_scope;
|
||||
mod complete_postfix;
|
||||
mod complete_macro_in_item_position;
|
||||
|
||||
use ra_db::SourceDatabase;
|
||||
|
||||
|
@ -69,5 +70,6 @@ pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Opti
|
|||
complete_record_pattern::complete_record_pattern(&mut acc, &ctx);
|
||||
complete_pattern::complete_pattern(&mut acc, &ctx);
|
||||
complete_postfix::complete_postfix(&mut acc, &ctx);
|
||||
complete_macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx);
|
||||
Some(acc)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
use crate::completion::{CompletionContext, Completions};
|
||||
|
||||
pub(super) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
// Show only macros in top level.
|
||||
if ctx.is_new_item {
|
||||
for (name, res) in ctx.analyzer.all_names(ctx.db) {
|
||||
if res.get_macros().is_some() {
|
||||
acc.add_resolution(ctx, name.to_string(), &res.only_macros());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::completion::{do_completion, CompletionItem, CompletionKind};
|
||||
use insta::assert_debug_snapshot;
|
||||
|
||||
fn do_reference_completion(code: &str) -> Vec<CompletionItem> {
|
||||
do_completion(code, CompletionKind::Reference)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completes_macros_as_item() {
|
||||
assert_debug_snapshot!(
|
||||
do_reference_completion(
|
||||
"
|
||||
//- /main.rs
|
||||
macro_rules! foo {
|
||||
() => {}
|
||||
}
|
||||
|
||||
fn foo() {}
|
||||
|
||||
<|>
|
||||
"
|
||||
),
|
||||
@r##"[
|
||||
CompletionItem {
|
||||
label: "foo",
|
||||
source_range: [46; 46),
|
||||
delete: [46; 46),
|
||||
insert: "foo!",
|
||||
kind: Macro,
|
||||
detail: "macro_rules! foo",
|
||||
},
|
||||
]"##
|
||||
);
|
||||
}
|
||||
}
|
|
@ -6,15 +6,6 @@ use rustc_hash::FxHashMap;
|
|||
use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
|
||||
|
||||
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
// Show only macros in top level.
|
||||
if ctx.is_new_item {
|
||||
for (name, res) in ctx.analyzer.all_names(ctx.db) {
|
||||
if res.get_macros().is_some() {
|
||||
acc.add_resolution(ctx, name.to_string(), &res.only_macros());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !ctx.is_trivial_path {
|
||||
return;
|
||||
}
|
||||
|
@ -730,34 +721,6 @@ mod tests {
|
|||
kind: Function,
|
||||
detail: "fn main()",
|
||||
},
|
||||
]"##
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completes_macros_as_item() {
|
||||
assert_debug_snapshot!(
|
||||
do_reference_completion(
|
||||
"
|
||||
//- /main.rs
|
||||
macro_rules! foo {
|
||||
() => {}
|
||||
}
|
||||
|
||||
fn foo() {}
|
||||
|
||||
<|>
|
||||
"
|
||||
),
|
||||
@r##"[
|
||||
CompletionItem {
|
||||
label: "foo",
|
||||
source_range: [46; 46),
|
||||
delete: [46; 46),
|
||||
insert: "foo!",
|
||||
kind: Macro,
|
||||
detail: "macro_rules! foo",
|
||||
},
|
||||
]"##
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue