extensions/typescript-language-features/src/ui/jsNodeWalkthrough.electron.ts/tryFindRelevantDocument
function tryFindRelevantDocument(lastDocument: vscode.TextDocument | undefined, languageId: string, languageExtension: string): DocSearchResult {
	let editor: vscode.TextEditor | undefined;

	// Try to find the document created from the last step.
	if (lastDocument) {
		editor = vscode.window.visibleTextEditors.find(editor => editor.document === lastDocument);
	}

	// If we couldn't find that, find a visible document with the desired language.
	editor ??= vscode.window.visibleTextEditors.find(editor => editor.document.languageId === languageId);
	if (editor) {
		return {
			kind: 'visible',
			editor,
		};
	}

	// If we still couldn't find that, find a possibly not-visible document.
	for (const tabGroup of vscode.window.tabGroups.all) {
		for (const tab of tabGroup.tabs) {
			if (tab.input instanceof vscode.TabInputText && tab.input.uri.path.endsWith(languageExtension)) {
				return {
					kind: 'hidden',
					uri: tab.input.uri,
				};
			}
		}
	}

	return { kind: 'not-found' };
}