I have an extension in which I query the source path of the current active tab file.
For textual files, the following works great:
const activeEditor: TextEditor = window.activeTextEditor;
if (activeEditor && activeEditor.document && activeEditor.document.fileName) {
return activeEditor.document.fileName;
}
Problem is, this doesn't work when the active file in the text editor is non-textual, for example an image file such as a .jpg.
For these types of files, window.activeTextEditor is undefined. Moreover, when I try running the following code:
const uri = Uri.file(<path_to_binary_file>);
workspace.openTextDocument(uri);
I receive the following error: "cannot open <path_to_file>. Detail: File seems to be binary and cannot be opened as text", and I don't see any similar API to openTextDocument that deals with non-textual files.
Is there any straightforward way of obtaining this data without using commands.executeCommand('workbench.action.files.copyPathOfActiveFile') and various clipboard manipulations?
It seems that this is a known open issue in VS code. The following Github issue discusses it.
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