diff options
author | Aleksey Kladov <[email protected]> | 2018-11-05 11:57:41 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-11-05 11:57:41 +0000 |
commit | 0192c116f78b3a81ef15587eecac29a2676ae00c (patch) | |
tree | e4ade14c93e07ad1e55df0961ba5ca67902f29f7 /crates/ra_lsp_server/src/conv.rs | |
parent | 1e1c188cbf1fbb80ee398977e6635b9a54a3ab7a (diff) |
Use FilePosition everywhere
Diffstat (limited to 'crates/ra_lsp_server/src/conv.rs')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 84ffac2da..fa04f4b00 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -2,7 +2,7 @@ use languageserver_types::{ | |||
2 | Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, | 2 | Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, |
3 | TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier, | 3 | TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier, |
4 | }; | 4 | }; |
5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit}; | 5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition}; |
6 | use ra_editor::{AtomEdit, Edit, LineCol, LineIndex}; | 6 | use ra_editor::{AtomEdit, Edit, LineCol, LineIndex}; |
7 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 7 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
8 | 8 | ||
@@ -165,6 +165,17 @@ impl<'a> TryConvWith for &'a TextDocumentIdentifier { | |||
165 | } | 165 | } |
166 | } | 166 | } |
167 | 167 | ||
168 | impl<'a> TryConvWith for &'a TextDocumentPositionParams { | ||
169 | type Ctx = ServerWorld; | ||
170 | type Output = FilePosition; | ||
171 | fn try_conv_with(self, world: &ServerWorld) -> Result<FilePosition> { | ||
172 | let file_id = self.text_document.try_conv_with(world)?; | ||
173 | let line_index = world.analysis().file_line_index(file_id); | ||
174 | let offset = self.position.conv_with(&line_index); | ||
175 | Ok(FilePosition { file_id, offset }) | ||
176 | } | ||
177 | } | ||
178 | |||
168 | impl<T: TryConvWith> TryConvWith for Vec<T> { | 179 | impl<T: TryConvWith> TryConvWith for Vec<T> { |
169 | type Ctx = <T as TryConvWith>::Ctx; | 180 | type Ctx = <T as TryConvWith>::Ctx; |
170 | type Output = Vec<<T as TryConvWith>::Output>; | 181 | type Output = Vec<<T as TryConvWith>::Output>; |