更新结构

This commit is contained in:
锦恢 2024-09-07 21:39:23 +08:00
parent 00ec7abc6c
commit 53b8ebaa1a

View File

@ -455,31 +455,31 @@ pub trait LSPSupport {
/// Extend ropey's Rope type with lsp convenience functions /// Extend ropey's Rope type with lsp convenience functions
impl LSPSupport for Rope { impl LSPSupport for Rope {
fn pos_to_byte(&self, pos: &Position) -> usize { fn pos_to_byte(&self, pos: &Position) -> usize {
self.char_to_byte(self.pos_to_char(pos)) return self.char_to_byte(self.pos_to_char(pos));
} }
fn pos_to_char(&self, pos: &Position) -> usize { fn pos_to_char(&self, pos: &Position) -> usize {
let line_slice = self.line(pos.line as usize); let line_slice = self.line(pos.line as usize);
self.line_to_char(pos.line as usize) + line_slice.utf16_cu_to_char(pos.character as usize) return self.line_to_char(pos.line as usize) + line_slice.utf16_cu_to_char(pos.character as usize);
} }
fn byte_to_pos(&self, byte_idx: usize) -> Position { fn byte_to_pos(&self, byte_idx: usize) -> Position {
self.char_to_pos(self.byte_to_char(min(byte_idx, self.len_bytes() - 1))) return self.char_to_pos(self.byte_to_char(min(byte_idx, self.len_bytes() - 1)));
} }
fn char_to_pos(&self, char_idx: usize) -> Position { fn char_to_pos(&self, char_idx: usize) -> Position {
let line = self.char_to_line(char_idx); let line = self.char_to_line(char_idx);
let line_slice = self.line(line); let line_slice = self.line(line);
Position { return Position {
line: line as u32, line: line as u32,
character: line_slice.char_to_utf16_cu(char_idx - self.line_to_char(line)) as u32, character: line_slice.char_to_utf16_cu(char_idx - self.line_to_char(line)) as u32,
} };
} }
fn range_to_char_range(&self, range: &Range) -> StdRange<usize> { fn range_to_char_range(&self, range: &Range) -> StdRange<usize> {
self.pos_to_char(&range.start)..self.pos_to_char(&range.end) return self.pos_to_char(&range.start)..self.pos_to_char(&range.end);
} }
fn char_range_to_range(&self, range: StdRange<usize>) -> Range { fn char_range_to_range(&self, range: StdRange<usize>) -> Range {
Range { return Range {
start: self.char_to_pos(range.start), start: self.char_to_pos(range.start),
end: self.char_to_pos(range.end), end: self.char_to_pos(range.end),
} };
} }
fn apply_change(&mut self, change: &TextDocumentContentChangeEvent) { fn apply_change(&mut self, change: &TextDocumentContentChangeEvent) {
if let Some(range) = change.range { if let Some(range) = change.range {