【问题标题】:VSCode snippets refresh required after change?更改后需要刷新 VSCode 片段吗?
【发布时间】:2020-01-22 12:10:07
【问题描述】:

换了一个用户sn-p后,我想用它。

除了重启VSCode还有其他方法可以更新sn-ps吗?

【问题讨论】:

  • 保存 sn-p 文件的那一刻,sn-p 处于活动状态
  • 我在一个系统上看到了这个,但在另一个系统上没有。所以我仍在调查 - 在这个系统中的 vscode 中似乎有一些其他的行为。
  • 如果您在保存文件后似乎没有更新,file an issue

标签: visual-studio-code vscode-snippets


【解决方案1】:

只需保存 sn-p 文件。

如果还是不行,按Ctrl +Shift + P,输入reload window 然后回车。

【讨论】:

  • 这对我有用。
【解决方案2】:

当我将 sn-p 放入错误的 Snippet 文件时,我遇到了这个问题。例如,我想写一个新的 sn-p 来创建一个 React 函数组件,如下所示:

{
    // Place your snippets for typescriptreact here. Each snippet is defined under a snippet name and has a prefix, body and
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
    // same ids are connected.
    // Example:
    // "Print to console": {
    //  "prefix": "log",
    //  "body": [
    //      "console.log('$1');",
    //      "$2"
    //  ],
    //  "description": "Log output to console"
    // }
    "React Function Component": {
        "prefix": "reactfc",
        "body": [
            "export type ${2:Props} = {",
            "};",
            "",
            "export const ${1:Component}: React.FC<${2:Props}> = props => {",
            "  return (",
            "    <>$0</>",
            "  );",
            "};"
        ],
        "description": "Create a new React Function Component with types"
    }
}

但是我不小心把它放在了typescript.jsonsn-ps 文件而不是typescriptreact.jsonsn-ps 文件中。将其移动到正确的 sn-ps 文件中使其被正确拾取。这可能是这里的问题。

无论如何,我在这里写这个答案是因为这是在试图找到解决这个问题的方法时出现的搜索。

【讨论】:

    猜你喜欢
    • 2010-12-10
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多