Skip to content

Fix didChange out-of-range crash in ollama_lsp#10

Open
cmtonkinson wants to merge 1 commit intoJacob411:mainfrom
cmtonkinson:fix/didchange-index-guard
Open

Fix didChange out-of-range crash in ollama_lsp#10
cmtonkinson wants to merge 1 commit intoJacob411:mainfrom
cmtonkinson:fix/didchange-index-guard

Conversation

@cmtonkinson
Copy link
Copy Markdown

Summary

Fixes a crash in python/ollama_lsp.py when handling textDocument/didChange events with ranges that are missing or out of bounds.

Problem

on_change assumed:

  • change.range is always present
  • change.range.start.line is always within document.lines
  • change.range.start.character is always within the current line

In real edit/delete flows, those assumptions can be violated, causing exceptions and the Neovim client to exit with code 1.

Changes

In python/ollama_lsp.py (on_change):

  • return early if change.range is missing/None
  • return early if start.line >= len(lines)
  • guard start.character before slicing the current line (use empty suffix if out of range)

This keeps behavior unchanged for valid edits while avoiding crashes on edge-case range payloads.

Validation

  • python3 -m py_compile python/ollama_lsp.py
  • validated in Neovim using local plugin dir
  • confirmed ollama_lsp stays attached after edit operations that previously caused exits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant