diff --git a/src/test/workspace.test.ts b/src/test/workspace.test.ts index 9dd73cb5..3617ab81 100644 --- a/src/test/workspace.test.ts +++ b/src/test/workspace.test.ts @@ -1,26 +1,25 @@ import os from 'os' import { Uri } from 'vscode' import chai from 'chai' -import { normalizeUri } from '../util/workspace' const expect = chai.expect suite('Normalize URI', () => { test('Should lowercase drive letter on Windows', async () => { if (os.platform() === 'win32') { - const result = normalizeUri(Uri.parse('file:///C:/path/WITH/camelCase/A/b/C/index.adoc')) + const result = Uri.parse('file:///C:/path/WITH/camelCase/A/b/C/index.adoc') expect(result.path).to.equal('/c:/path/WITH/camelCase/A/b/C/index.adoc') } }) test('Should do nothing since the drive letter is already lowercase', async () => { if (os.platform() === 'win32') { - const result = normalizeUri(Uri.parse('file:///c:/path/WITH/camelCase/A/b/C/index.adoc')) + const result = Uri.parse('file:///c:/path/WITH/camelCase/A/b/C/index.adoc') expect(result.path).to.equal('/c:/path/WITH/camelCase/A/b/C/index.adoc') } }) test('Should do nothing on Linux', async () => { if (os.platform() !== 'win32') { - const result = normalizeUri(Uri.parse('/C/path/WITH/camelCase/A/b/C/index.adoc')) + const result = Uri.parse('/C/path/WITH/camelCase/A/b/C/index.adoc') expect(result.path).to.equal('/C/path/WITH/camelCase/A/b/C/index.adoc') } }) diff --git a/src/test/workspaceHelper.ts b/src/test/workspaceHelper.ts index 80a697c9..42492243 100644 --- a/src/test/workspaceHelper.ts +++ b/src/test/workspaceHelper.ts @@ -1,5 +1,5 @@ import vscode, { FileSystemError, FileType } from 'vscode' -import { getDefaultWorkspaceFolderUri, normalizeUri } from '../util/workspace' +import { getDefaultWorkspaceFolderUri } from '../util/workspace' import { extensionContext } from './helper' export async function removeFiles (files: vscode.Uri[]) { @@ -26,7 +26,7 @@ async function exists (file: vscode.Uri): Promise { export async function createFile (content: string, ...pathSegments: string[]): Promise { const file = vscode.Uri.joinPath(getDefaultWorkspaceFolderUri(), ...pathSegments) await vscode.workspace.fs.writeFile(file, Buffer.from(content)) - return normalizeUri(file) + return file } export async function createDirectories (...pathSegments: string[]): Promise { @@ -54,7 +54,7 @@ export async function createDirectories (...pathSegments: string[]): Promise { const dir = vscode.Uri.joinPath(getDefaultWorkspaceFolderUri(), ...pathSegments) await vscode.workspace.fs.createDirectory(dir) - return normalizeUri(dir) + return dir } export async function createLink (existingPathSegments: string[], newPathSegments: string[]): Promise { @@ -63,7 +63,7 @@ export async function createLink (existingPathSegments: string[], newPathSegment const existingPath = vscode.Uri.joinPath(workspaceUri, ...existingPathSegments) const newPath = vscode.Uri.joinPath(workspaceUri, ...newPathSegments) await fs.symlink(existingPath.fsPath, newPath.fsPath) - return normalizeUri(newPath) + return newPath } export async function enableAntoraSupport () { diff --git a/src/util/workspace.ts b/src/util/workspace.ts index 84085cb7..be654701 100644 --- a/src/util/workspace.ts +++ b/src/util/workspace.ts @@ -1,35 +1,15 @@ 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 } @@ -37,15 +17,5 @@ export function findDefaultWorkspaceFolderUri (): Uri | 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 }