Auto merge of #13318 - Veykril:annotations, r=Veykril

Fix annotations not resolving when lens location is set to whole item

Fixes https://github.com/rust-lang/rust-analyzer/issues/13310
This commit is contained in:
bors
2022-09-30 22:31:05 +00:00
5 changed files with 199 additions and 130 deletions

View File

@@ -95,22 +95,22 @@ pub(crate) fn annotation(
match resolve {
lsp_ext::CodeLensResolveData::Impls(params) => {
let file_id =
snap.url_to_file_id(&params.text_document_position_params.text_document.uri)?;
let pos @ FilePosition { file_id, .. } =
file_position(snap, params.text_document_position_params)?;
let line_index = snap.file_line_index(file_id)?;
Ok(Annotation {
range: text_range(&line_index, code_lens.range)?,
kind: AnnotationKind::HasImpls { file_id, data: None },
kind: AnnotationKind::HasImpls { pos, data: None },
})
}
lsp_ext::CodeLensResolveData::References(params) => {
let file_id = snap.url_to_file_id(&params.text_document.uri)?;
let pos @ FilePosition { file_id, .. } = file_position(snap, params)?;
let line_index = snap.file_line_index(file_id)?;
Ok(Annotation {
range: text_range(&line_index, code_lens.range)?,
kind: AnnotationKind::HasReferences { file_id, data: None },
kind: AnnotationKind::HasReferences { pos, data: None },
})
}
}

View File

@@ -1177,13 +1177,13 @@ pub(crate) fn code_lens(
})
}
}
AnnotationKind::HasImpls { file_id, data } => {
AnnotationKind::HasImpls { pos: file_range, data } => {
if !client_commands_config.show_reference {
return Ok(());
}
let line_index = snap.file_line_index(file_id)?;
let line_index = snap.file_line_index(file_range.file_id)?;
let annotation_range = range(&line_index, annotation.range);
let url = url(snap, file_id);
let url = url(snap, file_range.file_id);
let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
@@ -1221,13 +1221,13 @@ pub(crate) fn code_lens(
data: Some(to_value(lsp_ext::CodeLensResolveData::Impls(goto_params)).unwrap()),
})
}
AnnotationKind::HasReferences { file_id, data } => {
AnnotationKind::HasReferences { pos: file_range, data } => {
if !client_commands_config.show_reference {
return Ok(());
}
let line_index = snap.file_line_index(file_id)?;
let line_index = snap.file_line_index(file_range.file_id)?;
let annotation_range = range(&line_index, annotation.range);
let url = url(snap, file_id);
let url = url(snap, file_range.file_id);
let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };