vscode-openThis is a Visual Studio Code extension for opening files in your browser, or vice versa. The main purpose of this extension is to be able to seamlessly move between your editor and the SCM/code review provider in your browser. You can open files or pull requests in your browser based off of selected lines in your editor, or conversely open a file in your editor from a given URI. See the release notes for the list of recent changes. Features
ConfigurationMappingsMappings are the main settings that determine how to generate file paths/URIs/PRs.
VariablesThere are a number of special variables that are supported by this extension, which make it possible/easier to generate mappings. Variables can be used in the patterns that are required for various mappings, using the format
|
Variable | Description |
---|---|
${editor:workspaceFolder} |
The path of the folder opened in VS Code. Folder name must be specified as an additional argument if there are multiple open workspace folders, e.g. ${editor:workspaceFolder:folder_name} . |
${editor:workspaceFolderBasename} |
The name of the folder opened in VS Code without any slashes (/). Folder name must be specified as an additional argument if there are multiple open workspace folders. |
${editor:relativeFile} |
The current opened file relative to workspaceFolder . Folder name must be specified as an additional argument if there are multiple open workspace folders. |
${editor:relativeFileDirname} |
The current opened file's dirname relative to workspaceFolder . Folder name must be specified as an additional argument if there are multiple open workspace folders. |
${editor:file} |
The current opened file. |
${editor:fileBasename} |
The current opened file's basename. |
${editor:fileBasenameNoExtension} |
The current opened file's basename with no file extension. |
${editor:fileDirname} |
The current opened file's dirname. |
${editor:fileExtname} |
The current opened file's extension. |
${editor:lines} |
The selected lines of the current opened file. The exact output is configurable via settings like lineSeparator and linePrefix . |
${editor:currentCommit} |
The current commit hash of the opened file. |
Examples:
# Assume multiple opened workspace folders, current file is /myrepo/dir/file.py
${editor:workspaceFolder:myrepo}
# Output: /myrepo
${editor:workspaceFolderBasename:myrepo}
# Output: myrepo
${editor:relativeFile:myrepo}
# Output: /dir/file.py
${editor:relativeFileDirname:myrepo}
# Output: /dir
# Assume single opened workspace folder, current file is /myrepo/dir/file.py
${editor:workspaceFolder}
# Output: /myrepo
${editor:workspaceFolderBasename}
# Output: myrepo
${editor:relativeFile}
# Output: /dir/file.py
${editor:relativeFileDirname}
# Output: /dir
${editor:file}
# Output: /myrepo/dir/file.py
${editor:fileBasename}
# Output: file.py
${editor:fileBasenameNoExtension}
# Output: file
${editor:fileDirname}
# Output: /myrepo/dir
${editor:fileExtname}
# Output: .py
${editor:lines}
# Output: e.g. [#12](https://github.com/alexander-yu/vscode-open/issues/12) or [#12](https://github.com/alexander-yu/vscode-open/issues/12)-14 (the default format)
${editor:currentCommit}
# Output: e.g. 6081948371a180586a806a214202e44c2f922a42
match
This category allows you to extract any regex capture groups from the input patterns of mappings. The value of the variable must be the name of a valid capture group in the input pattern.
Example:
${match:group_1}/${match:group_2}
# Input pattern: (?<group_1>[A-Za-z]+)_(?<group_2>[0-9]+).txt
# Input text: hello_123.txt
# Output: hello/123
regex
This category provides some standard regex templates to use. This will be subsituted by the appropriate regex template, with a capture group whose name is equal to the template name (i.e. you can use this in conjunction with match
variables).
Variable | Description |
---|---|
file |
Regex for capturing file names. For simplicity, this is currently just .+ . |
lines |
Regex for capturing line numbers. The end result regex is configurable via settings like lineSeparator and linePrefix . |
Example Configuration
{
"open.fileMappings": [
{
"pattern": "src/static/(?<mdFileWithoutExt>.+)\\.md$",
"output": "https://host.example.com/docs/${match:mdFileWithoutExt}"
},
{
"pattern": "${editor:file}",
"output": "https://host.example.com/repo/blob/${editor.currentCommit}/${editor:relativeFile}${editor:lines}",
"lineSeparator": "#",
"linePrefix": "L"
}
],
"open.prMappings": [
{
"pattern": "${editor:file}",
"provider": {
"type": "phabricator",
"base": "https://phabricator.example.com"
}
}
],
"open.uriMappings": [
{
"pattern": "https://host.example.com/repo/${regex:file}${regex:lines}",
"output": "${editor:workspaceFolder}/${match:file}${match:lines}",
"lineSeparator": "#"
}
]
}