mirror of
https://github.com/denoland/deno.git
synced 2025-10-03 07:34:36 +00:00
refactor(lsp): don't duplicate fields present in DocumentSpan (#9131)
This commit is contained in:
parent
a3007de950
commit
4b2df87c54
2 changed files with 13 additions and 18 deletions
|
@ -812,7 +812,8 @@ impl lspower::LanguageServer for LanguageServer {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let reference_specifier =
|
let reference_specifier =
|
||||||
ModuleSpecifier::resolve_url(&reference.file_name).unwrap();
|
ModuleSpecifier::resolve_url(&reference.document_span.file_name)
|
||||||
|
.unwrap();
|
||||||
// TODO(lucacasonato): handle error correctly
|
// TODO(lucacasonato): handle error correctly
|
||||||
let line_index =
|
let line_index =
|
||||||
self.get_line_index(reference_specifier).await.unwrap();
|
self.get_line_index(reference_specifier).await.unwrap();
|
||||||
|
|
|
@ -474,13 +474,8 @@ pub struct ImplementationLocation {
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct RenameLocation {
|
pub struct RenameLocation {
|
||||||
// inherit from DocumentSpan
|
#[serde(flatten)]
|
||||||
text_span: TextSpan,
|
document_span: DocumentSpan,
|
||||||
file_name: String,
|
|
||||||
original_text_span: Option<TextSpan>,
|
|
||||||
original_file_name: Option<String>,
|
|
||||||
context_span: Option<TextSpan>,
|
|
||||||
original_context_span: Option<TextSpan>,
|
|
||||||
// RenameLocation props
|
// RenameLocation props
|
||||||
prefix_text: Option<String>,
|
prefix_text: Option<String>,
|
||||||
suffix_text: Option<String>,
|
suffix_text: Option<String>,
|
||||||
|
@ -504,8 +499,9 @@ impl RenameLocations {
|
||||||
let mut text_document_edit_map: HashMap<Url, lsp_types::TextDocumentEdit> =
|
let mut text_document_edit_map: HashMap<Url, lsp_types::TextDocumentEdit> =
|
||||||
HashMap::new();
|
HashMap::new();
|
||||||
for location in self.locations.iter() {
|
for location in self.locations.iter() {
|
||||||
let uri = utils::normalize_file_name(&location.file_name)?;
|
let uri = utils::normalize_file_name(&location.document_span.file_name)?;
|
||||||
let specifier = ModuleSpecifier::resolve_url(&location.file_name)?;
|
let specifier =
|
||||||
|
ModuleSpecifier::resolve_url(&location.document_span.file_name)?;
|
||||||
|
|
||||||
// ensure TextDocumentEdit for `location.file_name`.
|
// ensure TextDocumentEdit for `location.file_name`.
|
||||||
if text_document_edit_map.get(&uri).is_none() {
|
if text_document_edit_map.get(&uri).is_none() {
|
||||||
|
@ -535,6 +531,7 @@ impl RenameLocations {
|
||||||
.edits
|
.edits
|
||||||
.push(lsp_types::OneOf::Left(lsp_types::TextEdit {
|
.push(lsp_types::OneOf::Left(lsp_types::TextEdit {
|
||||||
range: location
|
range: location
|
||||||
|
.document_span
|
||||||
.text_span
|
.text_span
|
||||||
.to_range(&index_provider(specifier.clone()).await?),
|
.to_range(&index_provider(specifier.clone()).await?),
|
||||||
new_text: new_name.to_string(),
|
new_text: new_name.to_string(),
|
||||||
|
@ -654,20 +651,17 @@ pub struct ReferenceEntry {
|
||||||
is_write_access: bool,
|
is_write_access: bool,
|
||||||
pub is_definition: bool,
|
pub is_definition: bool,
|
||||||
is_in_string: Option<bool>,
|
is_in_string: Option<bool>,
|
||||||
text_span: TextSpan,
|
#[serde(flatten)]
|
||||||
pub file_name: String,
|
pub document_span: DocumentSpan,
|
||||||
original_text_span: Option<TextSpan>,
|
|
||||||
original_file_name: Option<String>,
|
|
||||||
context_span: Option<TextSpan>,
|
|
||||||
original_context_span: Option<TextSpan>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReferenceEntry {
|
impl ReferenceEntry {
|
||||||
pub fn to_location(&self, line_index: &[u32]) -> lsp_types::Location {
|
pub fn to_location(&self, line_index: &[u32]) -> lsp_types::Location {
|
||||||
let uri = utils::normalize_file_name(&self.file_name).unwrap();
|
let uri =
|
||||||
|
utils::normalize_file_name(&self.document_span.file_name).unwrap();
|
||||||
lsp_types::Location {
|
lsp_types::Location {
|
||||||
uri,
|
uri,
|
||||||
range: self.text_span.to_range(line_index),
|
range: self.document_span.text_span.to_range(line_index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue