src/vs/editor/contrib/snippet/browser/snippetSession.ts/SnippetSession/createEditsAndSnippetsFromEdits
class SnippetSession:	static createEditsAndSnippetsFromEdits(editor: IActiveCodeEditor, snippetEdits: ISnippetEdit[], enforceFinalTabstop: boolean, adjustWhitespace: boolean, clipboardText: string | undefined, overtypingCapturer: OvertypingCapturer | undefined, languageConfigurationService: ILanguageConfigurationService): { edits: IIdentifiedSingleEditOperation[]; snippets: OneSnippet[] } {

		if (!editor.hasModel() || snippetEdits.length === 0) {
			return { edits: [], snippets: [] };
		}

		const edits: IIdentifiedSingleEditOperation[] = [];
		const model = editor.getModel();

		const parser = new SnippetParser();
		const snippet = new TextmateSnippet();

		// snippet variables resolver
		const resolver = new CompositeSnippetVariableResolver([
			editor.invokeWithinContext(accessor => new ModelBasedVariableResolver(accessor.get(ILabelService), model)),
			new ClipboardBasedVariableResolver(() => clipboardText, 0, editor.getSelections().length, editor.getOption(EditorOption.multiCursorPaste) === 'spread'),
			new SelectionBasedVariableResolver(model, editor.getSelection(), 0, overtypingCapturer),
			new CommentBasedVariableResolver(model, editor.getSelection(), languageConfigurationService),
			new TimeBasedVariableResolver,
			new WorkspaceBasedVariableResolver(editor.invokeWithinContext(accessor => accessor.get(IWorkspaceContextService))),
			new RandomBasedVariableResolver,
		]);

		//
		snippetEdits = snippetEdits.sort((a, b) => Range.compareRangesUsingStarts(a.range, b.range));
		let offset = 0;
		for (let i = 0; i < snippetEdits.length; i++) {

			const { range, template } = snippetEdits[i];

			// gaps between snippet edits are appended as text nodes. this
			// ensures placeholder-offsets are later correct
			if (i > 0) {
				const lastRange = snippetEdits[i - 1].range;
				const textRange = Range.fromPositions(lastRange.getEndPosition(), range.getStartPosition());
				const textNode = new Text(model.getValueInRange(textRange));
				snippet.appendChild(textNode);
				offset += textNode.value.length;
			}

			parser.parseFragment(template, snippet);
			snippet.resolveVariables(resolver);

			const snippetText = snippet.toString();
			const snippetFragmentText = snippetText.slice(offset);
			offset = snippetText.length;

			// make edit
			const edit: IIdentifiedSingleEditOperation = EditOperation.replace(range, snippetFragmentText);
			edit.identifier = { major: i, minor: 0 }; // mark the edit so only our undo edits will be used to generate end cursors
			edit._isTracked = true;
			edits.push(edit);
		}

		//
		parser.ensureFinalTabstop(snippet, enforceFinalTabstop, true);

		return {
			edits,
			snippets: [new OneSnippet(editor, snippet, '')]
		};
	}