1

I made my TextDocumentContentProvider for virtual documents. I'm generating the content of the file on the go, and it looks like VS Code is caching the content of the file. This is a problem for me. I expect to see a new number in the text of the document every time. Does anyone know how to get around this without using random numbers in the filename?

const vscode = require('vscode');

class MyVirtualDocument {
    constructor() {
        this.onDidChangeEmitter = new vscode.EventEmitter();
        this.onDidChange = this.onDidChangeEmitter.event;
    }
    provideTextDocumentContent(uri) {
       return "Test String for uri: " + uri.path + "\nRandom number: " + Math.floor(Math.random() * 65535) + ".";
    }
};

function activate(context)
{
    context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider('myvirtualdocument', new MyVirtualDocument()));

    context.subscriptions.push(vscode.commands.registerCommand('myvirtualdocument.open', () => {
        vscode.workspace.openTextDocument(vscode.Uri.parse('myvirtualdocument:1.txt')).then(doc => {
             vscode.window.showTextDocument(doc, { preview: true });
        });
    }));
}

function deactivate(){}
module.exports = {activate, deactivate}

0 Answers0