VScode 中带有上次修改时间的自动 JSDoc 风格注释

问题描述 投票:0回答:1

在 Sublime text 中,有一些选项或者插件可以让你将其放在文件的顶部:

/**
 *@Last Modified Time: 
 */

每当您保存文件时,它都会在其中添加实际时间

非常有用

如何在 vscode 中获得相同的功能?

visual-studio-code jsdoc
1个回答
0
投票

我做了一个扩展来做到这一点。请参阅插入上次修改时间

使用它,您可以在“设置 UI”中创建一个模板,其中包含所需的插入内容,这将在

settings.json
中创建一个设置,例如:

"insertLastModifiedTime.template": "/**\n *@Last Modified Time: %% LMT %%\n */",

您只需在模板中的某个位置添加

%% LMT %%
以获取实际时间。

您可以选择要在以下设置中显示的日期和时间选项:

  "insertLastModifiedTime.options": {
    "locales": "en-US",
    "timeStyle": "full",
    "dateStyle": "full",
    
    "timeZone": "CET"
  }

或者使用

MDN 中的其他 
Intl.DateTimeFormat() 选项:Intl.DateTimeFormat() 选项

您可以设置键绑定以手动插入上次修改时间,或者为了在每次保存时自动触发它,您还可以创建另一个设置:

"[javascript][typescript]": {     // to restrict to these file types
  "editor.codeActionsOnSave": [
    "source.insert-last-modified-time.insertTimeTop"   // all commands must start with "source."
  ]
}

演示(在打字稿文件中,只需保存文件):

让我知道它是否按您想要的方式工作。

© www.soinside.com 2019 - 2024. All rights reserved.