Skip to content

Commit 2e60994

Browse files
authored
feat: support VSCode insiders (#19)
* Add vscode insiders support
1 parent 91cff73 commit 2e60994

File tree

3 files changed

+2547
-2183
lines changed

3 files changed

+2547
-2183
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ The extension will try to open the file in a clone named by the last segment of
1111

1212
- Set `vscode.open.uncPath` to true in your user settings to enable support for UNC (Universal Naming Convention) paths.
1313

14+
- Set `vscode.open.insidersMode` to true in your user settings to open files in VS Code Insiders instead of regular VS Code.
15+
1416
## Examples
1517

1618
### Mac
@@ -63,3 +65,10 @@ To open repository files in your Home directory:
6365
"vscode.open.uncPath": true
6466
}
6567
```
68+
69+
## Development
70+
71+
1. Run `yarn && yarn run serve` and keep the Parcel bundler process running.
72+
1. [Sideload the extension](https://docs.sourcegraph.com/extensions/authoring/local_development) (at the URL http://localhost:1234 by default) on your Sourcegraph instance or Sourcegraph.com.
73+
74+
When you edit a source file in your editor, Parcel will recompile the extension. Reload the Sourcegraph web page to use the updated extension.

src/open-in-vscode.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function getOpenUrl(textDocumentUri: URL): URL {
77
const repoBaseName = rawRepoName.split('/').pop()!
88
const basePath: unknown = sourcegraph.configuration.get().value['vscode.open.basePath']
99
const isUNC: boolean = sourcegraph.configuration.get().value['vscode.open.uncPath']
10+
const insidersMode: boolean = sourcegraph.configuration.get().value['vscode.open.insidersMode']
1011
if (typeof basePath !== 'string') {
1112
throw new Error(
1213
`Setting \`vscode.open.basePath\` must be set in your [user settings](${new URL('/user/settings', sourcegraph.internal.sourcegraphURL.href).href}) to open files in VS Code.`
@@ -21,12 +22,12 @@ function getOpenUrl(textDocumentUri: URL): URL {
2122
const absolutePath = path.join(basePath, repoBaseName, relativePath)
2223

2324
// if windows or enabled UNC path, add an extra slash in the beginning
24-
let uri = '';
25-
if (/^[a-zA-Z]:\\/.test(basePath) || isUNC) {
26-
uri = 'vscode://file/' + absolutePath
27-
} else {
28-
uri = 'vscode://file' + absolutePath
29-
}
25+
const uncPath = /^[a-zA-Z]:\\/.test(basePath) || isUNC ? '/' : '';
26+
// check if vscode-insiders mode is enabled
27+
const mode = insidersMode ? 'vscode-insiders' : 'vscode';
28+
// construct uri
29+
const uri = mode + '://file' + uncPath + absolutePath;
30+
3031
const openUrl = new URL(uri)
3132
if (sourcegraph.app.activeWindow?.activeViewComponent?.type === 'CodeEditor') {
3233
const selection = sourcegraph.app.activeWindow?.activeViewComponent?.selection

0 commit comments

Comments
 (0)