Skip to content

Commit 91cff73

Browse files
authored
feat: support UNC path (#17)
* Support UNC path
1 parent 4c7f462 commit 91cff73

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,60 @@ Adds a button at the top of files in both Sourcegraph app and code hosts like Gi
66

77
## Configuration
88

9-
Set `vscode.open.basePath` in your user settings to a local folder that contains your Git repositories.
9+
- Set `vscode.open.basePath` in your user settings to a local folder that contains your Git repositories.
1010
The extension will try to open the file in a clone named by the last segment of the repository name in that folder.
11+
12+
- Set `vscode.open.uncPath` to true in your user settings to enable support for UNC (Universal Naming Convention) paths.
13+
14+
## Examples
15+
16+
### Mac
17+
18+
To open repository files in your Documents directory:
19+
20+
```json
21+
{
22+
"extensions": {
23+
"sourcegraph/open-in-vscode": true
24+
},
25+
"vscode.open.basePath": "/Users/USERNAME/Documents/"
26+
}
27+
```
28+
29+
### Windows
30+
31+
To open repository files in your Documents directory:
32+
33+
```json
34+
{
35+
"extensions": {
36+
"sourcegraph/open-in-vscode": true
37+
},
38+
"vscode.open.basePath": "/Users/USERNAME/Documents/"
39+
}
40+
```
41+
42+
You may also use an absolute file path from the root of drive C: with the following setting:
43+
44+
```json
45+
{
46+
"extensions": {
47+
"sourcegraph/open-in-vscode": true,
48+
},
49+
"vscode.open.basePath": "/C:/Users/USERNAME/Documents/"
50+
}
51+
```
52+
53+
### WSL
54+
55+
To open repository files in your Home directory:
56+
57+
```json
58+
{
59+
"extensions": {
60+
"sourcegraph/open-in-vscode": true
61+
},
62+
"vscode.open.basePath": "//wsl$/Ubuntu-18.04/home",
63+
"vscode.open.uncPath": true
64+
}
65+
```

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
"vscode.open.basePath": {
5252
"description": "The file path on the machine to the folder that is expected to contain all repositories.",
5353
"type": "string"
54+
},
55+
"vscode.open.uncPath": {
56+
"description": "Set true to enable support for Universal naming convention (UNC) paths, which use double slashes or backslashes before the host device name (as used in Windows or WSL).",
57+
"type": "boolean"
5458
}
5559
}
5660
}

src/open-in-vscode.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function getOpenUrl(textDocumentUri: URL): URL {
66
// TODO support different folder layouts, e.g. repo nested under owner name
77
const repoBaseName = rawRepoName.split('/').pop()!
88
const basePath: unknown = sourcegraph.configuration.get().value['vscode.open.basePath']
9+
const isUNC: boolean = sourcegraph.configuration.get().value['vscode.open.uncPath']
910
if (typeof basePath !== 'string') {
1011
throw new Error(
1112
`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.`
@@ -19,9 +20,9 @@ function getOpenUrl(textDocumentUri: URL): URL {
1920
const relativePath = decodeURIComponent(textDocumentUri.hash.slice('#'.length))
2021
const absolutePath = path.join(basePath, repoBaseName, relativePath)
2122

22-
// if windows add an extra slash in the beginning
23+
// if windows or enabled UNC path, add an extra slash in the beginning
2324
let uri = '';
24-
if (/^[a-zA-Z]:\\/.test(basePath)) {
25+
if (/^[a-zA-Z]:\\/.test(basePath) || isUNC) {
2526
uri = 'vscode://file/' + absolutePath
2627
} else {
2728
uri = 'vscode://file' + absolutePath

0 commit comments

Comments
 (0)