VS代码中是否有快捷方式来实施开玩笑的TODO测试?

发布于 2025-01-26 01:22:03 字数 301 浏览 4 评论 0原文

当我拥有的时候:

test.todo('customer can order a pizza');

我想要一个将行转换为以下路程的快捷方式,

test('customer can order a pizza', async () => {
  <|>
});

其中&lt; |&gt;是光标位置。

可以使用摘要吗?理想情况下,我希望在触发转换之前不必选择整个线。

还是有这样做的扩展名?

When I have:

test.todo('customer can order a pizza');

I would like a shortcut that would transform the line to:

test('customer can order a pizza', async () => {
  <|>
});

where <|> is the cursor position.

Is it possible using snippets? Ideally, I would prefer not to have to select the whole line before triggering the transform.

Or is there an extension that does this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清晰传感 2025-02-02 01:22:03

您可以使用扩展名多command

{
    "key": "alt+x",
    "command": "extension.multiCommand.execute",
    "args": { 
        "sequence": [
            "cursorEnd",
            "cursorHomeSelect",
            { "command": "editor.action.insertSnippet",
              "args": {
                "snippet": "test(${TM_SELECTED_TEXT/test\\.todo('[^']+');/'${1}'/}, async () => {\\n\\t$0\\n\\t});"
              }
            }
        ]
    }
}

you can use the extension multi-command

{
    "key": "alt+x",
    "command": "extension.multiCommand.execute",
    "args": { 
        "sequence": [
            "cursorEnd",
            "cursorHomeSelect",
            { "command": "editor.action.insertSnippet",
              "args": {
                "snippet": "test(${TM_SELECTED_TEXT/test\\.todo('[^']+');/'${1}'/}, async () => {\\n\\t$0\\n\\t});"
              }
            }
        ]
    }
}
凌乱心跳 2025-02-02 01:22:03

基于 @riov8

答案键盘快捷键(JSON)从命令调色板和粘贴:

  {
    "key": "cmd+shift+i",
    "command": "extension.multiCommand.execute",
    "args": {
      "sequence": [
        "cursorEnd",
        "cursorHomeSelect",
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "snippet": "${TM_SELECTED_TEXT/(test|it)\\.todo\\(('[^']+'|\"[^\"]+\")\\);/$1($2/}, async () => {\n\t$1\n});"
          }
        }
      ]
    }
  }

我选择cmd+shift+i“实现”,请随时选择您喜欢的快捷方式。

Based on answer from @rioV8, I was able to make it work ???? thanks a ton ????

Open Preferences: Open Keyboard Shortcuts (JSON) from command palette, and paste:

  {
    "key": "cmd+shift+i",
    "command": "extension.multiCommand.execute",
    "args": {
      "sequence": [
        "cursorEnd",
        "cursorHomeSelect",
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "snippet": "${TM_SELECTED_TEXT/(test|it)\\.todo\\(('[^']+'|\"[^\"]+\")\\);/$1($2/}, async () => {\n\t$1\n});"
          }
        }
      ]
    }
  }

I chose cmd+shift+i for "implement", feel free to choose which ever shortcut you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文