代码片段完成后,VS Code 是否可以获取选择代码片段的选择建议?

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

在 VSC 中,我有一个粘贴的用户片段

call colorecho "Red;Text"

并且它是在用户片段设置中设置的

"Color Echo": {
        "scope": "batch,bat",
        "prefix": "color echo",
        "body": "call colorecho \"${1|Red,Cyan,Green,Blue,Magenta,Yellow,White,Red Underline,Cyan Underline,Green Underline,Blue Underline,Magenta Underline,Yellow Underline,White Underline|};${2:Text}\"$0",
        "description": "Echo But With Color, Text Blocks Must be in \"Color;Text\" format"
    },

当我输入

color echo
并点击 Tab 时,它会将光标置于 Tabstop 1 处,并带有一个包含所有这些选项的漂亮下拉菜单。当我第一次输入它时,它工作得很好,但是如果我必须返回并调整颜色,id 就像相同的上下文感知建议一样,当光标位于第一个 ( 和 ;

之间时

并且不要破坏其他地方的建议

我不知道这是否是一个东西,但我觉得它可能存在

我尝试在“设置”中启用字符串的“快速建议”设置。当光标位于所述位置时,这会带来建议,但是,这会带来我曾经输入过的所有内容的非常大且不了解上下文的历史记录。如果可能的话,我希望它能调出颜色。

visual-studio-code intellisense vscode-snippets
1个回答
0
投票

您可以使用扩展(我写的)Select By和执行多个命令的键绑定来模拟它。

如果光标位于上一个片段中color的位置,它将选择颜色并启动一个片段,显示可能的颜色列表。

如果光标位于任何其他位置,则键绑定只会在该位置插入颜色。

  {
    "key": "ctrl+f8",   // any key combo
    "command": "runCommands",
    "args": {
      "commands": [
        {
          "command": "selectby.regex",
          "args": {
            "surround": "(?<=call colorecho \")[ a-zA-Z]+(?=;)"
          }
        },
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "snippet": "${1|Red,Cyan,Green,Blue,Magenta,Yellow,White,Red Underline,Cyan Underline,Green Underline,Blue Underline,Magenta Underline,Yellow Underline,White Underline|}"
          }
        }
      ]
    }
  }

如果您因为不想修改颜色而转义代码片段,则必须执行撤消 (

Ctrl+Z
)。

如果您的 VSC 版本不支持

runCommands
(在 >1.75 版本中添加),您可以使用 多命令

  {
    "key": "ctrl+f8",   // any key combo
    "command": "extension.multiCommand.execute",
    "args": {
      "sequence": [
        {
          "command": "selectby.regex",
          "args": {
            "surround": "(?<=call colorecho \")[ a-zA-Z]+(?=;)"
          }
        },
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "snippet": "${1|Red,Cyan,Green,Blue,Magenta,Yellow,White,Red Underline,Cyan Underline,Green Underline,Blue Underline,Magenta Underline,Yellow Underline,White Underline|}"
          }
        }
      ]
    }
  }
© www.soinside.com 2019 - 2024. All rights reserved.