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

Explicitly refresh active text editor from extension api. #7532

Closed
bmingles opened this issue Jun 10, 2016 · 13 comments
Closed

Explicitly refresh active text editor from extension api. #7532

bmingles opened this issue Jun 10, 2016 · 13 comments
Labels
api feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Milestone

Comments

@bmingles
Copy link

There doesn't appear to be any way to explicitly refresh the active text editor. This would be useful for extensions that modify files via external commands and need to show the latest version once said command completes.

@alexdima
Copy link
Member

@bmingles Would window.showTextDocument help here ?

@sandy081 sandy081 added the feature-request Request for new features or functionality label Jun 14, 2016
@bpasero
Copy link
Member

bpasero commented Jun 14, 2016

There is an option for opening editors to forceOpen which will reload the file from disk. Assuming we do not want to make this extension API, an alternative would be to add a command for this.

/cc @jrieken

@bpasero bpasero added the api label Jun 14, 2016
@bpasero bpasero added this to the Backlog milestone Jun 14, 2016
@jrieken
Copy link
Member

jrieken commented Jun 14, 2016

@bpasero Isn't this a case for file events?

@bpasero
Copy link
Member

bpasero commented Jun 14, 2016

@jrieken yeah though all the bugs I have on file events show me that they do not work in all cases ;-)

@bpasero
Copy link
Member

bpasero commented Jun 14, 2016

Actually in this case what could bite is the fact that I ignore file change events on the currently edited file for a short period because otherwise I would reload the file every time you made a modification.

@bmingles is this a possible explanation that the text content is rapidly changed after the user saved? what is the use case for the extension?

@bmingles
Copy link
Author

bmingles commented Jun 19, 2016

@bpasero I have an extension that can run arbitrary shell commands whenever a user saves a file (using vscode.workspace.onDidSaveTextDocument). I have some users of the extension that are running commands that modify the source file after save and are asking if it could update the active file after the commands run. The goal would be to explicitly refresh it in the extension after commands run and not based on change detection on the source file.

@SteveLemire
Copy link

My current version of VS code is 1.11.1 and got the same issue.

I noticed that the VS code editor do not refresh when an external program update a file (copy, save, etc). If the opened file is currently focused in the editor and change externally, it does not refresh.

The workaround to refresh the opened and focused file in VS code is to select another opened file and get back to the edited/updated opened file.

Steps to reproduce:

  • Open a file in VS Code.
  • Open the same file in Notepass++, change it and save it.
  • Get back to VS Code.

Expected result: The change is visible in VS Code.

I found this while trying to debug a file under the node_module that is copied from another server package during the build process.

Please, give us a solution to automatically refresh opened and focused file in VS Code editor when an external program change it.

@bmingles
Copy link
Author

bmingles commented May 8, 2017

@slemireOmni To clarify, it sounds like you are asking for a different feature, one that responds to a file system change or something external to vscode. The feature I am requesting here is for extension developers to be able to explicitly trigger a refresh via a vscode extension through an api of some sort.

@bpasero bpasero removed the workbench label Nov 16, 2017
@alekstheod
Copy link

alekstheod commented Jan 29, 2019

Is it still open? Any solution to that? It is really annoying I can't use any formatting tools as vscode get out of sync with the formatted files.

@bmingles
Copy link
Author

bmingles commented Feb 1, 2019

@bpasero Has there been anything added to the extension api that would facilitate this,

@bpasero
Copy link
Member

bpasero commented Feb 4, 2019

There is no official API yet (hence this issue is still open).

The only workaround to force refresh the active file from disk is to call our internal command workbench.action.files.revert, e.g. by doing vscode.commands.executeCommand('workbench.action.files.revert'). If the file is dirty, this will remove any made changes by the user though.

@bmingles
Copy link
Author

bmingles commented Feb 4, 2019

Ok, that may be a good workaround for some synchronous use cases.

Now that I think about it, I guess that would be a challenge of any sort of refresh from disk scenario if it is possible for the user to make changes before it runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

8 participants
@bpasero @alekstheod @jrieken @bmingles @alexdima @sandy081 @SteveLemire and others