src/vs/editor/contrib/snippet/browser/snippetController2.ts/SnippetController2/_doInsert
class SnippetController2:	private _doInsert(
		template: string,
		opts: ISnippetInsertOptions
	): void {
		if (!this._editor.hasModel()) {
			return;
		}

		// don't listen while inserting the snippet
		// as that is the inflight state causing cancelation
		this._snippetListener.clear();

		if (opts.undoStopBefore) {
			this._editor.getModel().pushStackElement();
		}

		if (!this._session) {
			this._modelVersionId = this._editor.getModel().getAlternativeVersionId();
			this._session = new SnippetSession(this._editor, template, opts, this._languageConfigurationService);
			this._session.insert();
		} else {
			this._session.merge(template, opts);
		}

		if (opts.undoStopAfter) {
			this._editor.getModel().pushStackElement();
		}

		// regster completion item provider when there is any choice element
		if (this._session?.hasChoice) {
			this._choiceCompletionItemProvider = {
				provideCompletionItems: (model: ITextModel, position: Position) => {
					if (!this._session || model !== this._editor.getModel() || !Position.equals(this._editor.getPosition(), position)) {
						return undefined;
					}
					const { activeChoice } = this._session;
					if (!activeChoice || activeChoice.options.length === 0) {
						return undefined;
					}

					const info = model.getWordUntilPosition(position);
					const isAnyOfOptions = Boolean(activeChoice.options.find(o => o.value === info.word));
					const suggestions: CompletionItem[] = [];
					for (let i = 0; i < activeChoice.options.length; i++) {
						const option = activeChoice.options[i];
						suggestions.push({
							kind: CompletionItemKind.Value,
							label: option.value,
							insertText: option.value,
							sortText: 'a'.repeat(i + 1),
							range: new Range(position.lineNumber, info.startColumn, position.lineNumber, info.endColumn),
							filterText: isAnyOfOptions ? `${info.word}_${option.value}` : undefined,
							command: { id: 'jumpToNextSnippetPlaceholder', title: localize('next', 'Go to next placeholder...') }
						});
					}
					return { suggestions };
				}
			};

			const registration = this._languageFeaturesService.completionProvider.register({
				language: this._editor.getModel().getLanguageId(),
				pattern: this._editor.getModel().uri.path,
				scheme: this._editor.getModel().uri.scheme
			}, this._choiceCompletionItemProvider);

			this._snippetListener.add(registration);
		}

		this._updateState();

		this._snippetListener.add(this._editor.onDidChangeModelContent(e => e.isFlush && this.cancel()));
		this._snippetListener.add(this._editor.onDidChangeModel(() => this.cancel()));
		this._snippetListener.add(this._editor.onDidChangeCursorSelection(() => this._updateState()));
	}