-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65cfe9d
commit f8abad0
Showing
3 changed files
with
12 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,21 @@ | ||
import vscode, { Uri, WorkspaceFolder } from 'vscode' | ||
import os from 'os' | ||
|
||
const driveLetterRx = /(?<=^\/)([A-Z])(?=:\/)/ | ||
|
||
export function getWorkspaceFolder (uri: Uri): WorkspaceFolder | undefined { | ||
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri) | ||
if (workspaceFolder && os.platform() === 'win32') { | ||
return { | ||
uri: normalizeUri(workspaceFolder.uri), | ||
name: workspaceFolder.name, | ||
index: workspaceFolder.index, | ||
} | ||
} | ||
return workspaceFolder | ||
return vscode.workspace.getWorkspaceFolder(uri) | ||
} | ||
|
||
export function getWorkspaceFolders (): WorkspaceFolder[] | undefined { | ||
return vscode.workspace.workspaceFolders?.map((workspaceFolder) => { | ||
if (os.platform() === 'win32') { | ||
return { | ||
uri: normalizeUri(workspaceFolder.uri), | ||
name: workspaceFolder.name, | ||
index: workspaceFolder.index, | ||
} | ||
} | ||
return workspaceFolder | ||
}) | ||
export function getWorkspaceFolders (): readonly WorkspaceFolder[] { | ||
return vscode.workspace.workspaceFolders | ||
} | ||
|
||
export function findDefaultWorkspaceFolderUri (): Uri | undefined { | ||
const workspaceFolders = getWorkspaceFolders() | ||
const workspaceFolders = vscode.workspace.workspaceFolders | ||
if (workspaceFolders && workspaceFolders.length) { | ||
return workspaceFolders[0].uri | ||
} | ||
return undefined | ||
} | ||
|
||
export function getDefaultWorkspaceFolderUri (): Uri | undefined { | ||
const workspaceFolders = getWorkspaceFolders() | ||
return normalizeUri(workspaceFolders[0].uri) | ||
} | ||
|
||
export function normalizeUri (uri: Uri): Uri { | ||
// normalize Windows drive letter | ||
// https://github.com/microsoft/vscode/issues/194692 | ||
if (os.platform() === 'win32') { | ||
return uri.with({ path: uri.path.replace(driveLetterRx, (driverLetter) => driverLetter.toLowerCase()) }) | ||
} | ||
return uri | ||
return vscode.workspace.workspaceFolders[0].uri | ||
} |