use flatten branch of lsp-types

This commit is contained in:
Jeremy Kolb 2019-07-07 14:13:13 -04:00
parent 1b38ca3b87
commit 3f44aaf363
5 changed files with 22 additions and 31 deletions

View file

@ -153,14 +153,12 @@ pub fn handle_on_type_formatting(
params: req::DocumentOnTypeFormattingParams,
) -> Result<Option<Vec<TextEdit>>> {
let _p = profile("handle_on_type_formatting");
let file_id = params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(file_id);
let position = FilePosition {
file_id,
/// in `ra_ide_api`, the `on_type` invariant is that
/// `text.char_at(position) == typed_char`.
offset: params.position.conv_with(&line_index) - TextUnit::of_char('.'),
};
let mut position = params.text_document_position.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(position.file_id);
// in `ra_ide_api`, the `on_type` invariant is that
// `text.char_at(position) == typed_char`.
position.offset = position.offset - TextUnit::of_char('.');
let edit = match params.ch.as_str() {
"=" => world.analysis().on_eq_typed(position),
@ -407,12 +405,7 @@ pub fn handle_completion(
params: req::CompletionParams,
) -> Result<Option<req::CompletionResponse>> {
let _p = profile("handle_completion");
let position = {
let file_id = params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(file_id);
let offset = params.position.conv_with(&line_index);
FilePosition { file_id, offset }
};
let position = params.text_document_position.try_conv_with(&world)?;
let completion_triggered_after_single_colon = {
let mut res = false;
if let Some(ctx) = params.context {
@ -543,9 +536,7 @@ pub fn handle_prepare_rename(
}
pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Option<WorkspaceEdit>> {
let file_id = params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(file_id);
let offset = params.position.conv_with(&line_index);
let position = params.text_document_position.try_conv_with(&world)?;
if params.new_name.is_empty() {
return Err(LspError::new(
@ -555,8 +546,7 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio
.into());
}
let optional_change =
world.analysis().rename(FilePosition { file_id, offset }, &*params.new_name)?;
let optional_change = world.analysis().rename(position, &*params.new_name)?;
let change = match optional_change {
None => return Ok(None),
Some(it) => it,
@ -571,11 +561,10 @@ pub fn handle_references(
world: WorldSnapshot,
params: req::ReferenceParams,
) -> Result<Option<Vec<Location>>> {
let file_id = params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(file_id);
let offset = params.position.conv_with(&line_index);
let position = params.text_document_position.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(position.file_id);
let refs = match world.analysis().find_all_refs(FilePosition { file_id, offset })? {
let refs = match world.analysis().find_all_refs(position)? {
None => return Ok(None),
Some(refs) => refs,
};