mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
introduce completion_item module
This commit is contained in:
parent
463e5af3f2
commit
74406ca8ea
3 changed files with 54 additions and 21 deletions
44
crates/ra_analysis/src/completion/completion_item.rs
Normal file
44
crates/ra_analysis/src/completion/completion_item.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
#[derive(Debug)]
|
||||
pub struct CompletionItem {
|
||||
/// What user sees in pop-up in the UI.
|
||||
pub label: String,
|
||||
/// What string is used for filtering, defaults to label.
|
||||
pub lookup: Option<String>,
|
||||
/// What is inserted, defaults to label.
|
||||
pub snippet: Option<String>,
|
||||
}
|
||||
|
||||
impl CompletionItem {
|
||||
pub(crate) fn new(label: impl Into<String>) -> Builder {
|
||||
let label = label.into();
|
||||
Builder {
|
||||
label,
|
||||
lookup: None,
|
||||
snippet: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Builder {
|
||||
label: String,
|
||||
lookup: Option<String>,
|
||||
snippet: Option<String>,
|
||||
}
|
||||
|
||||
impl Builder {
|
||||
pub fn add_to(self, acc: &mut Vec<CompletionItem>) {
|
||||
acc.push(self.build())
|
||||
}
|
||||
|
||||
pub fn build(self) -> CompletionItem {
|
||||
CompletionItem {
|
||||
label: self.label,
|
||||
lookup: self.lookup,
|
||||
snippet: self.snippet,
|
||||
}
|
||||
}
|
||||
pub fn lookup_by(mut self, lookup: impl Into<String>) -> Builder {
|
||||
self.lookup = Some(lookup.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -6,11 +6,9 @@ use ra_syntax::{
|
|||
ast::{self, LoopBodyOwner},
|
||||
SyntaxKind::*,
|
||||
};
|
||||
use hir::{
|
||||
self,
|
||||
FnScopes,
|
||||
Def,
|
||||
Path,
|
||||
use hir::{
|
||||
self,
|
||||
FnScopes, Def, Path
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue