I'm trying to determine if the active editor is opened by git or not (i.e. files that typically end in Working Tree, Untracked, etc)
There is little difference in vscode.window.activeTextEditor
from the original file vs the same file opened from git with the modifications view, save for one field:
(vscode.window.activeTextEditor as any).id
Which returns a string like this:
'vs.editor.ICodeEditor:1,$model12' // value for normal editor
'vs.editor.ICodeEditor:7,$model12' // value for git editor
The value 7
returned for ICodeEditor
will be consistent across all editors within a particular vscode instance, but changes depending on what editors are available.
So I'm trying to translate the magic number 7
(in this one particular case) to the EditorType
In the source code, there's an editorBrowser
which has the following function:
export function isDiffEditor(thing: any): thing is IDiffEditor {
if (thing && typeof (<IDiffEditor>thing).getEditorType === 'function') {
return (<IDiffEditor>thing).getEditorType() === editorCommon.EditorType.IDiffEditor;
} else {
return false;
}
}
And editorCommon
has an EditorType
:
export const EditorType = {
ICodeEditor: 'vs.editor.ICodeEditor',
IDiffEditor: 'vs.editor.IDiffEditor'
};
But I cannot figure out how to access any of that information from within the context of an extension.
Even window.activeTextEditor
which returns type TextEditor
doesn't explicitly offer up fields like id
(which is why I had to cast to any above). So some of the internals here might not show up in the docs / public facing interfaces.