diff options
Diffstat (limited to 'cli/lsp/text.rs')
-rw-r--r-- | cli/lsp/text.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/cli/lsp/text.rs b/cli/lsp/text.rs index 26df170ce..8013edd52 100644 --- a/cli/lsp/text.rs +++ b/cli/lsp/text.rs @@ -210,6 +210,18 @@ pub fn get_edits(a: &str, b: &str, line_index: &LineIndex) -> Vec<TextEdit> { if a == b { return vec![]; } + // Heuristic to detect things like minified files. `diff()` is expensive. + if b.chars().filter(|c| *c == '\n').count() + > line_index.utf8_offsets.len() * 3 + { + return vec![TextEdit { + range: lsp::Range { + start: lsp::Position::new(0, 0), + end: line_index.position_utf16(TextSize::from(a.len() as u32)), + }, + new_text: b.to_string(), + }]; + } let chunks = diff(a, b); let mut text_edits = Vec::<TextEdit>::new(); let mut iter = chunks.iter().peekable(); |