mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
only activate snippet choice completion provider when at a choice element (#184174)
fixes https://github.com/microsoft/vscode/issues/180069
This commit is contained in:
parent
3062c19c90
commit
3e232a82df
|
@ -4,7 +4,7 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
|
||||||
import { assertType } from 'vs/base/common/types';
|
import { assertType } from 'vs/base/common/types';
|
||||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||||
import { EditorCommand, EditorContributionInstantiation, registerEditorCommand, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
|
import { EditorCommand, EditorContributionInstantiation, registerEditorCommand, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
|
||||||
|
@ -66,7 +66,7 @@ export class SnippetController2 implements IEditorContribution {
|
||||||
private _modelVersionId: number = -1;
|
private _modelVersionId: number = -1;
|
||||||
private _currentChoice?: Choice;
|
private _currentChoice?: Choice;
|
||||||
|
|
||||||
private _choiceCompletionItemProvider?: CompletionItemProvider;
|
private _choiceCompletions?: { provider: CompletionItemProvider; enable(): void; disable(): void };
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _editor: ICodeEditor,
|
private readonly _editor: ICodeEditor,
|
||||||
|
@ -156,7 +156,7 @@ export class SnippetController2 implements IEditorContribution {
|
||||||
|
|
||||||
// regster completion item provider when there is any choice element
|
// regster completion item provider when there is any choice element
|
||||||
if (this._session?.hasChoice) {
|
if (this._session?.hasChoice) {
|
||||||
this._choiceCompletionItemProvider = {
|
const provider = {
|
||||||
provideCompletionItems: (model: ITextModel, position: Position) => {
|
provideCompletionItems: (model: ITextModel, position: Position) => {
|
||||||
if (!this._session || model !== this._editor.getModel() || !Position.equals(this._editor.getPosition(), position)) {
|
if (!this._session || model !== this._editor.getModel() || !Position.equals(this._editor.getPosition(), position)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -185,14 +185,29 @@ export class SnippetController2 implements IEditorContribution {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const registration = this._languageFeaturesService.completionProvider.register({
|
const model = this._editor.getModel();
|
||||||
language: this._editor.getModel().getLanguageId(),
|
|
||||||
pattern: this._editor.getModel().uri.fsPath,
|
let registration: IDisposable = Disposable.None;
|
||||||
scheme: this._editor.getModel().uri.scheme,
|
let isRegistered = false;
|
||||||
exclusive: true
|
const disable = () => {
|
||||||
}, this._choiceCompletionItemProvider);
|
registration.dispose();
|
||||||
|
isRegistered = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const enable = () => {
|
||||||
|
if (!isRegistered) {
|
||||||
|
registration = this._languageFeaturesService.completionProvider.register({
|
||||||
|
language: model.getLanguageId(),
|
||||||
|
pattern: model.uri.fsPath,
|
||||||
|
scheme: model.uri.scheme,
|
||||||
|
exclusive: true
|
||||||
|
}, provider);
|
||||||
|
isRegistered = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this._snippetListener.add(registration);
|
this._snippetListener.add(registration);
|
||||||
|
this._choiceCompletions = { provider, enable, disable };
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updateState();
|
this._updateState();
|
||||||
|
@ -239,7 +254,8 @@ export class SnippetController2 implements IEditorContribution {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { activeChoice } = this._session;
|
const { activeChoice } = this._session;
|
||||||
if (!activeChoice || !this._choiceCompletionItemProvider) {
|
if (!activeChoice || !this._choiceCompletions) {
|
||||||
|
this._choiceCompletions?.disable();
|
||||||
this._currentChoice = undefined;
|
this._currentChoice = undefined;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -247,9 +263,11 @@ export class SnippetController2 implements IEditorContribution {
|
||||||
if (this._currentChoice !== activeChoice.choice) {
|
if (this._currentChoice !== activeChoice.choice) {
|
||||||
this._currentChoice = activeChoice.choice;
|
this._currentChoice = activeChoice.choice;
|
||||||
|
|
||||||
|
this._choiceCompletions.enable();
|
||||||
|
|
||||||
// trigger suggest with the special choice completion provider
|
// trigger suggest with the special choice completion provider
|
||||||
queueMicrotask(() => {
|
queueMicrotask(() => {
|
||||||
showSimpleSuggestions(this._editor, this._choiceCompletionItemProvider!);
|
showSimpleSuggestions(this._editor, this._choiceCompletions!.provider);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue