|
1 | 1 | # VS Code Sourcegraph extension
|
2 | 2 |
|
3 |
| -Adds a button at the top of files in both Sourcegraph app and code hosts like GitHub (when the Sourcegraph browser extension is installed) that will open the current file in VS Code. |
| 3 | +Adds a button to the Sourcegraph's extension panel and at the top of files in code hosts like GitHub (when the Sourcegraph browser extension is installed) that will open the current file in VS Code. |
| 4 | + |
| 5 | +**This extension requires all git repos to be cloned and available on your local machine.** |
4 | 6 |
|
5 | 7 | 
|
6 | 8 |
|
7 | 9 | ## Configuration
|
8 | 10 |
|
9 |
| -- Set `vscode.open.basePath` in your user settings to a local folder that contains your Git repositories. |
10 |
| -The extension will try to open the file in a clone named by the last segment of the repository name in that folder. |
| 11 | +Please add the following options in your Sourcegraph's User Settings to configure the extension: |
| 12 | + |
| 13 | +- `vscode.open.basePath`: [REQUIRED] String. The absolute path on your local machine that contains your Git repositories. |
| 14 | +The extension will try to open the file in a clone named by the last segment of the repository name in that folder. This extension requires all git repos to be already cloned under the provided path with their original names, which can then be altered using the `vscode.open.replacements` option. |
| 15 | + |
| 16 | +- `vscode.open.uncPath`: [OPTIONAL] Boolean. Set option to `true` in your user settings to enable support for UNC (Universal Naming Convention) paths. |
11 | 17 |
|
12 |
| -- Set `vscode.open.uncPath` to true in your user settings to enable support for UNC (Universal Naming Convention) paths. |
| 18 | +- `vscode.open.useMode`: [OPTIONAL] String. Specifies the mode you would like to use with VS Code. Currently support opening VS Code in the following modes: |
| 19 | + - `"insiders"`: Open files in VS Code Insiders instead of regular VS Code. |
| 20 | + - `"ssh"`: Open files from a remote server via ssh. This requires `vscode.open.remoteHost` configured in your User Setting and VS Code extension [Remote Development by Microsoft](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) installed in your VS Code to work. |
13 | 21 |
|
14 |
| -- Set `vscode.open.insidersMode` to true in your user settings to open files in VS Code Insiders instead of regular VS Code. |
| 22 | +- `vscode.open.replacements`: [OPTIONAL] Object. Take object with pairs of strings, where each key will be replaced by its value in the final url. The key can be a string or a RegExp, and the value must be a string. For example, using `"vscode.open.replacements": {"sourcegraph-": ""}` will remove `sourcegraph-` from the final URL. |
| 23 | + |
| 24 | +- `vscode.open.remoteHost`: [OPTIONAL] String. Set option to your desired `USER@HOSTNAME` to work with remote repositories. This requires VS Code extension [Remote Development by Microsoft](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) with `"vscode.open.useMode": "ssh"` configured in your Sourcegraph's User Setting to work. |
| 25 | + |
| 26 | +- `vscode.open.osPaths`: [OPTIONAL] Object. We will use the assigned path for the detected Operating System when available. If no platform is detected then we will keep using the path provided with `vscode.open.basePath`. Currently support `"windows"`, `"mac"`, and `"linux"` as keys. |
15 | 27 |
|
16 | 28 | ## Examples
|
17 | 29 |
|
| 30 | +### Configured base paths for different platforms |
| 31 | + |
| 32 | +```json |
| 33 | +{ |
| 34 | + "extensions": { |
| 35 | + "sourcegraph/open-in-vscode": true |
| 36 | + }, |
| 37 | + "vscode.open.osPaths": { |
| 38 | + "windows": "/C:/Users/USERNAME/folder/", |
| 39 | + "mac": "/Users/USERNAME/folder/", |
| 40 | + "linux": "/home/USERNAME/folder/" |
| 41 | + }, |
| 42 | + // set basePath as fallback path when no operating system is detected |
| 43 | + "vscode.open.basePath": "/Users/USERNAME/Documents/", |
| 44 | +} |
| 45 | +``` |
| 46 | + |
18 | 47 | ### Mac
|
19 | 48 |
|
20 | 49 | To open repository files in your Documents directory:
|
@@ -66,6 +95,55 @@ To open repository files in your Home directory:
|
66 | 95 | }
|
67 | 96 | ```
|
68 | 97 |
|
| 98 | +### Replacements |
| 99 | + |
| 100 | +Adds `sourcegraph-` in front of the string that matches the `(?<=Documents\/)(.*[\\\/])` RegExp pattern, which is the string after `Documents/` and before the final slash. This turns the final url from `vscode://file//Users/USERNAME/Documents/REPO-NAME/package.json` to `vscode://file//Users/USERNAME/Documents/sourcegraph-REPO-NAME/package.json` |
| 101 | + |
| 102 | +```json |
| 103 | +{ |
| 104 | + "extensions": { |
| 105 | + "sourcegraph/open-in-vscode": true |
| 106 | + }, |
| 107 | + "vscode.open.basePath": "/Users/USERNAME/Documents/", |
| 108 | + "vscode.open.replacements": {"(?<=Documents\/)(.*[\\\/])": "sourcegraph-$1"}, |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +### Remote SSH Server |
| 113 | + |
| 114 | +**This requires VS Code extension [Remote Development by Microsoft](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) to work.** |
| 115 | + |
| 116 | +To open repository files reside in a remote server: |
| 117 | + |
| 118 | +```json |
| 119 | +{ |
| 120 | + "extensions": { |
| 121 | + "sourcegraph/open-in-vscode": true |
| 122 | + }, |
| 123 | + // File path for where the repositories reside in the remote server |
| 124 | + "vscode.open.basePath": "/Users/USERNAME/Documents/", |
| 125 | + // Specifies extension to run VS Code with a SSH server |
| 126 | + "vscode.open.useMode": "ssh", |
| 127 | + // Replaces USER and HOSTNAME as appropriate |
| 128 | + "vscode.open.remoteHost": "USER@HOSTNAME", |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +### Open folders instead of files |
| 133 | + |
| 134 | +To open directory where the repository files reside: |
| 135 | + |
| 136 | +```json |
| 137 | +{ |
| 138 | + "extensions": { |
| 139 | + "sourcegraph/open-in-vscode": true |
| 140 | + }, |
| 141 | + "vscode.open.basePath": "/Users/USERNAME/Documents/", |
| 142 | + // Use RegExp to remove file names |
| 143 | + "vscode.open.replacements": {"\/[^\/]*$": ""}, |
| 144 | +} |
| 145 | +``` |
| 146 | + |
69 | 147 | ## Development
|
70 | 148 |
|
71 | 149 | 1. Run `yarn && yarn run serve` and keep the Parcel bundler process running.
|
|
0 commit comments