【问题标题】:Getting the currently open file in VSCode在 VSCode 中获取当前打开的文件
【发布时间】:2016-07-24 17:05:44
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    几个选项取决于您的需要:

    // 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

    【讨论】:

    • 谢谢,它有帮助:)
    • 我想将当前在编辑器中打开的文件的文件位置打印到终端。我可以从您链接的 api 中获取命令的信息吗?示例:我有一个想要共享的扩展配置文件。我看到该位置悬停在编辑器和面包屑中的选项卡上。我想要这个位置字符串来复制它。
    猜你喜欢
    • 2022-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-18
    • 2017-06-20
    • 1970-01-01
    • 2022-06-13
    相关资源
    最近更新 更多