From c9a44e591cbe7dd7d9d6dbc6833a00d54c80f319 Mon Sep 17 00:00:00 2001 From: Markus Hennerbichler Date: Mon, 5 Feb 2024 17:37:24 +0000 Subject: [PATCH] Fix handling of end-of-file (#60) * Fix underflow on empty line * Update crates/llm-ls/src/main.rs Co-authored-by: Luc Georges * Update crates/llm-ls/src/main.rs Co-authored-by: Luc Georges --------- Co-authored-by: Luc Georges --- crates/llm-ls/src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/llm-ls/src/main.rs b/crates/llm-ls/src/main.rs index 5700152..2640569 100644 --- a/crates/llm-ls/src/main.rs +++ b/crates/llm-ls/src/main.rs @@ -57,6 +57,10 @@ impl Display for CompletionType { fn should_complete(document: &Document, position: Position) -> Result { let row = position.line as usize; let column = position.character as usize; + if document.text.len_chars() == 0 { + warn!("Document is empty"); + return Ok(CompletionType::Empty); + } if let Some(tree) = &document.tree { let current_node = tree.root_node().descendant_for_point_range( tree_sitter::Point { row, column }, @@ -111,10 +115,11 @@ fn should_complete(document: &Document, position: Position) -> Result