diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/completion/complete_unqualified_path.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 46 |
2 files changed, 49 insertions, 9 deletions
diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index f559f2b97..a6a5568de 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs | |||
@@ -53,7 +53,7 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T | |||
53 | // Variants with trivial paths are already added by the existing completion logic, | 53 | // Variants with trivial paths are already added by the existing completion logic, |
54 | // so we should avoid adding these twice | 54 | // so we should avoid adding these twice |
55 | if path.segments.len() > 1 { | 55 | if path.segments.len() > 1 { |
56 | acc.add_enum_variant(ctx, variant, Some(path.to_string())); | 56 | acc.add_qualified_enum_variant(ctx, variant, path); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | } | 59 | } |
@@ -1173,6 +1173,7 @@ mod tests { | |||
1173 | delete: 248..250, | 1173 | delete: 248..250, |
1174 | insert: "Foo::Bar", | 1174 | insert: "Foo::Bar", |
1175 | kind: EnumVariant, | 1175 | kind: EnumVariant, |
1176 | lookup: "Bar", | ||
1176 | detail: "()", | 1177 | detail: "()", |
1177 | }, | 1178 | }, |
1178 | CompletionItem { | 1179 | CompletionItem { |
@@ -1181,6 +1182,7 @@ mod tests { | |||
1181 | delete: 248..250, | 1182 | delete: 248..250, |
1182 | insert: "Foo::Baz", | 1183 | insert: "Foo::Baz", |
1183 | kind: EnumVariant, | 1184 | kind: EnumVariant, |
1185 | lookup: "Baz", | ||
1184 | detail: "()", | 1186 | detail: "()", |
1185 | }, | 1187 | }, |
1186 | CompletionItem { | 1188 | CompletionItem { |
@@ -1189,6 +1191,7 @@ mod tests { | |||
1189 | delete: 248..250, | 1191 | delete: 248..250, |
1190 | insert: "Foo::Quux", | 1192 | insert: "Foo::Quux", |
1191 | kind: EnumVariant, | 1193 | kind: EnumVariant, |
1194 | lookup: "Quux", | ||
1192 | detail: "()", | 1195 | detail: "()", |
1193 | }, | 1196 | }, |
1194 | ] | 1197 | ] |
@@ -1231,6 +1234,7 @@ mod tests { | |||
1231 | delete: 219..221, | 1234 | delete: 219..221, |
1232 | insert: "Foo::Bar", | 1235 | insert: "Foo::Bar", |
1233 | kind: EnumVariant, | 1236 | kind: EnumVariant, |
1237 | lookup: "Bar", | ||
1234 | detail: "()", | 1238 | detail: "()", |
1235 | }, | 1239 | }, |
1236 | CompletionItem { | 1240 | CompletionItem { |
@@ -1239,6 +1243,7 @@ mod tests { | |||
1239 | delete: 219..221, | 1243 | delete: 219..221, |
1240 | insert: "Foo::Baz", | 1244 | insert: "Foo::Baz", |
1241 | kind: EnumVariant, | 1245 | kind: EnumVariant, |
1246 | lookup: "Baz", | ||
1242 | detail: "()", | 1247 | detail: "()", |
1243 | }, | 1248 | }, |
1244 | CompletionItem { | 1249 | CompletionItem { |
@@ -1247,6 +1252,7 @@ mod tests { | |||
1247 | delete: 219..221, | 1252 | delete: 219..221, |
1248 | insert: "Foo::Quux", | 1253 | insert: "Foo::Quux", |
1249 | kind: EnumVariant, | 1254 | kind: EnumVariant, |
1255 | lookup: "Quux", | ||
1250 | detail: "()", | 1256 | detail: "()", |
1251 | }, | 1257 | }, |
1252 | ] | 1258 | ] |
@@ -1285,6 +1291,7 @@ mod tests { | |||
1285 | delete: 185..186, | 1291 | delete: 185..186, |
1286 | insert: "Foo::Bar", | 1292 | insert: "Foo::Bar", |
1287 | kind: EnumVariant, | 1293 | kind: EnumVariant, |
1294 | lookup: "Bar", | ||
1288 | detail: "()", | 1295 | detail: "()", |
1289 | }, | 1296 | }, |
1290 | CompletionItem { | 1297 | CompletionItem { |
@@ -1293,6 +1300,7 @@ mod tests { | |||
1293 | delete: 185..186, | 1300 | delete: 185..186, |
1294 | insert: "Foo::Baz", | 1301 | insert: "Foo::Baz", |
1295 | kind: EnumVariant, | 1302 | kind: EnumVariant, |
1303 | lookup: "Baz", | ||
1296 | detail: "()", | 1304 | detail: "()", |
1297 | }, | 1305 | }, |
1298 | CompletionItem { | 1306 | CompletionItem { |
@@ -1301,6 +1309,7 @@ mod tests { | |||
1301 | delete: 185..186, | 1309 | delete: 185..186, |
1302 | insert: "Foo::Quux", | 1310 | insert: "Foo::Quux", |
1303 | kind: EnumVariant, | 1311 | kind: EnumVariant, |
1312 | lookup: "Quux", | ||
1304 | detail: "()", | 1313 | detail: "()", |
1305 | }, | 1314 | }, |
1306 | CompletionItem { | 1315 | CompletionItem { |
@@ -1353,6 +1362,7 @@ mod tests { | |||
1353 | delete: 98..99, | 1362 | delete: 98..99, |
1354 | insert: "m::E::V", | 1363 | insert: "m::E::V", |
1355 | kind: EnumVariant, | 1364 | kind: EnumVariant, |
1365 | lookup: "V", | ||
1356 | detail: "()", | 1366 | detail: "()", |
1357 | }, | 1367 | }, |
1358 | ] | 1368 | ] |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 77d354376..2edb130cf 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! This modules takes care of rendering various definitions as completion items. | 1 | //! This modules takes care of rendering various definitions as completion items. |
2 | 2 | ||
3 | use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type}; | 3 | use hir::{Docs, HasAttrs, HasSource, HirDisplay, ModPath, ScopeDef, StructKind, Type}; |
4 | use ra_syntax::ast::NameOwner; | 4 | use ra_syntax::ast::NameOwner; |
5 | use stdx::SepBy; | 5 | use stdx::SepBy; |
6 | use test_utils::tested_by; | 6 | use test_utils::tested_by; |
@@ -246,14 +246,37 @@ impl Completions { | |||
246 | .add_to(self); | 246 | .add_to(self); |
247 | } | 247 | } |
248 | 248 | ||
249 | pub(crate) fn add_qualified_enum_variant( | ||
250 | &mut self, | ||
251 | ctx: &CompletionContext, | ||
252 | variant: hir::EnumVariant, | ||
253 | path: ModPath, | ||
254 | ) { | ||
255 | self.add_enum_variant_impl(ctx, variant, None, Some(path)) | ||
256 | } | ||
257 | |||
249 | pub(crate) fn add_enum_variant( | 258 | pub(crate) fn add_enum_variant( |
250 | &mut self, | 259 | &mut self, |
251 | ctx: &CompletionContext, | 260 | ctx: &CompletionContext, |
252 | variant: hir::EnumVariant, | 261 | variant: hir::EnumVariant, |
253 | local_name: Option<String>, | 262 | local_name: Option<String>, |
254 | ) { | 263 | ) { |
264 | self.add_enum_variant_impl(ctx, variant, local_name, None) | ||
265 | } | ||
266 | |||
267 | fn add_enum_variant_impl( | ||
268 | &mut self, | ||
269 | ctx: &CompletionContext, | ||
270 | variant: hir::EnumVariant, | ||
271 | local_name: Option<String>, | ||
272 | path: Option<ModPath>, | ||
273 | ) { | ||
255 | let is_deprecated = is_deprecated(variant, ctx.db); | 274 | let is_deprecated = is_deprecated(variant, ctx.db); |
256 | let name = local_name.unwrap_or_else(|| variant.name(ctx.db).to_string()); | 275 | let name = local_name.unwrap_or_else(|| variant.name(ctx.db).to_string()); |
276 | let qualified_name = match &path { | ||
277 | Some(it) => it.to_string(), | ||
278 | None => name.to_string(), | ||
279 | }; | ||
257 | let detail_types = variant | 280 | let detail_types = variant |
258 | .fields(ctx.db) | 281 | .fields(ctx.db) |
259 | .into_iter() | 282 | .into_iter() |
@@ -271,16 +294,23 @@ impl Completions { | |||
271 | .surround_with("{ ", " }") | 294 | .surround_with("{ ", " }") |
272 | .to_string(), | 295 | .to_string(), |
273 | }; | 296 | }; |
274 | let mut res = | 297 | let mut res = CompletionItem::new( |
275 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) | 298 | CompletionKind::Reference, |
276 | .kind(CompletionItemKind::EnumVariant) | 299 | ctx.source_range(), |
277 | .set_documentation(variant.docs(ctx.db)) | 300 | qualified_name.clone(), |
278 | .set_deprecated(is_deprecated) | 301 | ) |
279 | .detail(detail); | 302 | .kind(CompletionItemKind::EnumVariant) |
303 | .set_documentation(variant.docs(ctx.db)) | ||
304 | .set_deprecated(is_deprecated) | ||
305 | .detail(detail); | ||
306 | |||
307 | if path.is_some() { | ||
308 | res = res.lookup_by(name); | ||
309 | } | ||
280 | 310 | ||
281 | if variant_kind == StructKind::Tuple { | 311 | if variant_kind == StructKind::Tuple { |
282 | let params = Params::Anonymous(variant.fields(ctx.db).len()); | 312 | let params = Params::Anonymous(variant.fields(ctx.db).len()); |
283 | res = res.add_call_parens(ctx, name, params) | 313 | res = res.add_call_parens(ctx, qualified_name, params) |
284 | } | 314 | } |
285 | 315 | ||
286 | res.add_to(self); | 316 | res.add_to(self); |