diff --git a/src/completion.ts b/src/completion.ts index a1bb0fb..498b1af 100644 --- a/src/completion.ts +++ b/src/completion.ts @@ -96,7 +96,13 @@ export class CompletionContext { /// implicitly by typing. The usual way to respond to this is to /// only return completions when either there is part of a /// completable entity before the cursor, or `explicit` is true. - readonly explicit: boolean + readonly explicit: boolean, + /// The editor view. May be undefined if the context was created + /// in a situation where there is no such view available, such as + /// in synchronous updates via + /// [`CompletionResult.update`](#autocomplete.CompletionResult.update) + /// or when called by test code. + readonly view?: EditorView ) {} /// Get the extent, content, and (if there is a token) type of the diff --git a/src/view.ts b/src/view.ts index 692ac18..aaadd45 100644 --- a/src/view.ts +++ b/src/view.ts @@ -130,7 +130,7 @@ export const completionPlugin = ViewPlugin.fromClass(class implements PluginValu startQuery(active: ActiveSource) { let {state} = this.view, pos = cur(state) - let context = new CompletionContext(state, pos, active.explicitPos == pos) + let context = new CompletionContext(state, pos, active.explicitPos == pos, this.view) let pending = new RunningQuery(active, context) this.running.push(pending) Promise.resolve(active.source(context)).then(result => {