Answer a question

I'm new to VS Code as I mainly have been using IntelliJ for most of my years. I now want to set up License header as a template in my VS Code globally so that it is applied automatically on any new files that I create.

I installed psioniq psi header and I tried to follow the documentation but I'm not sure how to set it up. As per the documentation, I need to hit F1 and enter Header Change Log Insert, but as soon as I do this, I get to see an error message as seen in the screen below:

psioniq error message

Any idea what the issue could be?

Answers

I figured it out by myself and here is what I had to do:

To configure the headers as a template, I had to open the settings.json by navigating from File -> Preferences -> Settings and then follow as per the screenshot below.

settings.json

My settings.json has the following content:

{
    "workbench.iconTheme": "vscode-icons",
    "workbench.editorAssociations": [
        {
            "viewType": "jupyter.notebook.ipynb",
            "filenamePattern": "*.ipynb"
        }
    ],
    "files.autoSave": "afterDelay",
    "psi-header.variables": [
        ["author", "myuser"],
        ["url", "<https://my.github.com/myuser>"]
    ],
    "psi-header.templates": [
        {
            "language": "*",
            "template": [
                "Copyright (c) <<year>> <<author>> <<url>>",
                "",
                "Created Date: <<filecreated('dddd, MMMM Do YYYY, h:mm:ss a')>>",
                "Author: <<author>>",
                "",
                "Redistribution and use in source and binary forms, with or without",  
                "modification, are permitted provided that the following conditions are", 
                "met:",
                "",
                "1. Redistributions of source code must retain the above copyright notice,", 
                "this list of conditions and the following disclaimer.",
                "",
                "2. Redistributions in binary form must reproduce the above copyright", 
                "notice, this list of conditions and the following disclaimer in the",   
                "documentation and/or other materials provided with the distribution.",
                "",
                "3. Neither the name of the copyright holder nor the names of its", 
                "contributors may be used to endorse or promote products derived from this",
                "software without specific prior written permission.",
                "",
                "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS", 
                "IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,", 
                "THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ",
                "PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR", 
                "CONTRIBUTORS BE", 
                "LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR",
                "CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF", 
                "SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS", 
                "INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN", 
                "CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)", 
                "ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF", 
                "THE POSSIBILITY OF SUCH DAMAGE.",
                "",
                "HISTORY:",
                "Date      \tBy\tComments",
                "----------\t---\t----------------------------------------------------------"
            ],
            "changeLogCaption": "HISTORY:",
            "changeLogHeaderLineCount": 2,
            "changeLogEntryTemplate": [
                "<<dateformat('YYYY-MM-DD')>>\t<<initials>>\t"
            ]
        }
    ]
}

So that would then produce a header file as below:

/*
 * Copyright (c) 2020 myuser <https://my.github.com/myuser>
 * 
 * Created Date: Thursday, October 29th 2020, 9:08:05 am
 * Author: myuser
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. Neither the name of the copyright holder nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS
 * IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * HISTORY:
 * Date         By  Comments
 * ----------   --- ----------------------------------------------------------
 */
Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐