How to manually trigger auto completion to run?

We have implemented a yaml editor in our product that can switch between different yaml text documents. User can also make edits within each document as well. Due to this requirement it seems we are forced to dispatch changes when yamlDocument changes.

The below dispatch runs when the user switches the yaml document in view or they type within the editor.
Which seems a bit inefficient and maybe there is a better way to handle this? In any case doing this on every change breaks auto completion. Is there a way to trigger auto completion to run after the dispatch occurs? Or is there a better solution than the one I have below?

         changes: { from: 0, to: view.state.doc.length, insert: yamlDocument },
          selection: {              
              anchor: cursorPosition,
              head: cursorPosition,

I don’t understand why you’d need to replace the entire document on every change here. If the user can switch between documents, that only needs to happen when they actually switch, no? When doing that, create a new editor state and move the editor to that using EditorView.setState.

Thanks again for the quick response. The main problem is that we are using a wrapper around code mirror. None of the internal code mirror functionality is exposed through this component. I’ll have to figure out if there is a way to separate the logic as such that the component only is initialized once and no subsequent updates occur unless the user switches the yaml view.