src/vs/editor/contrib/snippet/browser/snippetSession.ts/SnippetSession/adjustWhitespace
class SnippetSession:	static adjustWhitespace(model: ITextModel, position: IPosition, snippet: TextmateSnippet, adjustIndentation: boolean, adjustNewlines: boolean): string {
		const line = model.getLineContent(position.lineNumber);
		const lineLeadingWhitespace = getLeadingWhitespace(line, 0, position.column - 1);

		// the snippet as inserted
		let snippetTextString: string | undefined;

		snippet.walk(marker => {
			// all text elements that are not inside choice
			if (!(marker instanceof Text) || marker.parent instanceof Choice) {
				return true;
			}

			const lines = marker.value.split(/\r\n|\r|\n/);

			if (adjustIndentation) {
				// adjust indentation of snippet test
				// -the snippet-start doesn't get extra-indented (lineLeadingWhitespace), only normalized
				// -all N+1 lines get extra-indented and normalized
				// -the text start get extra-indented and normalized when following a linebreak
				const offset = snippet.offset(marker);
				if (offset === 0) {
					// snippet start
					lines[0] = model.normalizeIndentation(lines[0]);

				} else {
					// check if text start is after a linebreak
					snippetTextString = snippetTextString ?? snippet.toString();
					const prevChar = snippetTextString.charCodeAt(offset - 1);
					if (prevChar === CharCode.LineFeed || prevChar === CharCode.CarriageReturn) {
						lines[0] = model.normalizeIndentation(lineLeadingWhitespace + lines[0]);
					}
				}
				for (let i = 1; i < lines.length; i++) {
					lines[i] = model.normalizeIndentation(lineLeadingWhitespace + lines[i]);
				}
			}

			const newValue = lines.join(model.getEOL());
			if (newValue !== marker.value) {
				marker.parent.replace(marker, [new Text(newValue)]);
				snippetTextString = undefined;
			}
			return true;
		});

		return lineLeadingWhitespace;
	}