aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-20 22:32:25 +0000
committerGitHub <[email protected]>2021-03-20 22:32:25 +0000
commit090e013161ab5b1679554ddd53683e81e3fe845a (patch)
treeffcf20a2b041f8fada69f7dfbc4adb1e129327f1 /crates/ide_completion/src/completions.rs
parentbe3dc673e2f00eaa7cfbf4727cc69032ed0b6179 (diff)
parent3c000c6364ebcf94652d221ee9ffe8970540589c (diff)
Merge #8124
8124: Add basic lifetime completion r=Veykril a=Veykril This adds basic lifetime completion, basic in the sense that the completions for lifetimes are only shown when the user enters `'` followed by a char. Showing them when nothing is entered is kind of a pain, as we would want them to only show up where they are useful which in turn requires a lot of tree traversal and cursor position checking to verify whether the position is valid for a lifetime. This in itself doesn't seem too bad as usually when you know you want to write a lifetime putting `'` to ask for lifetime completions seems fine. ~~I'll take a look at whether its possible to lift the restriction of having to put a char after `'`.~~ This actually already works so I guess this is the clients responsibility, in which case VSCode doesn't like it. ![TYH9gIlyVo](https://user-images.githubusercontent.com/3757771/111886437-c9b02f80-89cd-11eb-9bee-340f1536b0de.gif) Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/completions.rs')
-rw-r--r--crates/ide_completion/src/completions.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/crates/ide_completion/src/completions.rs b/crates/ide_completion/src/completions.rs
index 09882c4f3..cdac4e41a 100644
--- a/crates/ide_completion/src/completions.rs
+++ b/crates/ide_completion/src/completions.rs
@@ -2,25 +2,27 @@
2 2
3pub(crate) mod attribute; 3pub(crate) mod attribute;
4pub(crate) mod dot; 4pub(crate) mod dot;
5pub(crate) mod record; 5pub(crate) mod flyimport;
6pub(crate) mod pattern;
7pub(crate) mod fn_param; 6pub(crate) mod fn_param;
8pub(crate) mod keyword; 7pub(crate) mod keyword;
9pub(crate) mod snippet; 8pub(crate) mod lifetime;
10pub(crate) mod qualified_path;
11pub(crate) mod unqualified_path;
12pub(crate) mod postfix;
13pub(crate) mod macro_in_item_position; 9pub(crate) mod macro_in_item_position;
14pub(crate) mod trait_impl;
15pub(crate) mod mod_; 10pub(crate) mod mod_;
16pub(crate) mod flyimport; 11pub(crate) mod pattern;
12pub(crate) mod postfix;
13pub(crate) mod qualified_path;
14pub(crate) mod record;
15pub(crate) mod snippet;
16pub(crate) mod trait_impl;
17pub(crate) mod unqualified_path;
17 18
18use std::iter; 19use std::iter;
19 20
20use hir::{known, ModPath, ScopeDef, Type}; 21use hir::{known, ModPath, ScopeDef, Type};
22use ide_db::SymbolKind;
21 23
22use crate::{ 24use crate::{
23 item::Builder, 25 item::{Builder, CompletionKind},
24 render::{ 26 render::{
25 const_::render_const, 27 const_::render_const,
26 enum_variant::render_variant, 28 enum_variant::render_variant,
@@ -31,7 +33,7 @@ use crate::{
31 type_alias::render_type_alias, 33 type_alias::render_type_alias,
32 RenderContext, 34 RenderContext,
33 }, 35 },
34 CompletionContext, CompletionItem, 36 CompletionContext, CompletionItem, CompletionItemKind,
35}; 37};
36 38
37/// Represents an in-progress set of completions being built. 39/// Represents an in-progress set of completions being built.
@@ -77,6 +79,13 @@ impl Completions {
77 self.add(item); 79 self.add(item);
78 } 80 }
79 81
82 pub(crate) fn add_static_lifetime(&mut self, ctx: &CompletionContext) {
83 let mut item =
84 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), "'static");
85 item.kind(CompletionItemKind::SymbolKind(SymbolKind::LifetimeParam));
86 self.add(item.build());
87 }
88
80 pub(crate) fn add_resolution( 89 pub(crate) fn add_resolution(
81 &mut self, 90 &mut self,
82 ctx: &CompletionContext, 91 ctx: &CompletionContext,