mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Teach CompletionItem about documentation
This commit is contained in:
parent
b59334e67a
commit
5d110c0ee2
2 changed files with 26 additions and 2 deletions
|
@ -15,6 +15,7 @@ pub struct CompletionItem {
|
|||
label: String,
|
||||
kind: Option<CompletionItemKind>,
|
||||
detail: Option<String>,
|
||||
documentation: Option<String>,
|
||||
lookup: Option<String>,
|
||||
insert_text: Option<String>,
|
||||
insert_text_format: InsertTextFormat,
|
||||
|
@ -77,6 +78,7 @@ impl CompletionItem {
|
|||
insert_text: None,
|
||||
insert_text_format: InsertTextFormat::PlainText,
|
||||
detail: None,
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
kind: None,
|
||||
text_edit: None,
|
||||
|
@ -90,6 +92,10 @@ impl CompletionItem {
|
|||
pub fn detail(&self) -> Option<&str> {
|
||||
self.detail.as_ref().map(|it| it.as_str())
|
||||
}
|
||||
/// A doc-comment
|
||||
pub fn documentation(&self) -> Option<&str> {
|
||||
self.documentation.as_ref().map(|it| it.as_str())
|
||||
}
|
||||
/// What string is used for filtering.
|
||||
pub fn lookup(&self) -> &str {
|
||||
self.lookup
|
||||
|
@ -127,6 +133,7 @@ pub(crate) struct Builder {
|
|||
insert_text: Option<String>,
|
||||
insert_text_format: InsertTextFormat,
|
||||
detail: Option<String>,
|
||||
documentation: Option<String>,
|
||||
lookup: Option<String>,
|
||||
kind: Option<CompletionItemKind>,
|
||||
text_edit: Option<TextEdit>,
|
||||
|
@ -142,6 +149,7 @@ impl Builder {
|
|||
source_range: self.source_range,
|
||||
label: self.label,
|
||||
detail: self.detail,
|
||||
documentation: self.documentation,
|
||||
insert_text_format: self.insert_text_format,
|
||||
lookup: self.lookup,
|
||||
kind: self.kind,
|
||||
|
@ -184,6 +192,14 @@ impl Builder {
|
|||
self.detail = detail.map(Into::into);
|
||||
self
|
||||
}
|
||||
#[allow(unused)]
|
||||
pub(crate) fn documentation(self, docs: impl Into<String>) -> Builder {
|
||||
self.set_documentation(Some(docs))
|
||||
}
|
||||
pub(crate) fn set_documentation(mut self, docs: Option<impl Into<String>>) -> Builder {
|
||||
self.documentation = docs.map(Into::into);
|
||||
self
|
||||
}
|
||||
pub(super) fn from_resolution(
|
||||
mut self,
|
||||
ctx: &CompletionContext,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use lsp_types::{
|
||||
self, CreateFile, DocumentChangeOperation, DocumentChanges, Location, LocationLink,
|
||||
Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
|
||||
self, CreateFile, Documentation, DocumentChangeOperation, DocumentChanges, Location, LocationLink,
|
||||
MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
|
||||
TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier,
|
||||
WorkspaceEdit,
|
||||
};
|
||||
|
@ -87,6 +87,13 @@ impl ConvWith for CompletionItem {
|
|||
None
|
||||
};
|
||||
|
||||
let documentation = self.documentation().map(|value| {
|
||||
Documentation::MarkupContent(MarkupContent {
|
||||
kind: MarkupKind::Markdown,
|
||||
value: value.to_string(),
|
||||
})
|
||||
});
|
||||
|
||||
let mut res = lsp_types::CompletionItem {
|
||||
label: self.label().to_string(),
|
||||
detail: self.detail().map(|it| it.to_string()),
|
||||
|
@ -94,6 +101,7 @@ impl ConvWith for CompletionItem {
|
|||
kind: self.kind().map(|it| it.conv()),
|
||||
text_edit: Some(text_edit),
|
||||
additional_text_edits,
|
||||
documentation: documentation,
|
||||
..Default::default()
|
||||
};
|
||||
res.insert_text_format = Some(match self.insert_text_format() {
|
||||
|
|
Loading…
Reference in a new issue