diff options
Diffstat (limited to 'crates/ra_lsp_server/src/conv.rs')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 218ded4ee..051f1f995 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | use languageserver_types::{ | 1 | use languageserver_types::{ |
2 | self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, | 2 | self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, |
3 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, | 3 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat, |
4 | }; | 4 | }; |
5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition}; | 5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition, CompletionItem, CompletionItemKind, InsertText}; |
6 | use ra_editor::{LineCol, LineIndex}; | 6 | use ra_editor::{LineCol, LineIndex}; |
7 | use ra_text_edit::{AtomTextEdit, TextEdit}; | 7 | use ra_text_edit::{AtomTextEdit, TextEdit}; |
8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
@@ -45,6 +45,46 @@ impl Conv for SyntaxKind { | |||
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | impl Conv for CompletionItemKind { | ||
49 | type Output = ::languageserver_types::CompletionItemKind; | ||
50 | |||
51 | fn conv(self) -> <Self as Conv>::Output { | ||
52 | use ::languageserver_types::CompletionItemKind::*; | ||
53 | match self { | ||
54 | CompletionItemKind::Keyword => Keyword, | ||
55 | CompletionItemKind::Snippet => Snippet, | ||
56 | CompletionItemKind::Module => Module, | ||
57 | CompletionItemKind::Function => Function, | ||
58 | CompletionItemKind::Binding => Variable, | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | impl Conv for CompletionItem { | ||
64 | type Output = ::languageserver_types::CompletionItem; | ||
65 | |||
66 | fn conv(self) -> <Self as Conv>::Output { | ||
67 | let mut res = ::languageserver_types::CompletionItem { | ||
68 | label: self.label().to_string(), | ||
69 | filter_text: Some(self.lookup().to_string()), | ||
70 | kind: self.kind().map(|it| it.conv()), | ||
71 | ..Default::default() | ||
72 | }; | ||
73 | match self.insert_text() { | ||
74 | InsertText::PlainText { text } => { | ||
75 | res.insert_text = Some(text); | ||
76 | res.insert_text_format = Some(InsertTextFormat::PlainText); | ||
77 | } | ||
78 | InsertText::Snippet { text } => { | ||
79 | res.insert_text = Some(text); | ||
80 | res.insert_text_format = Some(InsertTextFormat::Snippet); | ||
81 | res.kind = Some(languageserver_types::CompletionItemKind::Keyword); | ||
82 | } | ||
83 | } | ||
84 | res | ||
85 | } | ||
86 | } | ||
87 | |||
48 | impl ConvWith for Position { | 88 | impl ConvWith for Position { |
49 | type Ctx = LineIndex; | 89 | type Ctx = LineIndex; |
50 | type Output = TextUnit; | 90 | type Output = TextUnit; |