mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
specify completion item kind
This commit is contained in:
parent
284e894069
commit
328d123f5b
4 changed files with 17 additions and 12 deletions
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use crate::completion::completion_item::{CompletionItem, InsertText};
|
pub use crate::completion::completion_item::{CompletionItem, InsertText, CompletionItemKind};
|
||||||
|
|
||||||
/// Main entry point for copmletion. We run comletion as a two-phase process.
|
/// Main entry point for copmletion. We run comletion as a two-phase process.
|
||||||
///
|
///
|
||||||
|
|
|
@ -5,10 +5,11 @@ use ra_syntax::{
|
||||||
SyntaxKind::*, SyntaxNodeRef,
|
SyntaxKind::*, SyntaxNodeRef,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind};
|
use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind};
|
||||||
|
|
||||||
fn keyword(kw: &str, snippet: &str) -> CompletionItem {
|
fn keyword(kw: &str, snippet: &str) -> CompletionItem {
|
||||||
CompletionItem::new(CompletionKind::Keyword, kw)
|
CompletionItem::new(CompletionKind::Keyword, kw)
|
||||||
|
.kind(CompletionItemKind::Keyword)
|
||||||
.snippet(snippet)
|
.snippet(snippet)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext, completion_item::Builder};
|
use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionItemKind, CompletionContext, completion_item::Builder};
|
||||||
|
|
||||||
fn snippet(label: &str, snippet: &str) -> Builder {
|
fn snippet(label: &str, snippet: &str) -> Builder {
|
||||||
CompletionItem::new(CompletionKind::Snippet, label).snippet(snippet)
|
CompletionItem::new(CompletionKind::Snippet, label)
|
||||||
|
.snippet(snippet)
|
||||||
|
.kind(CompletionItemKind::Keyword)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
/// `CompletionItem`, use `new` method and the `Builder` struct.
|
/// `CompletionItem`, use `new` method and the `Builder` struct.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CompletionItem {
|
pub struct CompletionItem {
|
||||||
|
/// Used only internally in tests, to check only specific kind of
|
||||||
|
/// completion.
|
||||||
|
completion_kind: CompletionKind,
|
||||||
label: String,
|
label: String,
|
||||||
lookup: Option<String>,
|
lookup: Option<String>,
|
||||||
snippet: Option<String>,
|
snippet: Option<String>,
|
||||||
kind: Option<CompletionItemKind>,
|
kind: Option<CompletionItemKind>,
|
||||||
/// Used only internally in tests, to check only specific kind of
|
|
||||||
/// completion.
|
|
||||||
completion_kind: CompletionKind,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum InsertText {
|
pub enum InsertText {
|
||||||
|
@ -38,10 +38,11 @@ impl CompletionItem {
|
||||||
pub(crate) fn new(completion_kind: CompletionKind, label: impl Into<String>) -> Builder {
|
pub(crate) fn new(completion_kind: CompletionKind, label: impl Into<String>) -> Builder {
|
||||||
let label = label.into();
|
let label = label.into();
|
||||||
Builder {
|
Builder {
|
||||||
|
completion_kind,
|
||||||
label,
|
label,
|
||||||
lookup: None,
|
lookup: None,
|
||||||
snippet: None,
|
snippet: None,
|
||||||
completion_kind,
|
kind: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// What user sees in pop-up in the UI.
|
/// What user sees in pop-up in the UI.
|
||||||
|
@ -73,10 +74,11 @@ impl CompletionItem {
|
||||||
/// A helper to make `CompletionItem`s.
|
/// A helper to make `CompletionItem`s.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) struct Builder {
|
pub(crate) struct Builder {
|
||||||
|
completion_kind: CompletionKind,
|
||||||
label: String,
|
label: String,
|
||||||
lookup: Option<String>,
|
lookup: Option<String>,
|
||||||
snippet: Option<String>,
|
snippet: Option<String>,
|
||||||
completion_kind: CompletionKind,
|
kind: Option<CompletionItemKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Builder {
|
impl Builder {
|
||||||
|
@ -89,7 +91,7 @@ impl Builder {
|
||||||
label: self.label,
|
label: self.label,
|
||||||
lookup: self.lookup,
|
lookup: self.lookup,
|
||||||
snippet: self.snippet,
|
snippet: self.snippet,
|
||||||
kind: None,
|
kind: self.kind,
|
||||||
completion_kind: self.completion_kind,
|
completion_kind: self.completion_kind,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,8 +103,8 @@ impl Builder {
|
||||||
self.snippet = Some(snippet.into());
|
self.snippet = Some(snippet.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub(crate) fn kind(mut self, kind: CompletionKind) -> Builder {
|
pub(crate) fn kind(mut self, kind: CompletionItemKind) -> Builder {
|
||||||
self.completion_kind = kind;
|
self.kind = Some(kind);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue