val-town / codemirror-codeium

Codeium code completion integration for CodeMirror 6
https://val-town.github.io/codemirror-codeium/
Other
50 stars 3 forks source link

Error about applying rejectSuggestionCommand to a document of a different length #25

Closed tmcw closed 5 months ago

tmcw commented 5 months ago

This is making me really wonder about the lifecycle of this component: hitting a pretty bad bug in which rejectSuggestionCommand is called with a document of the wrong length, which causes a hard crash. It's hard to replicate in isolation.

function viewCompletionPlugin() {
  return EditorView.updateListener.of((update) => {
    if (update.focusChanged) {
      rejectSuggestionCommand(update.view);
    }
  });
}

This always goes through the focusChanged path. At the very least it should be possible to make sure that the length of the Changeset is the same as the document.

RangeError: Applying change set to a document with the wrong length
  at ChangeSet.apply(../../../node_modules/@codemirror/state/dist/index.js:882:19)
  at get Transaction.newDoc(../../../node_modules/@codemirror/state/dist/index.js:2292:55)