Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of end-of-file #60

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Changes from 1 commit
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
Next Next commit
Fix underflow on empty line
  • Loading branch information
HennerM committed Jan 23, 2024
commit 878f3e40c7919a3a1473acdb5b2312a76a098bc7
6 changes: 5 additions & 1 deletion crates/llm-ls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ impl Display for CompletionType {
fn should_complete(document: &Document, position: Position) -> Result<CompletionType> {
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 },
Expand Down Expand Up @@ -114,7 +118,7 @@ fn should_complete(document: &Document, position: Position) -> Result<Completion
let next_char = document
.text
.get_char(start_idx + column)
HennerM marked this conversation as resolved.
Show resolved Hide resolved
.ok_or_else(|| internal_error(format!("failed to find char at {}", start_idx + column)))?;
.unwrap_or('\n'); // treat the end of document as newline
HennerM marked this conversation as resolved.
Show resolved Hide resolved
if next_char.is_whitespace() {
Ok(CompletionType::SingleLine)
} else {
Expand Down