在VSCode中获取当前打开的文件

时间:2016-04-04 23:52:49

标签: typescript visual-studio-code vscode-extensions

vscode命名空间中是否有命令允许您获取当前打开文件的TextDocument实例?我找到了vscode.workspace.onDidOpenTextDocument,但它对于在启动时打开的文件不起作用

1 个答案:

答案 0 :(得分:0)

根据您的需求选择一些选项:

// Single active editor. Editors have a `.document` property
vscode.window.activeTextEditor

// All showing text editors. For a split view, there are two active editors 
vscode.window.visibleTextEditors

// All open documents that vscode knows about. Do not have to be showing
vscode.workspace.textDocuments

有关详细信息,请参阅vscode API:https://code.visualstudio.com/docs/extensionAPI/vscode-api