Clamp for all UTF-16 to offset conversions which used to use ToOffset

This commit is contained in:
Julia 2022-11-15 15:16:52 -05:00
parent f9cbed5a1f
commit bb32599ded
4 changed files with 43 additions and 39 deletions

View file

@ -131,7 +131,9 @@ impl LspCommand for PrepareRename {
if buffer.clip_point_utf16(start, Bias::Left) == start
&& buffer.clip_point_utf16(end, Bias::Left) == end
{
return Ok(Some(buffer.anchor_after(start)..buffer.anchor_before(end)));
return Ok(Some(
buffer.clamped_anchor_after(start)..buffer.clamped_anchor_before(end),
));
}
}
Ok(None)
@ -143,7 +145,7 @@ impl LspCommand for PrepareRename {
project_id,
buffer_id: buffer.remote_id(),
position: Some(language::proto::serialize_anchor(
&buffer.anchor_before(self.position),
&buffer.clamped_anchor_before(self.position),
)),
version: serialize_version(&buffer.version()),
}
@ -262,7 +264,7 @@ impl LspCommand for PerformRename {
project_id,
buffer_id: buffer.remote_id(),
position: Some(language::proto::serialize_anchor(
&buffer.anchor_before(self.position),
&buffer.clamped_anchor_before(self.position),
)),
new_name: self.new_name.clone(),
version: serialize_version(&buffer.version()),
@ -360,7 +362,7 @@ impl LspCommand for GetDefinition {
project_id,
buffer_id: buffer.remote_id(),
position: Some(language::proto::serialize_anchor(
&buffer.anchor_before(self.position),
&buffer.clamped_anchor_before(self.position),
)),
version: serialize_version(&buffer.version()),
}
@ -446,7 +448,7 @@ impl LspCommand for GetTypeDefinition {
project_id,
buffer_id: buffer.remote_id(),
position: Some(language::proto::serialize_anchor(
&buffer.anchor_before(self.position),
&buffer.clamped_anchor_before(self.position),
)),
version: serialize_version(&buffer.version()),
}
@ -629,8 +631,8 @@ async fn location_links_from_lsp(
origin_buffer.clip_point_utf16(point_from_lsp(origin_range.end), Bias::Left);
Location {
buffer: buffer.clone(),
range: origin_buffer.anchor_after(origin_start)
..origin_buffer.anchor_before(origin_end),
range: origin_buffer.clamped_anchor_after(origin_start)
..origin_buffer.clamped_anchor_before(origin_end),
}
});
@ -641,8 +643,8 @@ async fn location_links_from_lsp(
target_buffer.clip_point_utf16(point_from_lsp(target_range.end), Bias::Left);
let target_location = Location {
buffer: target_buffer_handle,
range: target_buffer.anchor_after(target_start)
..target_buffer.anchor_before(target_end),
range: target_buffer.clamped_anchor_after(target_start)
..target_buffer.clamped_anchor_before(target_end),
};
definitions.push(LocationLink {
@ -741,8 +743,8 @@ impl LspCommand for GetReferences {
.clip_point_utf16(point_from_lsp(lsp_location.range.end), Bias::Left);
references.push(Location {
buffer: target_buffer_handle,
range: target_buffer.anchor_after(target_start)
..target_buffer.anchor_before(target_end),
range: target_buffer.clamped_anchor_after(target_start)
..target_buffer.clamped_anchor_before(target_end),
});
});
}
@ -756,7 +758,7 @@ impl LspCommand for GetReferences {
project_id,
buffer_id: buffer.remote_id(),
position: Some(language::proto::serialize_anchor(
&buffer.anchor_before(self.position),
&buffer.clamped_anchor_before(self.position),
)),
version: serialize_version(&buffer.version()),
}
@ -882,7 +884,8 @@ impl LspCommand for GetDocumentHighlights {
let end = buffer
.clip_point_utf16(point_from_lsp(lsp_highlight.range.end), Bias::Left);
DocumentHighlight {
range: buffer.anchor_after(start)..buffer.anchor_before(end),
range: buffer.clamped_anchor_after(start)
..buffer.clamped_anchor_before(end),
kind: lsp_highlight
.kind
.unwrap_or(lsp::DocumentHighlightKind::READ),
@ -897,7 +900,7 @@ impl LspCommand for GetDocumentHighlights {
project_id,
buffer_id: buffer.remote_id(),
position: Some(language::proto::serialize_anchor(
&buffer.anchor_before(self.position),
&buffer.clamped_anchor_before(self.position),
)),
version: serialize_version(&buffer.version()),
}
@ -1017,7 +1020,8 @@ impl LspCommand for GetHover {
let token_start =
buffer.clip_point_utf16(point_from_lsp(range.start), Bias::Left);
let token_end = buffer.clip_point_utf16(point_from_lsp(range.end), Bias::Left);
buffer.anchor_after(token_start)..buffer.anchor_before(token_end)
buffer.clamped_anchor_after(token_start)
..buffer.clamped_anchor_before(token_end)
})
});
@ -1099,7 +1103,7 @@ impl LspCommand for GetHover {
project_id,
buffer_id: buffer.remote_id(),
position: Some(language::proto::serialize_anchor(
&buffer.anchor_before(self.position),
&buffer.clamped_anchor_before(self.position),
)),
version: serialize_version(&buffer.version),
}