visual-studio-code

How to permanently link to a line in visual studio code


I was wondering if it is possible to create a permanent link to a line in the same file in visual studio code. I saw that in GitHub you can do this (How to link to specific line number on github). Is it possible to do the same in visual studio code?


Solution

  • With the extension I made HTML Related Links (better name would be Related Links) you can create a file that contains the path and line:character_pos that you want to jump to.

    If you open this file and lock the HTML Related Links View in the explorer to this file you have these links always available and they will update when you edit the file with links.

    If you have a .txt file with content like:

    src/module1/fileA.js@123
    src/module3/fileB.js@54
    

    You can use the following setting:

    "html-related-links.include": {
    "plaintext": [
        {
            "find": "([\\w./]+)@(\\d+):(\\d+)",
            "filePath": "/$1",
            "lineNr": "$2",
            "charPos": "$3"
        },
        {
            "find": "([\\w./]+)@(\\d+)",
            "filePath": "/$1",
            "lineNr": "$2"
        },
        {
            "find": "([\\w./]+)",
            "filePath": "/$1"
        },
    ]
    

    At the moment the bookmarking is done manually by editing the .txt file.

    I can have a look if can add a context menu entry to the editor.