mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-27 07:10:30 -04:00
Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)
* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 * disable strict null check
This commit is contained in:
@@ -7,7 +7,7 @@ import { isNonEmptyArray } from 'vs/base/common/arrays';
|
||||
import { TimeoutTimer } from 'vs/base/common/async';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, dispose, DisposableStore, isDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
@@ -91,7 +91,7 @@ export const enum State {
|
||||
|
||||
export class SuggestModel implements IDisposable {
|
||||
|
||||
private _toDispose: IDisposable[] = [];
|
||||
private readonly _toDispose = new DisposableStore();
|
||||
private _quickSuggestDelay: number;
|
||||
private _triggerCharacterListener: IDisposable;
|
||||
private readonly _triggerQuickSuggest = new TimeoutTimer();
|
||||
@@ -101,7 +101,8 @@ export class SuggestModel implements IDisposable {
|
||||
private _context?: LineContext;
|
||||
private _currentSelection: Selection;
|
||||
|
||||
private _completionModel?: CompletionModel;
|
||||
private _completionModel: CompletionModel | undefined;
|
||||
private readonly _completionDisposables = new DisposableStore();
|
||||
private readonly _onDidCancel = new Emitter<ICancelEvent>();
|
||||
private readonly _onDidTrigger = new Emitter<ITriggerEvent>();
|
||||
private readonly _onDidSuggest = new Emitter<ISuggestEvent>();
|
||||
@@ -117,36 +118,36 @@ export class SuggestModel implements IDisposable {
|
||||
this._currentSelection = this._editor.getSelection() || new Selection(1, 1, 1, 1);
|
||||
|
||||
// wire up various listeners
|
||||
this._toDispose.push(this._editor.onDidChangeModel(() => {
|
||||
this._toDispose.add(this._editor.onDidChangeModel(() => {
|
||||
this._updateTriggerCharacters();
|
||||
this.cancel();
|
||||
}));
|
||||
this._toDispose.push(this._editor.onDidChangeModelLanguage(() => {
|
||||
this._toDispose.add(this._editor.onDidChangeModelLanguage(() => {
|
||||
this._updateTriggerCharacters();
|
||||
this.cancel();
|
||||
}));
|
||||
this._toDispose.push(this._editor.onDidChangeConfiguration(() => {
|
||||
this._toDispose.add(this._editor.onDidChangeConfiguration(() => {
|
||||
this._updateTriggerCharacters();
|
||||
this._updateQuickSuggest();
|
||||
}));
|
||||
this._toDispose.push(CompletionProviderRegistry.onDidChange(() => {
|
||||
this._toDispose.add(CompletionProviderRegistry.onDidChange(() => {
|
||||
this._updateTriggerCharacters();
|
||||
this._updateActiveSuggestSession();
|
||||
}));
|
||||
this._toDispose.push(this._editor.onDidChangeCursorSelection(e => {
|
||||
this._toDispose.add(this._editor.onDidChangeCursorSelection(e => {
|
||||
this._onCursorChange(e);
|
||||
}));
|
||||
|
||||
let editorIsComposing = false;
|
||||
this._toDispose.push(this._editor.onCompositionStart(() => {
|
||||
this._toDispose.add(this._editor.onCompositionStart(() => {
|
||||
editorIsComposing = true;
|
||||
}));
|
||||
this._toDispose.push(this._editor.onCompositionEnd(() => {
|
||||
this._toDispose.add(this._editor.onCompositionEnd(() => {
|
||||
// refilter when composition ends
|
||||
editorIsComposing = false;
|
||||
this._refilterCompletionItems();
|
||||
}));
|
||||
this._toDispose.push(this._editor.onDidChangeModelContent(() => {
|
||||
this._toDispose.add(this._editor.onDidChangeModelContent(() => {
|
||||
// only filter completions when the editor isn't
|
||||
// composing a character, e.g. ¨ + u makes ü but just
|
||||
// ¨ cannot be used for filtering
|
||||
@@ -161,8 +162,8 @@ export class SuggestModel implements IDisposable {
|
||||
|
||||
dispose(): void {
|
||||
dispose([this._onDidCancel, this._onDidSuggest, this._onDidTrigger, this._triggerCharacterListener, this._triggerQuickSuggest]);
|
||||
this._toDispose = dispose(this._toDispose);
|
||||
dispose(this._completionModel);
|
||||
this._toDispose.dispose();
|
||||
this._completionDisposables.dispose();
|
||||
this.cancel();
|
||||
}
|
||||
|
||||
@@ -226,13 +227,16 @@ export class SuggestModel implements IDisposable {
|
||||
this._requestToken = undefined;
|
||||
}
|
||||
this._state = State.Idle;
|
||||
dispose(this._completionModel);
|
||||
this._completionModel = undefined;
|
||||
this._context = undefined;
|
||||
this._onDidCancel.fire({ retrigger });
|
||||
}
|
||||
}
|
||||
|
||||
clear() {
|
||||
this._completionDisposables.clear();
|
||||
}
|
||||
|
||||
private _updateActiveSuggestSession(): void {
|
||||
if (this._state !== State.Idle) {
|
||||
if (!this._editor.hasModel() || !CompletionProviderRegistry.has(this._editor.getModel())) {
|
||||
@@ -289,6 +293,9 @@ export class SuggestModel implements IDisposable {
|
||||
this.cancel();
|
||||
|
||||
this._triggerQuickSuggest.cancelAndSet(() => {
|
||||
if (this._state !== State.Idle) {
|
||||
return;
|
||||
}
|
||||
if (!LineContext.shouldAutoTrigger(this._editor)) {
|
||||
return;
|
||||
}
|
||||
@@ -435,7 +442,6 @@ export class SuggestModel implements IDisposable {
|
||||
}
|
||||
|
||||
const ctx = new LineContext(model, this._editor.getPosition(), auto, context.shy);
|
||||
dispose(this._completionModel);
|
||||
this._completionModel = new CompletionModel(items, this._context!.column, {
|
||||
leadingLineContent: ctx.leadingLineContent,
|
||||
characterCountDelta: ctx.column - this._context!.column
|
||||
@@ -443,6 +449,14 @@ export class SuggestModel implements IDisposable {
|
||||
wordDistance,
|
||||
this._editor.getConfiguration().contribInfo.suggest
|
||||
);
|
||||
|
||||
// store containers so that they can be disposed later
|
||||
for (const item of items) {
|
||||
if (isDisposable(item.container)) {
|
||||
this._completionDisposables.add(item.container);
|
||||
}
|
||||
}
|
||||
|
||||
this._onNewContext(ctx);
|
||||
|
||||
}).catch(onUnexpectedError);
|
||||
|
||||
Reference in New Issue
Block a user