Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet authored Dec 17, 2024
1 parent d08f30d commit 0686766
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import { InlineCompletionContextKeys } from './inlineCompletionContextKeys.js';
import { InlineCompletionsView } from '../view/inlineCompletionsView.js';

export class InlineCompletionsController extends Disposable {
private static readonly _instances = new Set<InlineCompletionsController>();

public static hot = createHotClass(InlineCompletionsController);
public static ID = 'editor.contrib.inlineCompletionsController';

Expand Down Expand Up @@ -116,6 +118,22 @@ export class InlineCompletionsController extends Disposable {
) {
super();

InlineCompletionsController._instances.add(this);
this._register(toDisposable(() => InlineCompletionsController._instances.delete(this)));

this._register(autorun(reader => {
// Cancel all other inline completions when a new one starts
const model = this.model.read(reader);
if (!model) { return; }
if (model.state.read(reader) !== undefined) {
for (const ctrl of InlineCompletionsController._instances) {
if (ctrl !== this) {
ctrl.reject();
}
}
}
}));

this._register(runOnChange(this._editorObs.onDidType, (_value, _changes) => {
if (this._enabled.get()) {
this.model.get()?.trigger();
Expand Down

0 comments on commit 0686766

Please sign in to comment.