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
36 lines (35 loc) · 1.31 KB
/
pathUtils.ts
File metadata and controls
36 lines (35 loc) · 1.31 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
import { inject, injectable } from 'inversify';
import * as path from 'path';
import { IPathUtils, IsWindows } from '../types';
import { NON_WINDOWS_PATH_VARIABLE_NAME, WINDOWS_PATH_VARIABLE_NAME } from './constants';
// tslint:disable-next-line:no-var-requires no-require-imports
const untildify = require('untildify');
@injectable()
export class PathUtils implements IPathUtils {
public readonly home = '';
constructor(@inject(IsWindows) private isWindows: boolean) {
this.home = untildify('~');
}
public get delimiter(): string {
return path.delimiter;
}
public get separator(): string {
return path.sep;
}
// TO DO: Deprecate in favor of IPlatformService
public getPathVariableName() {
return this.isWindows ? WINDOWS_PATH_VARIABLE_NAME : NON_WINDOWS_PATH_VARIABLE_NAME;
}
public basename(pathValue: string, ext?: string): string {
return path.basename(pathValue, ext);
}
public getDisplayName(pathValue: string, cwd?: string): string {
if (cwd && pathValue.startsWith(cwd)) {
return `.${path.sep}${path.relative(cwd, pathValue)}`;
} else if (pathValue.startsWith(this.home)) {
return `~${path.sep}${path.relative(this.home, pathValue)}`;
} else {
return pathValue;
}
}
}