提交 f2c2d9c6 编写于 作者: J Johannes Rieken

tweak URI to keep it compatible with gitlens, fyi @eamodio

上级 c43a66e7
......@@ -139,7 +139,7 @@ export default class URI {
* invalid characters and semantics. Will *not* look at the scheme of this URI.
*/
get fsPath(): string {
throw new Error('not implemented');
return _makeFsPath(this);
}
// ---- modify to new -------------------------
......@@ -261,7 +261,7 @@ export default class URI {
* @param skipEncoding Do not encode the result, default is `false`
*/
public toString(skipEncoding: boolean = false): string {
throw new Error('not implemented');
return _asFormatted(this, skipEncoding);
}
public toJSON(): any {
......@@ -308,6 +308,20 @@ export default class URI {
}
}
interface UriComponents {
scheme: string;
authority: string;
path: string;
query: string;
fragment: string;
}
interface UriState extends UriComponents {
$mid: number;
fsPath: string;
external: string;
}
// tslint:disable-next-line:class-name
class _URI extends URI {
......@@ -317,21 +331,7 @@ class _URI extends URI {
get fsPath(): string {
if (!this._fsPath) {
let value: string;
if (this.authority && this.path && this.scheme === 'file') {
// unc path: file://shares/c$/far/boo
value = `//${this.authority}${this.path}`;
} else if (_driveLetterPath.test(this.path)) {
// windows drive letter: file:///c:/far/boo
value = this.path[1].toLowerCase() + this.path.substr(2);
} else {
// other path
value = this.path;
}
if (platform.isWindows) {
value = value.replace(/\//g, '\\');
}
this._fsPath = value;
this._fsPath = _makeFsPath(this);
}
return this._fsPath;
}
......@@ -339,16 +339,44 @@ class _URI extends URI {
public toString(skipEncoding: boolean = false): string {
if (!skipEncoding) {
if (!this._formatted) {
this._formatted = _URI._asFormatted(this, false);
this._formatted = _asFormatted(this, false);
}
return this._formatted;
} else {
// we don't cache that
return _URI._asFormatted(this, true);
return _asFormatted(this, true);
}
}
}
/**
* Compute `fsPath` for the given uri
* @param uri
*/
function _makeFsPath(uri: URI): string {
let value: string;
if (uri.authority && uri.path && uri.scheme === 'file') {
// unc path: file://shares/c$/far/boo
value = `//${uri.authority}${uri.path}`;
} else if (_driveLetterPath.test(uri.path)) {
// windows drive letter: file:///c:/far/boo
value = uri.path[1].toLowerCase() + uri.path.substr(2);
} else {
// other path
value = uri.path;
}
if (platform.isWindows) {
value = value.replace(/\//g, '\\');
}
return value;
}
private static _asFormatted(uri: URI, skipEncoding: boolean): string {
/**
* Create the external version of a uri
*/
function _asFormatted(uri: URI, skipEncoding: boolean): string {
const encoder = !skipEncoding
? encodeURIComponent2
......@@ -418,19 +446,4 @@ class _URI extends URI {
}
return parts.join(_empty);
}
}
interface UriComponents {
scheme: string;
authority: string;
path: string;
query: string;
fragment: string;
}
interface UriState extends UriComponents {
$mid: number;
fsPath: string;
external: string;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册