简体   繁体   English

VSCode 扩展 - 访问时间轴选项卡

[英]VSCode extension - access timeline tab

Is there a way for a VSCode extension to access the timeline tab?有没有办法让 VSCode 扩展访问时间轴选项卡? I searched the docs but I couldn't find anything?我搜索了文档,但找不到任何东西?

To be more specific, I'd like to watch for changes in certain files and get the diff of that change.更具体地说,我想观察某些文件的变化并获得该变化的差异。 I managed to register a listener on file changes, but I also want the actual change.我设法在文件更改时注册了一个侦听器,但我也想要实际的更改。 This is what I have so far:这是我到目前为止所拥有的:

const vscode = require("vscode");

function activate(context) {
  const workspacePath = vscode.workspace.workspaceFolders[0];
  const watcher = vscode.workspace.createFileSystemWatcher(
    new vscode.RelativePattern(workspacePath, "**/package.json")
  );
  
  watcher.onDidChange((e) => {
    console.log(e); # this only prints the file path, not the content.
  }
}

module.exports = {activate};

There is no Timeline API available yet.目前还没有可用的时间轴 API。 There is however, a proposed API being discussed for a while ( https://github.com/microsoft/vscode/issues/84297 ), but the last comment is one year old.然而,有一个提议的 API正在讨论一段时间( https://github.com/microsoft/vscode/issues/84297 ),但最后一条评论是一年前的。

But, if you need to detect file changes (not necessarily the file being edited by the user, but any file in the workspace) and compare its content, you need not only the FileSystemWatcher but also some lib that provides you text differencing algorithm, like jsdiff .但是,如果您需要检测文件更改(不一定是用户正在编辑的文件,而是工作区中的任何文件)并比较其内容,您不仅需要FileSystemWatcher ,还需要一些为您提供文本差异算法的库,例如差异

Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM