diff options
Diffstat (limited to 'crates/ra_lsp_server/src/conv.rs')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 6e187d49e..76215a975 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -1,13 +1,13 @@ | |||
1 | use lsp_types::{ | 1 | use lsp_types::{ |
2 | self, CreateFile, DocumentChangeOperation, DocumentChanges, InsertTextFormat, Location, LocationLink, | 2 | self, CreateFile, DocumentChangeOperation, DocumentChanges, Location, LocationLink, |
3 | Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, | 3 | Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, |
4 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, | 4 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, |
5 | WorkspaceEdit, | 5 | WorkspaceEdit, |
6 | }; | 6 | }; |
7 | use ra_ide_api::{ | 7 | use ra_ide_api::{ |
8 | CompletionItem, CompletionItemKind, FileId, FilePosition, FileRange, FileSystemEdit, | 8 | CompletionItem, CompletionItemKind, FileId, FilePosition, FileRange, FileSystemEdit, |
9 | InsertText, NavigationTarget, SourceChange, SourceFileEdit, RangeInfo, | 9 | NavigationTarget, SourceChange, SourceFileEdit, RangeInfo, |
10 | LineCol, LineIndex, translate_offset_with_edit | 10 | LineCol, LineIndex, translate_offset_with_edit, InsertTextFormat |
11 | }; | 11 | }; |
12 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 12 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
13 | use ra_text_edit::{AtomTextEdit, TextEdit}; | 13 | use ra_text_edit::{AtomTextEdit, TextEdit}; |
@@ -74,27 +74,30 @@ impl Conv for CompletionItemKind { | |||
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | impl Conv for CompletionItem { | 77 | impl ConvWith for CompletionItem { |
78 | type Ctx = LineIndex; | ||
78 | type Output = ::lsp_types::CompletionItem; | 79 | type Output = ::lsp_types::CompletionItem; |
79 | 80 | ||
80 | fn conv(self) -> <Self as Conv>::Output { | 81 | fn conv_with(mut self, ctx: &LineIndex) -> ::lsp_types::CompletionItem { |
81 | let mut res = ::lsp_types::CompletionItem { | 82 | let text_edit = self.text_edit().map(|t| t.conv_with(ctx)); |
83 | let additonal_text_edit = self | ||
84 | .take_additional_text_edits() | ||
85 | .map(|it| it.conv_with(ctx)); | ||
86 | |||
87 | let mut res = lsp_types::CompletionItem { | ||
82 | label: self.label().to_string(), | 88 | label: self.label().to_string(), |
83 | detail: self.detail().map(|it| it.to_string()), | 89 | detail: self.detail().map(|it| it.to_string()), |
84 | filter_text: Some(self.lookup().to_string()), | 90 | filter_text: Some(self.lookup().to_string()), |
85 | kind: self.kind().map(|it| it.conv()), | 91 | kind: self.kind().map(|it| it.conv()), |
92 | text_edit, | ||
93 | additional_text_edits: additonal_text_edit, | ||
86 | ..Default::default() | 94 | ..Default::default() |
87 | }; | 95 | }; |
88 | match self.insert_text() { | 96 | res.insert_text_format = Some(match self.insert_text_format() { |
89 | InsertText::PlainText { text } => { | 97 | InsertTextFormat::Snippet => lsp_types::InsertTextFormat::Snippet, |
90 | res.insert_text = Some(text); | 98 | InsertTextFormat::PlainText => lsp_types::InsertTextFormat::PlainText, |
91 | res.insert_text_format = Some(InsertTextFormat::PlainText); | 99 | }); |
92 | } | 100 | |
93 | InsertText::Snippet { text } => { | ||
94 | res.insert_text = Some(text); | ||
95 | res.insert_text_format = Some(InsertTextFormat::Snippet); | ||
96 | } | ||
97 | } | ||
98 | res | 101 | res |
99 | } | 102 | } |
100 | } | 103 | } |