Home > Software design >  Extension for getting vscode application url of a line of code
Extension for getting vscode application url of a line of code

Time:01-11

Specific lines of code in vscode can be linked to via application url as documented here: https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls

It would be nice to be able right-click on a line of code and get the url in your clipboard. I can't seem to find if there is an existing extension for that feature, wondering if anyone knows.

The use case I can think of is pasting the url into a task manager so when it comes time to work on that line of code, you can easily jump right to it versus trying to remember the code file / LOC

CodePudding user response:

you can use the following task to print the url to the terminal, you can copy it from there

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "file URL",
      "type": "shell",
      "command": "echo vscode://file${command:extension.commandvariable.file.filePosix}:${lineNumber}",
      "problemMatcher": []
    }
  ]
}

It uses the extension Command Variable to get the correct file separators on Windows (/). It only removes the : of the drive, because you don't want that in Cygwin and MSys.

You can try if this works in opening VSC with the file and line number

      "command": "echo vscode://file${file}:${lineNumber}",
  •  Tags:  
  • Related