microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.49k stars 28.1k forks source link

vscode.TextDocumentContentProvider providers don't get updated as extensions get activated. #211116

Open gcampbell-msft opened 2 months ago

gcampbell-msft commented 2 months ago

Does this issue occur when all extensions are disabled?: Yes/No

Steps to Reproduce:

Follow the repro steps for this bug: https://github.com/microsoft/vscode-cmake-tools/issues/3651. This is the root bug that I was investigating that caused me to create this.

I think I've noticed the issue.

Effectively, if you open the folder WITHOUT the CMakePresets.json file open. Then, perform an action that activates the CMake Tools extension, THEN open up the CMakePresets.json file, since the provider is already activated, the provideTextDocumentContent method that the CMake Tools extension provides will get called.

However, if you open the CMakePresets.json file BEFORE the CMake Tools extension is activated, even after activating the CMake Tools extension and closing an reopening the CMakePresets.json file, the validation still fails.

This makes me think that the provideTextDocumentContent isn't being called again for new providers when extensions are activated.

Technically we could fix this by adding an onFileSystem:cmake-tools-schema activationEvent, but I'm not sure yet whether we want to do this.

Thanks

jrieken commented 2 months ago

Follow the repro steps for this bug: https://github.com/microsoft/vscode-cmake-tools/issues/3651. This is the root bug that I was investigating that caused me to create this.

Sorry, I cannot go through that. Minimal repro steps welcome.

This makes me think that the provideTextDocumentContent isn't being called again for new providers when extensions are activated.

Can you provide more context? Is the CMakePresets.json-file a real file on disk or where does it come from? Also, who is provide its contents in case your extension hasn't been activated yet.

Generally, "yes" we don't call provideTextDocumentContent again if the document is already open and "owned" by another provider

gcampbell-msft commented 2 months ago

@jrieken CMakePresets.json is a real file. My expectation is that it wouldn't be owned by another provider except for when our extension is activated.

Minimal repro steps:

  1. Open an empty folder
  2. Ensure the CMake Tools extension is installed.
  3. Create a CMakePresets.json file with the contents of "{}".
  4. Notice that there is a warning at the top saying it couldn't load the schema.
  5. Run the "CMake: Configure" command to activate the cmake tools extension.
  6. The schema issue doesn't go away even though it's activated now.

This is where I would slightly expect that when we provide the schema provider, it would get re-called and it would resolve.

To see how our extension does provide the schema:

  1. In the same project as above, close the CMakePresets.json file.
  2. Close VS Code.
  3. Open VS Code.
  4. Run "CMake: Configure" command to activate CMake Tools extension.
  5. Open CMakePresets.json
  6. Notice that schema is correctly loaded.
jrieken commented 2 months ago

Notice that there is a warning at the top saying it couldn't load the schema.

So, you register a text document content provider for the schema, not for the file itself. But the schema-uri is passed through some other way, right?

gcampbell-msft commented 2 months ago

Correct.

I'm not 100% sure I understand your question. But the CMake Tools extension uses the package.json jsonValidation entry to associate the files with the schema-uri