3

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?

3 Answers 3

5

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
 * ----------   --- ----------------------------------------------------------
 */
Sign up to request clarification or add additional context in comments.

Comments

0

Say against you tap this for show License header

clt+alt+h x 2

Comments

0

I don't think you had a document selected when you got that error. (looks like you're in the settings page.) When I close all my editor panes and hit F1 and select Header Insert I also get that error message. So to answer your question, make sure you have a document open in your editor and have it selected.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.