I'm working on a VSCode extension that registers a TextDocumentContentProvider to provide a custom read-only viewer for certain Azure resources. I have it working the way I want except for one weird behavior. I can't get VSCode to open multiple editors for different urls. Calling vscode.window.showTextDocument() when there is already an editor displaying one of my documents always closes the current document before editing the new one. This does not occur with normal files.
Specifically, this sequence:
doc1 = await vscode.workspace.openTextDocument( "file1.txt" );
edit1 = await vscode.window.showTextDocument( doc1, undefined, true );
doc2 = await vscode.workspace.openTextDocument( "file2.txt" );
edit2 = await vscode.window.showTextDocument( doc2, undefined, true );
always results in two edit windows/tabs displaying the contents of each file as expected, whereas this sequence:
doc1 = await vscode.workspace.openTextDocument( <url1> );
edit1 = await vscode.window.showTextDocument( doc1, undefined, true );
doc2 = await vscode.workspace.openTextDocument( <url2> );
edit2 = await vscode.window.showTextDocument( doc2, undefined, true );
always results in only one edit window/tab displaying the contents associated with url2.
Stepping through in the debugger confirms that the second showTextDocument() call closes the first document and displays the second one in the same edit window/tab.
Is there some additional capability or configuration I need to add to my provider to allow multiple documents to be open concurrently? Can anyone shed some light?
By default, VS Code opens new text documents in preview mode. This means that when the second document is opened, it replaces the first one that was opened.
You can fully open the document by setting preview: false in the TextDocumentShowOptions that are passed to showTextDocument
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With