Skip to content

Commit d6329f2

Browse files
bors[bot]Veykril
andauthored
Merge #11401
11401: Sort completion calls lexicographically r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 5a7e11f + c830818 commit d6329f2

File tree

6 files changed

+130
-24
lines changed

6 files changed

+130
-24
lines changed

crates/ide_completion/src/completions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub(crate) mod attribute;
44
pub(crate) mod dot;
5+
pub(crate) mod extern_abi;
56
pub(crate) mod flyimport;
67
pub(crate) mod fn_param;
78
pub(crate) mod format_string;

crates/ide_completion/src/completions/dot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,12 @@ struct Foo { field: i32 }
684684
685685
impl Foo { fn foo(&self) { $0 } }"#,
686686
expect![[r#"
687+
fd self.field i32
688+
me self.foo() fn(&self)
687689
lc self &Foo
688690
sp Self
689691
st Foo
690692
bt u32
691-
fd self.field i32
692-
me self.foo() fn(&self)
693693
"#]],
694694
);
695695
check(
@@ -698,12 +698,12 @@ struct Foo(i32);
698698
699699
impl Foo { fn foo(&mut self) { $0 } }"#,
700700
expect![[r#"
701+
fd self.0 i32
702+
me self.foo() fn(&mut self)
701703
lc self &mut Foo
702704
sp Self
703705
st Foo
704706
bt u32
705-
fd self.0 i32
706-
me self.foo() fn(&mut self)
707707
"#]],
708708
);
709709
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//! Completes function abi strings.
2+
use syntax::{
3+
ast::{self, IsString},
4+
AstNode, AstToken,
5+
};
6+
7+
use crate::{
8+
completions::Completions, context::CompletionContext, CompletionItem, CompletionItemKind,
9+
};
10+
11+
// Most of these are feature gated, we should filter/add feature gate completions once we have them.
12+
const SUPPORTED_CALLING_CONVENTIONS: &[&str] = &[
13+
"Rust",
14+
"C",
15+
"C-unwind",
16+
"cdecl",
17+
"stdcall",
18+
"stdcall-unwind",
19+
"fastcall",
20+
"vectorcall",
21+
"thiscall",
22+
"thiscall-unwind",
23+
"aapcs",
24+
"win64",
25+
"sysv64",
26+
"ptx-kernel",
27+
"msp430-interrupt",
28+
"x86-interrupt",
29+
"amdgpu-kernel",
30+
"efiapi",
31+
"avr-interrupt",
32+
"avr-non-blocking-interrupt",
33+
"C-cmse-nonsecure-call",
34+
"wasm",
35+
"system",
36+
"system-unwind",
37+
"rust-intrinsic",
38+
"rust-call",
39+
"platform-intrinsic",
40+
"unadjusted",
41+
];
42+
43+
pub(crate) fn complete_extern_abi(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
44+
if ctx.token.parent().and_then(ast::Abi::cast).is_none() {
45+
return None;
46+
}
47+
let abi_str = ast::String::cast(ctx.token.clone())?;
48+
let source_range = abi_str.text_range_between_quotes()?;
49+
for &abi in SUPPORTED_CALLING_CONVENTIONS {
50+
CompletionItem::new(CompletionItemKind::Keyword, source_range, abi).add_to(acc);
51+
}
52+
Some(())
53+
}
54+
55+
#[cfg(test)]
56+
mod tests {
57+
use expect_test::{expect, Expect};
58+
59+
use crate::tests::{check_edit, completion_list_no_kw};
60+
61+
fn check(ra_fixture: &str, expect: Expect) {
62+
let actual = completion_list_no_kw(ra_fixture);
63+
expect.assert_eq(&actual);
64+
}
65+
66+
#[test]
67+
fn only_completes_in_string_literals() {
68+
check(
69+
r#"
70+
$0 fn foo {}
71+
"#,
72+
expect![[]],
73+
);
74+
}
75+
76+
#[test]
77+
fn requires_extern_prefix() {
78+
check(
79+
r#"
80+
"$0" fn foo {}
81+
"#,
82+
expect![[]],
83+
);
84+
}
85+
86+
#[test]
87+
fn works() {
88+
check(
89+
r#"
90+
extern "$0" fn foo {}
91+
"#,
92+
expect![[]],
93+
);
94+
check_edit(
95+
"Rust",
96+
r#"
97+
extern "$0" fn foo {}
98+
"#,
99+
r#"
100+
extern "Rust" fn foo {}
101+
"#,
102+
);
103+
}
104+
}

crates/ide_completion/src/lib.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,28 @@ pub fn completions(
151151
}
152152

153153
let mut acc = Completions::default();
154-
completions::attribute::complete_known_attribute_input(&mut acc, &ctx);
155154
completions::attribute::complete_attribute(&mut acc, &ctx);
156-
completions::use_::complete_use_tree(&mut acc, &ctx);
157-
completions::vis::complete_vis(&mut acc, &ctx);
155+
completions::attribute::complete_known_attribute_input(&mut acc, &ctx);
156+
completions::dot::complete_dot(&mut acc, &ctx);
157+
completions::extern_abi::complete_extern_abi(&mut acc, &ctx);
158+
completions::flyimport::import_on_the_fly(&mut acc, &ctx);
158159
completions::fn_param::complete_fn_param(&mut acc, &ctx);
160+
completions::format_string::format_string(&mut acc, &ctx);
159161
completions::keyword::complete_expr_keyword(&mut acc, &ctx);
160-
completions::snippet::complete_expr_snippet(&mut acc, &ctx);
161-
completions::snippet::complete_item_snippet(&mut acc, &ctx);
162-
completions::qualified_path::complete_qualified_path(&mut acc, &ctx);
163-
completions::unqualified_path::complete_unqualified_path(&mut acc, &ctx);
164-
completions::dot::complete_dot(&mut acc, &ctx);
165-
completions::record::complete_record(&mut acc, &ctx);
166-
completions::record::complete_record_literal(&mut acc, &ctx);
162+
completions::lifetime::complete_label(&mut acc, &ctx);
163+
completions::lifetime::complete_lifetime(&mut acc, &ctx);
164+
completions::mod_::complete_mod(&mut acc, &ctx);
167165
completions::pattern::complete_pattern(&mut acc, &ctx);
168166
completions::postfix::complete_postfix(&mut acc, &ctx);
167+
completions::qualified_path::complete_qualified_path(&mut acc, &ctx);
168+
completions::record::complete_record_literal(&mut acc, &ctx);
169+
completions::record::complete_record(&mut acc, &ctx);
170+
completions::snippet::complete_expr_snippet(&mut acc, &ctx);
171+
completions::snippet::complete_item_snippet(&mut acc, &ctx);
169172
completions::trait_impl::complete_trait_impl(&mut acc, &ctx);
170-
completions::mod_::complete_mod(&mut acc, &ctx);
171-
completions::flyimport::import_on_the_fly(&mut acc, &ctx);
172-
completions::lifetime::complete_lifetime(&mut acc, &ctx);
173-
completions::lifetime::complete_label(&mut acc, &ctx);
174-
completions::format_string::format_string(&mut acc, &ctx);
173+
completions::unqualified_path::complete_unqualified_path(&mut acc, &ctx);
174+
completions::use_::complete_use_tree(&mut acc, &ctx);
175+
completions::vis::complete_vis(&mut acc, &ctx);
175176

176177
Some(acc)
177178
}

crates/ide_completion/src/tests/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl Unit {
126126
"#,
127127
// `self` is in here twice, once as the module, once as the local
128128
expect![[r##"
129+
me self.foo() fn(self)
129130
kw unsafe
130131
kw fn
131132
kw const
@@ -172,7 +173,6 @@ impl Unit {
172173
un Union
173174
ev TupleV(…) (u32)
174175
ct CONST
175-
me self.foo() fn(self)
176176
"##]],
177177
);
178178
check(

crates/ide_completion/src/tests/record.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ fn main() {
166166
kw true
167167
kw false
168168
kw return
169+
sn Foo {…} Foo { foo1: ${1:()}, foo2: ${2:()} }$0
170+
fd ..Default::default()
171+
fd foo1 u32
172+
fd foo2 u32
169173
kw self
170174
kw super
171175
kw crate
@@ -177,10 +181,6 @@ fn main() {
177181
bt u32
178182
tt Sized
179183
tt Default
180-
fd ..Default::default()
181-
fd foo1 u32
182-
fd foo2 u32
183-
sn Foo {…} Foo { foo1: ${1:()}, foo2: ${2:()} }$0
184184
"#]],
185185
);
186186
check(

0 commit comments

Comments
 (0)