forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpathUtils.ts
More file actions
54 lines (45 loc) · 1.63 KB
/
pathUtils.ts
File metadata and controls
54 lines (45 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// TODO: Drop this file.
// See https://github.com/microsoft/vscode-python/issues/8542.
import { inject, injectable } from 'inversify';
import * as path from 'path';
import { IPathUtils, IsWindows } from '../types';
import { OSType } from '../utils/platform';
import { Executables, FileSystemPaths, FileSystemPathUtils } from './fs-paths';
const untildify = require('untildify');
@injectable()
export class PathUtils implements IPathUtils {
private readonly utils: FileSystemPathUtils;
constructor(
// "true" if targeting a Windows host.
@inject(IsWindows) isWindows: boolean,
) {
const osType = isWindows ? OSType.Windows : OSType.Unknown;
// We cannot just use FileSystemPathUtils.withDefaults() because
// of the isWindows arg.
this.utils = new FileSystemPathUtils(
untildify('~'),
FileSystemPaths.withDefaults(),
new Executables(path.delimiter, osType),
path,
);
}
public get home(): string {
return this.utils.home;
}
public get delimiter(): string {
return this.utils.executables.delimiter;
}
public get separator(): string {
return this.utils.paths.sep;
}
// TODO: Deprecate in favor of IPlatformService?
public getPathVariableName(): 'Path' | 'PATH' {
return this.utils.executables.envVar as any;
}
public getDisplayName(pathValue: string, cwd?: string): string {
return this.utils.getDisplayName(pathValue, cwd);
}
public basename(pathValue: string, ext?: string): string {
return this.utils.paths.basename(pathValue, ext);
}
}