How can I detect file change from outside in VSCode Extension? - visual-studio-code

I have a file foo.txt and open it with my Custom Editor Extension.
When my extension edit it, I can know the change by fire onDidChangeDocument Event.
But how can I know change from outside?
For example, I should update my web-view when some other program edit foo.txt.

You use a FileSystemWatcher.
Also read: FileSystemProvider.

Related

VS Code change file extension at file save as dialog

On some files I need to change standard save as file dialog.
I want to use custom command that executed 'workbench.action.files.saveLocalFile' command with some params that can change availible file extensions.
Where I can find the params if they exist?
Another way:
Custom command with showSaveDialog (my own vscode.SaveDialogOptions)
Close unsaved editor
Open saved file in editor
At step 2 I use 'workbench.action.closeActiveEditor' command, but I can see confirm dialog (Do you want to save the changes...)
How to remove this confirm?

How to open peek window in vscode from a program

I'm writing an extension for vscode, in typescript.
In the active editor, at a particular position, I want to open a peek window to display the content of a particular file. Like this one:
But I can't figure out how to do it. Is it possible? And how?
Since I found the answer I will post it here in case someone has similar needs.
The name of the built-in command to pop up a peek window is "editor.action.peekLocations". Here is the link to the source file where it is registered. The description in it was enough to make it work:
https://github.com/microsoft/vscode/blob/master/src/vs/editor/contrib/gotoSymbol/goToCommands.ts

How to get VSCode to "open as new file" from Go To File dialog

I have recently switched to VSCode, and am loving it, except for one specific thing that drives me nuts.
My "goto" command is {Command+P}, the easy search-and-open-file bar. If I type the name of a file into this bar and it does not exist, I want to be able to hit ENTER and have it open a tab editing that file as a new file. This is the behavior I would get in old-school Windows Notepad, or in mvim :e <filename>, but I can't figure out how to do it in VSCode.
Is there a toggle or a plugin I can use to get this behavior straight out of the Go To File dialog?
Answering my own question:
No, there's no way to do this using {Command+P}. This is strictly a file finder and I've yet to see any plugin that changes the behavior.
If you're using the VsCodeVim plugin, an almost-as-good approach is just :e <file> - immediately open a new buffer editing the given file. There's no tab autocomplete this way, but you just have to live with that.

How to change open with options in navigator depending upon name of the resource?

I am working on eclipse RCP application which implements CommonNavigator view to display navigator. I have few LinkedResources in navigator that link to files on the file system with custom extension. These custom extension files are opened in custom editor as well as in TextEditor.
One of the file named default.ext will be common to all the projects and I want to keep it read only. Is it possible to open file in custom editor only? For ex. Default.ext should be opened in only custom editor, however Test.ext should be opened in custom editor as well as text editor.
This way I could handle save action in my editor depending upon file name and keep the file read only.
Is there any other way to keep files read only?
Short answer: not possible in the way you describe.
Long answer: if somebody really wants to modify a file then there's no way or need to stop this. What you can do is either (1) hide the file from user or (2) set Read-only flag to discourage users from modifying the file.

it is possible to intercept the Open File menu in eclipse?

My project require to open a file with specified extension in eclipse, but not in a editor. the file should be open in a embedded QT application in a view of eclipse.
my thinking is trying to intercept the open file action in eclipse, and if the file extension is the one i am interesting, then I get the view embedded, and ask it to open the file.
the question is I does NOT find any extension to allow me to hook the Open File ... menu. I debug the eclipse editor, I find there is a IOpenListener which seems to be responsible for open file, I didnot try it.
is there a good way to do this.
I don't think you can associate a view with a file type. You'll have to use an editor, as editors are associated with a file; views are not.
In your plugin.xml, add the org.eclipse.ui.editors extension, and then add an editor to it. Specify the file extension(s) it should handle in the 'extensions' element, along with the name, id, class, etc. of the editor you want to open it with.
If you absolutely must use a view, you could provide a way to open a file from within the view itself. Depending on what you're doing, this will probably be deviating from Eclipse UI guidelines.