Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyrefly/lib/lsp/non_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub mod queue;
pub mod safe_delete_file;
pub mod server;
pub mod stdlib;
pub mod transaction_manager;
pub mod type_error_display_status;
pub mod type_hierarchy;
pub mod unsaved_file_tracker;
Expand Down
47 changes: 0 additions & 47 deletions pyrefly/lib/lsp/non_wasm/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

use lsp_server::RequestId;
use lsp_server::ResponseError;
use lsp_types::TextDocumentContentChangeEvent;
use ruff_source_file::LineIndex;
use ruff_source_file::OneIndexed;
use ruff_source_file::SourceLocation;
use serde::de::DeserializeOwned;

use crate::lsp::non_wasm::protocol::Notification;
Expand Down Expand Up @@ -99,46 +95,3 @@ where
},
}
}

pub fn apply_change_events(original: &str, changes: Vec<TextDocumentContentChangeEvent>) -> String {
/// Convert lsp_types::Position to usize index for a given text.
fn position_to_usize(
position: lsp_types::Position,
index: &LineIndex,
source_text: &str,
) -> usize {
let source_location = SourceLocation {
line: OneIndexed::from_zero_indexed(position.line as usize),
character_offset: OneIndexed::from_zero_indexed(position.character as usize),
};
let text_size = index.offset(
source_location,
source_text,
ruff_source_file::PositionEncoding::Utf16,
);
text_size.to_usize()
}

let mut result = original.to_owned();
for change in changes {
let (range, text) = match change {
TextDocumentContentChangeEvent::TextDocumentContentChangePartial(partial) => {
(Some(partial.range), partial.text)
}
TextDocumentContentChangeEvent::TextDocumentContentChangeWholeDocument(whole) => {
(None, whole.text)
}
};
// If no range is given, we can full text replace.
match range {
None => result = text,
Some(range) => {
let index = LineIndex::from_source_text(&result);
let start = position_to_usize(range.start, &index, &result);
let end = position_to_usize(range.end, &index, &result);
result.replace_range(start..end, &text);
}
}
}
result
}
Loading
Loading