I am writing a Vscode FTP extension following this example.
My problem is that it seems that provideTextDocumentContent
only gets called once per file.. opening the file again does not recall the function. Instead it just shows you the content already loaded.
Refer to code below:
public provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult<string> {
console.log('uri.path');
return this.model.getContent(uri).then(content => content);
}
and these are my results when clicking items on my View
log=> '/index.cfml' // Clicked on index.cfml
log=> '/login.cfml' // Clicked on login.cfml
log=> // Clicked on index.cfml
log=> // Clicked on login.cfml
log=> '/signup.cfml' // Clicked on signup.cfml
Expected results would be:
log=> '/index.cfml' // Clicked on index.cfml
log=> '/login.cfml' // Clicked on login.cfml
log=> '/index.cfml' // Clicked on index.cfml
log=> '/login.cfml' // Clicked on login.cfml
log=> '/signup.cfml' // Clicked on signup.cfml
As you can see provideTextDocumentContent
gets called the first time I click on an item but the second time I click on the same item it does not get called. Any idea why this is happening or how I could force vscode to call it for every click?
EDIT:
I currently have an onDidChange
event at the top of my data provider but the implementation may be wrong. Below is a rundown of what my data provider looks like.
export class FtpTreeDataProvider implements vscode.TreeDataProvider<FtpNode>, vscode.TextDocumentContentProvider {
private _onDidChangeTreeData: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
readonly onDidChangeTreeData: vscode.Event<any> = this._onDidChangeTreeData.event;
constructor(private readonly model: FtpModel){ }
public refresh(): any {
this._onDidChangeTreeData.fire();
}
public getTreeItem(element) {/*some code*/}
public getChildren(element) {/*some code*/}
public getParent(element) {/*some code*/}
public provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult<string> {
console.log(uri.path);
return this.model.getContent(uri);
}
VS Code will reuse the provided content as long as the document is open. Switching away from a document closes its editor but does close the document itself. If you fully close the document (in all tabs), you should see the provider invoked when you open a new document.
If you wish to update an existing document's content, implement the onDidChange
event on TextDocumentContentProvider
and use it to signal that VS Code should call provideTextDocumentContent
As @Matt Bierner said:
"If you wish to update an existing document's content, implement the onDidChange event on TextDocumentContentProvider and use it to signal that VS Code should call provideTextDocumentContent"
My problem was that I had to fire() _onDidChange
with an uri.
I ended up adding this line to my getTreeItem
method:
this._onDidChange.fire(element.resource);
now each item is freshly downloaded on opening.
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