2

更改用户片段后,我想使用它。

除了重新启动 VSCode 之外,还有其他方法可以更新代码片段吗?

4

2 回答 2

1

只需保存代码片段文件。

如果仍然不起作用,请执行Ctrl++ ,键入Shiftreload Pwindow 并按 enter。

于 2022-01-12T21:12:45.727 回答
0

当我将代码段放入错误的代码段文件中时,我遇到了这个问题。例如,我想编写一个新的片段来创建一个 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.jsonsnippets文件而不是typescriptreact.jsonsnippets文件中。将其移动到正确的片段文件中使其被正确拾取。这可能是这里的问题。

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

于 2021-03-16T22:41:17.307 回答