diff options
author | gfreezy <[email protected]> | 2019-01-19 14:02:50 +0000 |
---|---|---|
committer | gfreezy <[email protected]> | 2019-01-19 14:02:50 +0000 |
commit | d08e81cdd818dd3378c292767e15a38e6bbc6f6c (patch) | |
tree | e07b3363f21912ca7aaca4ae1dce482c0bcd6f85 /crates/ra_lsp_server | |
parent | fa43ef30f4f96fc8e4ea1f9c4492bcb07b3335ca (diff) |
refactor completions to use TextEdit instead of InsertText
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 35 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 6 |
2 files changed, 24 insertions, 17 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 | } |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 8f9db68a2..d1e8c5774 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -337,7 +337,11 @@ pub fn handle_completion( | |||
337 | None => return Ok(None), | 337 | None => return Ok(None), |
338 | Some(items) => items, | 338 | Some(items) => items, |
339 | }; | 339 | }; |
340 | let items = items.into_iter().map(|item| item.conv()).collect(); | 340 | let line_index = world.analysis().file_line_index(position.file_id); |
341 | let items = items | ||
342 | .into_iter() | ||
343 | .map(|item| item.conv_with(&line_index)) | ||
344 | .collect(); | ||
341 | 345 | ||
342 | Ok(Some(req::CompletionResponse::Array(items))) | 346 | Ok(Some(req::CompletionResponse::Array(items))) |
343 | } | 347 | } |