1
>
/*---------------------------------------------------------------------------------------------
resources.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { CharCode } from './charCode.js';
7
>
import * as extpath from './extpath.js';
8
>
import { Schemas } from './network.js';
9
>
import * as paths from './path.js';
10
>
import { isLinux, isWindows } from './platform.js';
11
>
import { compare as strCompare, equalsIgnoreCase } from './strings.js';
12
>
import { URI, uriToFsPath } from './uri.js';
13
>
14
>
export function originalFSPath(uri: URI): string {
15
return uriToFsPath(uri, true);
16
}
18
>
//#region IExtUri
19
>
20
>
export interface IExtUri {
21
>
22
>
// --- identity
23
>
24
>
/**
25
>
* Compares two uris.
26
>
*
27
>
* @param uri1 Uri
28
>
* @param uri2 Uri
29
>
* @param ignoreFragment Ignore the fragment (defaults to `false`)
30
>
*/
31
>
compare(uri1: URI, uri2: URI, ignoreFragment?: boolean): number;
32
>
33
>
/**
34
>
* Tests whether two uris are equal
35
>
*
36
>
* @param uri1 Uri
37
>
* @param uri2 Uri
38
>
* @param ignoreFragment Ignore the fragment (defaults to `false`)
39
>
*/
40
>
isEqual(uri1: URI | undefined, uri2: URI | undefined, ignoreFragment?: boolean): boolean;
41
>
42
>
/**
43
>
* Tests whether a `candidate` URI is a parent or equal of a given `base` URI.
44
>
*
45
>
* @param base A uri which is "longer" or at least same length as `parentCandidate`
46
>
* @param parentCandidate A uri which is "shorter" or up to same length as `base`
47
>
* @param ignoreFragment Ignore the fragment (defaults to `false`)
48
>
*/
49
>
isEqualOrParent(base: URI, parentCandidate: URI, ignoreFragment?: boolean): boolean;
50
>
51
>
/**
52
>
* Creates a key from a resource URI to be used to resource comparison and for resource maps.
53
>
* @see {@link ResourceMap}
54
>
* @param uri Uri
55
>
* @param ignoreFragment Ignore the fragment (defaults to `false`)
56
>
*/
57
>
getComparisonKey(uri: URI, ignoreFragment?: boolean): string;
58
>
59
>
/**
60
>
* Whether the casing of the path-component of the uri should be ignored.
61
>
*/
62
>
ignorePathCasing(uri: URI): boolean;
63
>
64
>
// --- path math
65
>
66
>
basenameOrAuthority(resource: URI): string;
67
>
68
>
/**
69
>
* Returns the basename of the path component of an uri.
70
>
* @param resource
71
>
*/
72
>
basename(resource: URI): string;
73
>
74
>
/**
75
>
* Returns the extension of the path component of an uri.
76
>
* @param resource
77
>
*/
78
>
extname(resource: URI): string;
79
>
/**
80
>
* Return a URI representing the directory of a URI path.
81
>
*
82
>
* @param resource The input URI.
83
>
* @returns The URI representing the directory of the input URI.
84
>
*/
85
>
dirname(resource: URI): URI;
86
>
/**
87
>
* Join a URI path with path fragments and normalizes the resulting path.
88
>
*
89
>
* @param resource The input URI.
90
>
* @param pathFragment The path fragment to add to the URI path.
91
>
* @returns The resulting URI.
92
>
*/
93
>
joinPath(resource: URI, ...pathFragment: string[]): URI;
94
>
/**
95
>
* Normalizes the path part of a URI: Resolves `.` and `..` elements with directory names.
96
>
*
97
>
* @param resource The URI to normalize the path.
98
>
* @returns The URI with the normalized path.
99
>
*/
100
>
normalizePath(resource: URI): URI;
101
>
/**
102
>
*
103
>
* @param from
104
>
* @param to
105
>
*/
106
>
relativePath(from: URI, to: URI): string | undefined;
107
>
/**
108
>
* Resolves an absolute or relative path against a base URI.
109
>
* The path can be relative or absolute posix or a Windows path
110
>
*/
111
>
resolvePath(base: URI, path: string): URI;
112
>
113
>
// --- misc
114
>
115
>
/**
116
>
* Returns true if the URI path is absolute.
117
>
*/
118
>
isAbsolutePath(resource: URI): boolean;
119
>
/**
120
>
* Tests whether the two authorities are the same
121
>
*/
122
>
isEqualAuthority(a1: string, a2: string): boolean;
123
>
/**
124
>
* Returns true if the URI path has a trailing path separator
125
>
*/
126
>
hasTrailingPathSeparator(resource: URI, sep?: string): boolean;
127
>
/**
128
>
* Removes a trailing path separator, if there's one.
129
>
* Important: Doesn't remove the first slash, it would make the URI invalid
130
>
*/
131
>
removeTrailingPathSeparator(resource: URI, sep?: string): URI;
132
>
/**
133
>
* Adds a trailing path separator to the URI if there isn't one already.
134
>
* For example, c:\ would be unchanged, but c:\users would become c:\users\
135
>
*/
136
>
addTrailingPathSeparator(resource: URI, sep?: string): URI;
137
>
}
138
>
139
>
export class ExtUri implements IExtUri {
140
>
141
>
constructor(private _ignorePathCasing: (uri: URI) => boolean) { }
142
>
143
>
compare(uri1: URI, uri2: URI, ignoreFragment: boolean = false): number {
144
if (uri1 === uri2) {
145
return 0;