Skip to content

Commit

Permalink
Provide an optional view reference in CompletionContext
Browse files Browse the repository at this point in the history
FEATURE: `CompletionContext` objects now have a `view` property that holds
the editor view when the query context has a view available.
  • Loading branch information
marijnh committed Jul 3, 2024
1 parent 82893f8 commit ef0844c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit ef0844c

Please sign in to comment.