Skip to content

Commit

Permalink
more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
nalbion committed Feb 13, 2024
1 parent e859067 commit 585ebac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/utils/fileUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ jest.mock('fs/promises', () => {

describe('getAbsolutePathInWorkspace', () => {
const testCases = [
{ workspace: '/my/workspace', file: 'file', expected: '/my/workspace/file' },
// { workspace: '/my/workspace', file: 'file', expected: '/my/workspace/file' },
{ workspace: 'C:\\my\\workspace', file: 'file', expected: '/my/workspace/file' },
{ workspace: '/my/workspace', file: '.env', expected: '/my/workspace/.env' },
{ workspace: '/my/workspace', file: './file', expected: '/my/workspace/file' },
{ workspace: '/my/workspace', file: 'path/to/file', expected: '/my/workspace/path/to/file' },
{ workspace: '/my/workspace', file: '../path/../../../to/file', expected: '/my/workspace/path/to/file' },
{ workspace: '/my/workspace', file: './path/to my/file', expected: '/my/workspace/path/to my/file' },
{ workspace: '/my/workspace', file: '~/file', expected: '/my/workspace/home/file' },
{ workspace: '/my/workspace', file: '~/path/to/file', expected: '/my/workspace/home/path/to/file' },
{ workspace: '/my/workspace', file: '/temp/path/to/file', expected: '/my/workspace/root/temp/path/to/file' },
{ workspace: '/my/workspace', file: 'C:\\temp\\path\\to\\file', expected: '/my/workspace/root/temp/path/to/file' },
// { workspace: '/my/workspace', file: '.env', expected: '/my/workspace/.env' },
// { workspace: '/my/workspace', file: './file', expected: '/my/workspace/file' },
// { workspace: '/my/workspace', file: 'path/to/file', expected: '/my/workspace/path/to/file' },
// { workspace: '/my/workspace', file: '../path/../../../to/file', expected: '/my/workspace/path/to/file' },
// { workspace: '/my/workspace', file: './path/to my/file', expected: '/my/workspace/path/to my/file' },
// { workspace: '/my/workspace', file: '~/file', expected: '/my/workspace/home/file' },
// { workspace: '/my/workspace', file: '~/path/to/file', expected: '/my/workspace/home/path/to/file' },
// { workspace: '/my/workspace', file: '/temp/path/to/file', expected: '/my/workspace/root/temp/path/to/file' },
// { workspace: '/my/workspace', file: 'C:\\temp\\path\\to\\file', expected: '/my/workspace/root/temp/path/to/file' },
];

testCases.forEach(({ workspace, file, expected }) => {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ export function normalisePath(filePath: string | undefined) {
}

export function getAbsolutePathInWorkspace(workspaceFolder: string, filePath: string): string {
console.info('filepath 1:', filePath);
filePath = filePath.replaceAll('\\', '/').replaceAll('../', '');
console.info('filepath 2:', filePath);

if (filePath.startsWith('~')) {
filePath = 'home/' + filePath.substring(1);
} else if (filePath.startsWith('/')) {
filePath = 'root' + filePath;
} else {
console.info('filepath 3:', filePath);
filePath = filePath.replace(/^[A-Za-z]:/, 'root');
}

console.info('filepath 4:', filePath);
console.info('workspaceFolder:', workspaceFolder);
let absolutePath = path.resolve(workspaceFolder, filePath);
console.info('absolutePath:', absolutePath);

return absolutePath;
}
Expand Down

0 comments on commit 585ebac

Please sign in to comment.