Skip to content

Commit

Permalink
Refactor getWorkspacePath function for improved readability and consi…
Browse files Browse the repository at this point in the history
…stency
  • Loading branch information
jeremytenjo committed Jan 31, 2025
1 parent e087e16 commit fe459a4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions utils/workspace/getWorkspacePath.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import vscode from 'vscode'
import path from 'path'
import { platform } from 'process';
import { StartsWithSlashRegex } from '../splitPath';
import removeFirstCharacter from '../folderFiles/removeFirstCharacter';
import { platform } from 'process'
import { StartsWithSlashRegex } from '../splitPath'
import removeFirstCharacter from '../folderFiles/removeFirstCharacter'

export type FilePath = {
path: string;
getFileUri(): string;
getExtension(): string;
hasExtension(ext: string): boolean;
addFile(dir: string): void;
path: string
getFileUri(): string
getExtension(): string
hasExtension(ext: string): boolean
addFile(dir: string): void
}

export default function getWorkspacePath(add = ''): FilePath {
// Get the workspace folder uri
const folderUri = vscode.workspace.workspaceFolders![0].uri

// add the path to the workspace folder
let filePath = path.join(folderUri.path, add);
let filePath = path.join(folderUri.path, add)

// If the platform is windows and the path starts with a slash, remove the slash
if(platform == "win32" && StartsWithSlashRegex.test(filePath)) {
if (platform == 'win32' && StartsWithSlashRegex.test(filePath)) {
filePath = removeFirstCharacter(filePath)
}

Expand Down

0 comments on commit fe459a4

Please sign in to comment.