From 61f3a438d3a729a6be941bca1ff4c6a97a33f221 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Mon, 15 Oct 2018 17:44:23 -0400 Subject: Cargo Format Run `cargo fmt` and ignore generated files --- crates/ra_lsp_server/src/conv.rs | 66 +++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 35 deletions(-) (limited to 'crates/ra_lsp_server/src/conv.rs') diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index a75b160c5..8325e8c1e 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -1,17 +1,12 @@ use languageserver_types::{ - Range, SymbolKind, Position, TextEdit, Location, Url, - TextDocumentIdentifier, VersionedTextDocumentIdentifier, TextDocumentItem, - TextDocumentPositionParams, TextDocumentEdit, -}; -use ra_editor::{LineIndex, LineCol, Edit, AtomEdit}; -use ra_syntax::{SyntaxKind, TextUnit, TextRange}; -use ra_analysis::{FileId, SourceChange, SourceFileEdit, FileSystemEdit}; - -use crate::{ - Result, - server_world::ServerWorld, - req, + Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, + TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier, }; +use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit}; +use ra_editor::{AtomEdit, Edit, LineCol, LineIndex}; +use ra_syntax::{SyntaxKind, TextRange, TextUnit}; + +use crate::{req, server_world::ServerWorld, Result}; pub trait Conv { type Output; @@ -190,8 +185,12 @@ impl TryConvWith for SourceChange { None => None, Some(pos) => { let line_index = world.analysis().file_line_index(pos.file_id); - let edits = self.source_file_edits.iter().find(|it| it.file_id == pos.file_id) - .map(|it| it.edits.as_slice()).unwrap_or(&[]); + let edits = self + .source_file_edits + .iter() + .find(|it| it.file_id == pos.file_id) + .map(|it| it.edits.as_slice()) + .unwrap_or(&[]); let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); let position = Position::new(line_col.line as u64, u32::from(line_col.col) as u64); Some(TextDocumentPositionParams { @@ -224,11 +223,11 @@ fn translate_offset_with_edit( let fallback = pre_edit_index.line_col(offset); let edit = match edits.first() { None => return fallback, - Some(edit) => edit + Some(edit) => edit, }; let end_offset = edit.delete.start() + TextUnit::of_str(&edit.insert); if !(edit.delete.start() <= offset && offset <= end_offset) { - return fallback + return fallback; } let rel_offset = offset - edit.delete.start(); let in_edit_line_col = LineIndex::new(&edit.insert).line_col(rel_offset); @@ -255,11 +254,11 @@ impl TryConvWith for SourceFileEdit { version: None, }; let line_index = world.analysis().file_line_index(self.file_id); - let edits = self.edits - .into_iter() - .map_conv_with(&line_index) - .collect(); - Ok(TextDocumentEdit { text_document, edits }) + let edits = self.edits.into_iter().map_conv_with(&line_index).collect(); + Ok(TextDocumentEdit { + text_document, + edits, + }) } } @@ -273,13 +272,13 @@ impl TryConvWith for FileSystemEdit { let path = &path.as_str()[3..]; // strip `../` b/c url is weird let uri = uri.join(path)?; req::FileSystemEdit::CreateFile { uri } - }, + } FileSystemEdit::MoveFile { file, path } => { let src = world.file_id_to_uri(file)?; let path = &path.as_str()[3..]; // strip `../` b/c url is weird let dst = src.join(path)?; req::FileSystemEdit::MoveFile { src, dst } - }, + } }; Ok(res) } @@ -291,12 +290,9 @@ pub fn to_location( world: &ServerWorld, line_index: &LineIndex, ) -> Result { - let url = file_id.try_conv_with(world)?; - let loc = Location::new( - url, - range.conv_with(line_index), - ); - Ok(loc) + let url = file_id.try_conv_with(world)?; + let loc = Location::new(url, range.conv_with(line_index)); + Ok(loc) } pub trait MapConvWith<'a>: Sized + 'a { @@ -309,8 +305,9 @@ pub trait MapConvWith<'a>: Sized + 'a { } impl<'a, I> MapConvWith<'a> for I - where I: Iterator + 'a, - I::Item: ConvWith +where + I: Iterator + 'a, + I::Item: ConvWith, { type Ctx = ::Ctx; type Output = ::Output; @@ -322,9 +319,9 @@ pub struct ConvWithIter<'a, I, Ctx: 'a> { } impl<'a, I, Ctx> Iterator for ConvWithIter<'a, I, Ctx> - where - I: Iterator, - I::Item: ConvWith, +where + I: Iterator, + I::Item: ConvWith, { type Item = ::Output; @@ -332,4 +329,3 @@ impl<'a, I, Ctx> Iterator for ConvWithIter<'a, I, Ctx> self.iter.next().map(|item| item.conv_with(self.ctx)) } } - -- cgit v1.2.3