How to add text in New File Name in Visual Studio Code using command ids?

768 views Asked by At

I've been learning more recently about user snippets and due to some things I've been reading on here I got interested about combining them as well using the multi-command extension.

I'm writing my first sequence and this is where I am at now:

"multiCommand.commands": [
{
  "command": "multiCommand.createFolderStructure",
  "sequence": [
    {
      "command": "renameFile",
      "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
    },
    {
      "command": "editor.action.clipboardCopyAction",
      "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
    },
    {
      "command": "explorer.newFile"
    },
    { "command": "editor.action.clipboardPasteAction" },
    {
      "command": "editor.action.insertSnippet",
      "args": {
        "snippet": ".js"
      }
    }
  ]
}

]

So what this does at the moment is:

  1. Opens the renaming for current active folder.
  2. Copies the name of the folder.
  3. Creates new file in active folder.
  4. Pastes the name of the folder from clipboard.

With the last command I was trying to add .js at the end of it. But it does not seems to be working. The insert snippet only works in the editor. I didn't find anything else that would work for me. Is there anyone that knows whats a good command id for this particular thing?

1

There are 1 answers

4
Talmacel Marian Silviu On

Ok I have managed to do what I needed but in an overly complicated way. If anybody knows the answer to my questions I would still like it. This is what I did:

"multiCommand.commands": [
    {
      "command": "multiCommand.createFolderStructure",
      "interval": 30,
      "sequence": [
        "renameFile",
        "editor.action.clipboardCopyAction",
        "explorer.newFile",
        "editor.action.clipboardPasteAction",
        "workbench.action.quickOpen",
        "workbench.files.action.focusOpenEditorsView",
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "snippet": "$CLIPBOARD.js"
          }
        },
        "editor.action.selectAll",
        "editor.action.clipboardCutAction",
        "workbench.files.action.focusFilesExplorer",
        "renameFile",
        "editor.action.clipboardPasteAction"
      ]
    }
  ]

This is the complete series of actions I had to do for all the requirements I had if anybody is interested. However this will not work for you as it is as you also need the user snippets I defined

{
      "command": "multiCommand.createFolderStructure",
      "interval": 100,
      "sequence": [
        "renameFile",
        "editor.action.clipboardCopyAction",
        "explorer.newFile",
        "editor.action.clipboardPasteAction",
        "workbench.action.quickOpen",
        "workbench.files.action.focusOpenEditorsView",
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "snippet": "$CLIPBOARD.js"
          }
        },
        "editor.action.selectAll",
        "editor.action.clipboardCutAction",
        "workbench.files.action.focusFilesExplorer",
        "renameFile",
        "editor.action.clipboardPasteAction",
        "workbench.action.quickOpen",
        "workbench.files.action.focusOpenEditorsView",
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "snippet": "${TM_FILENAME_BASE/(.*)/${1:capitalize}/}.styled.js"
          }
        },
        "editor.action.selectAll",
        "editor.action.clipboardCutAction",
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "name": "Simple Component"
          },
          "when": "editorLangId == javascript"
        },

        "workbench.files.action.focusFilesExplorer",
        "explorer.newFile",
        "editor.action.clipboardPasteAction",
        "workbench.action.quickOpen",
        "workbench.files.action.focusOpenEditorsView",
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "snippet": "index.js"
          },
          "when": "editorLangId == javascript"
        },
        "editor.action.selectAll",
        "editor.action.clipboardCutAction",
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "name": "Styled Template"
          },
          "when": "editorLangId == javascript"
        },
        "workbench.files.action.focusFilesExplorer",
        "explorer.newFile",
        "editor.action.clipboardPasteAction",
        "workbench.action.quickOpen",
        "workbench.files.action.focusOpenEditorsView",
        {
          "command": "editor.action.insertSnippet",
          "args": {
            "name": "Export Default From"
          },
          "when": "editorLangId == javascript"
        },
        "workbench.action.files.saveAll",
        "workbench.action.closeAllEditors"
      ]
    },