Repository: vscode
Issue: DocumentSemanticTokensProvider fails for the first untitled editor created with showTextDocument since v1.76
Labels: bug,semantic-tokens

I've been developing a VSCode extension to syntax highlight a language using [semantic highlight](https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide), and I've noticed that `vscode.DocumentSemanticTokensProvider.provideDocumentSemanticTokens` is never called for the untitled document created by `vscode.window.showTextDocument(await vscode.workspace.openTextDocument(...))` if the created untitled document is the first document created after opening a window.

The issue does not exist in VSCode v1.60-v1.75 but it does exist in v1.76-1.81 (current version).

Here is a minimal reproducible code. A .vsix file is also included in it.
[semantic-highlight-test-2.zip](https://github.com/microsoft/vscode/files/12436593/semantic-highlight-test-2.zip)

extension.js
```js
const vscode = require("vscode")

exports.activate = (/** @type {vscode.ExtensionContext} */context) => {
    const legend = new vscode.SemanticTokensLegend(["keyword"])
    context.subscriptions.push(
        // Highlight the entire file of languageId "test-lang" as "keyword"
        vscode.languages.registerDocumentSemanticTokensProvider({ language: "test-lang" }, {
            provideDocumentSemanticTokens(document) {
                const builder = new vscode.SemanticTokensBuilder(legend)
                for (let i = 0; i < document.lineCount; i++) {
                    builder.push(document.lineAt(i).range, "keyword")
                }
                return builder.build()
            }
        }, legend),

        // Register "semantic-highlighting-test", which opens a new document with languageId "test-lang"
        vscode.commands.registerCommand("semantic-highlighting-test", async () => {
            await vscode.window.showTextDocument(await vscode.workspace.openTextDocument({
                language: "test-lang",
                content: "foo\nbar"
            }))
        }),
    )
}
```

package.json
```json
{
	"name": "semantic-highlighting-test",
	"displayName": "semantic-highlighting-test",
	"description": "",
	"version": "1.0.0",
	"publisher": "test",
	"engines": {
		"vscode": "^1.60.0"
	},
	"activationEvents": [
		"onCommand:semantic-highlighting-test",
		"onLanguage:test-lang"
	],
	"main": "./extension.js",
	"browser": "./extension.js",
	"contributes": {
		"commands": [
			{
				"command": "semantic-highlighting-test",
				"title": "semantic-highlighting-test"
			}
		],
		"languages": [
			{
				"id": "test-lang"
			}
		],
		"configurationDefaults": {
			"[test-lang]": {
				"editor.semanticHighlighting.enabled": true
			}
		}
	},
	"scripts": {},
	"devDependencies": {
		"@types/vscode": "^1.60.0",
		"@vscode/vsce": "^2.20.1"
	}
}
```

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.76.2, 1.77.3, 1.81.1  (the bug does not exist in 1.75.1)
- OS Version: Windows 11, Ubuntu 22.04

Steps to Reproduce:

1. Open VSCode.
2. Install the extension.
3. Close the VSCode window.
4. Reopen a VSCode window.
5. Open a folder (this step is necessary to prevent VSCode from opening an untitled editor on startup).
6. Close all editor tabs.
7. Close the VSCode window.
8. Reopen a VSCode window. At this point, there should be no editor tabs.
9. Execute "semantic-highlighting-test" from the command palette 

Screencast:

[recording.webm](https://github.com/microsoft/vscode/assets/54441600/09bdf0fb-0c06-4662-aabe-f152e3c65811)