Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File models get disposed when contents change on disk #20901

Closed
928PJY opened this issue Feb 20, 2017 · 14 comments
Closed

File models get disposed when contents change on disk #20901

928PJY opened this issue Feb 20, 2017 · 14 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug debt Code quality issues *duplicate Issue identified as a duplicate of another issue(s)
Milestone

Comments

@928PJY
Copy link

928PJY commented Feb 20, 2017

  • VSCode Version:1.8.1
  • OS Version:win10

Command "vscode.previewHtml" can only provide two ways to preview a Html resource.
The one is providing Url, but when the Html file changes, how to update the preview content? Is there some sample code?
The second is providing a virtual resource, but when I want to use some js files to render this Html, do I have to give the absolute path? If so, How can I do when js file reference to another js file(in this case, it have to be a relative path(?)).

@928PJY 928PJY mentioned this issue Feb 20, 2017
@928PJY
Copy link
Author

928PJY commented Feb 20, 2017

I am writing an extension which will preview the DFM, and what I want to preview is a virtual Html resource, this Html will reference to some js files(in relative path), but the VSCode will translate it into absolute path based on the markdown file, I fix this problem by translate the js files's path into absolute path, but when this js files reference to other files, I don't know how to do.Maybe you can provide some advice.

@928PJY
Copy link
Author

928PJY commented Feb 21, 2017

When I use the first ways to preview Html(provide a Uri), how to trigger the update event.

@jrieken jrieken added *question Issue represents a question, should be posted to StackOverflow (VS Code) webview Webview issues labels Feb 21, 2017
@jrieken
Copy link
Member

jrieken commented Feb 21, 2017

When the URI points to a file on disk and that file is inside the current workspace/folder updating happens automatically, when you are showing a virtual resource its content provider must signal changes via an event. Therefore a TextDocumentContentProvider can implement a onDidChange event which in return will be honoured by the editor. There is an example here: https://github.com/Microsoft/vscode-extension-samples/blob/master/previewhtml-sample/src/extension.ts#L20. Full sample: https://github.com/Microsoft/vscode-extension-samples/blob/master/previewhtml-sample/

@jrieken jrieken closed this as completed Feb 21, 2017
@928PJY
Copy link
Author

928PJY commented Feb 21, 2017

There is a small sample, it doesn't behavior as what you said.

@jrieken
Copy link
Member

jrieken commented Feb 21, 2017

Can you reduce that to something small and simple?

@928PJY
Copy link
Author

928PJY commented Feb 22, 2017

Yes! Sample is smaller!

@928PJY
Copy link
Author

928PJY commented Feb 22, 2017

I was writing an extension, which is going to preview DocFx. Extension pass the markdown content to a child process, which will use DocFx engine to render the markdown file into Html, this Html will be written to a temp file, which is the resource of preview page, But When this temp Html changed, Nothing happens to preview page.

@jrieken
Copy link
Member

jrieken commented Feb 22, 2017

Is this file inside the workspace or did you open the file by itself? Can you open it in source and check if it updates when it is changed on disk?

@928PJY
Copy link
Author

928PJY commented Feb 23, 2017

The situation is, this file is inside the workspace, but not be opened, and When it is changed by another editor or process, it can't update automatically.

@jrieken jrieken added bug Issue identified by VS Code Team member as probable bug and removed *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Feb 23, 2017
@jrieken jrieken self-assigned this Feb 23, 2017
@jrieken
Copy link
Member

jrieken commented Feb 23, 2017

Thanks for sticking with me. There is actually something wrong. The preview updates as long as the file also open in an editor and stops after that. I need to investigate..

@jrieken
Copy link
Member

jrieken commented Feb 23, 2017

This happens because the TextFileEditorModelManager decides to dispose the model instead of updating it.

// Dispose models that got changed and are not visible. We do this because otherwise
// cached file models will be stale from the contents on disk.

I don't understand that. There is the IModelService but this comment seems to talk about another cache. My expectation was that the workbench listens on file events, updates models (IModel) that are alive, such that listeners to that can do their work

@jrieken jrieken reopened this Feb 23, 2017
@jrieken jrieken assigned bpasero and unassigned jrieken Feb 23, 2017
@jrieken jrieken removed the webview Webview issues label Feb 23, 2017
@jrieken jrieken changed the title vscode.previewHtml IModel illegally disposed Feb 23, 2017
@bpasero bpasero modified the milestone: February 2017 Feb 23, 2017
@928PJY
Copy link
Author

928PJY commented Feb 24, 2017

Thank you for reopening this issue, I have already solved my problem through another way, but I still want to see this problem can be fixed, thank you!

@bpasero bpasero changed the title IModel illegally disposed File models get disposed when contents change on disk Feb 24, 2017
@bpasero bpasero modified the milestones: March 2017, February 2017 Feb 24, 2017
@bpasero
Copy link
Member

bpasero commented Feb 24, 2017

Related to #17888

I will revisit this in March given you seem to have a workaround and this is not a recent regression.

Btw we had #5687 open for a while which is the same issue.

@bpasero
Copy link
Member

bpasero commented Mar 1, 2017

I fixed the fact that we dispose models when file changes so that we now update the model with the new contents. However due to #17888 this is still not working properly but should be once #17888 is done.

@bpasero bpasero added the *duplicate Issue identified as a duplicate of another issue(s) label Mar 1, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug debt Code quality issues *duplicate Issue identified as a duplicate of another issue(s)
Projects
None yet
Development

No branches or pull requests

3 participants