1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.URI = void 0;
|
19 | const vscode_uri_1 = require("vscode-uri");
|
20 | const path_1 = require("./path");
|
21 | class URI {
|
22 | constructor(uri = '') {
|
23 | if (uri instanceof vscode_uri_1.URI) {
|
24 | this.codeUri = uri;
|
25 | }
|
26 | else {
|
27 | this.codeUri = vscode_uri_1.URI.parse(uri);
|
28 | }
|
29 | }
|
30 | static fromComponents(components) {
|
31 | return new URI(vscode_uri_1.URI.revive(components));
|
32 | }
|
33 | static fromFilePath(path) {
|
34 | return new URI(vscode_uri_1.URI.file(path));
|
35 | }
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 | get displayName() {
|
42 | const base = this.path.base;
|
43 | if (base) {
|
44 | return base;
|
45 | }
|
46 | if (this.path.isRoot) {
|
47 | return this.path.fsPath();
|
48 | }
|
49 | return '';
|
50 | }
|
51 | |
52 |
|
53 |
|
54 | get allLocations() {
|
55 | const locations = [];
|
56 | let location = this;
|
57 | while (!location.path.isRoot && location.path.hasDir) {
|
58 | locations.push(location);
|
59 | location = location.parent;
|
60 | }
|
61 | locations.push(location);
|
62 | return locations;
|
63 | }
|
64 | get parent() {
|
65 | if (this.path.isRoot) {
|
66 | return this;
|
67 | }
|
68 | return this.withPath(this.path.dir);
|
69 | }
|
70 | relative(uri) {
|
71 | if (this.authority !== uri.authority || this.scheme !== uri.scheme) {
|
72 | return undefined;
|
73 | }
|
74 | return this.path.relative(uri.path);
|
75 | }
|
76 | resolve(path) {
|
77 | return this.withPath(this.path.join(path.toString()));
|
78 | }
|
79 | |
80 |
|
81 |
|
82 | resolveToAbsolute(...pathSegments) {
|
83 | const absolutePath = this.path.resolve(...pathSegments.map(path => path.toString()));
|
84 | if (absolutePath) {
|
85 | return this.withPath(absolutePath);
|
86 | }
|
87 | }
|
88 | |
89 |
|
90 |
|
91 | withScheme(scheme) {
|
92 | const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme }));
|
93 | return new URI(newCodeUri);
|
94 | }
|
95 | |
96 |
|
97 |
|
98 | withAuthority(authority) {
|
99 | const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, authority }));
|
100 | return new URI(newCodeUri);
|
101 | }
|
102 | |
103 |
|
104 |
|
105 | withoutAuthority() {
|
106 | return this.withAuthority('');
|
107 | }
|
108 | |
109 |
|
110 |
|
111 | withPath(path) {
|
112 | const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, path: path.toString() }));
|
113 | return new URI(newCodeUri);
|
114 | }
|
115 | |
116 |
|
117 |
|
118 | withoutPath() {
|
119 | return this.withPath('');
|
120 | }
|
121 | |
122 |
|
123 |
|
124 | withQuery(query) {
|
125 | const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, query }));
|
126 | return new URI(newCodeUri);
|
127 | }
|
128 | |
129 |
|
130 |
|
131 | withoutQuery() {
|
132 | return this.withQuery('');
|
133 | }
|
134 | |
135 |
|
136 |
|
137 | withFragment(fragment) {
|
138 | const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, fragment }));
|
139 | return new URI(newCodeUri);
|
140 | }
|
141 | |
142 |
|
143 |
|
144 | withoutFragment() {
|
145 | return this.withFragment('');
|
146 | }
|
147 | |
148 |
|
149 |
|
150 | normalizePath() {
|
151 | return this.withPath(this.path.normalize());
|
152 | }
|
153 | get scheme() {
|
154 | return this.codeUri.scheme;
|
155 | }
|
156 | get authority() {
|
157 | return this.codeUri.authority;
|
158 | }
|
159 | get path() {
|
160 | if (this._path === undefined) {
|
161 | this._path = new path_1.Path(this.codeUri.path);
|
162 | }
|
163 | return this._path;
|
164 | }
|
165 | get query() {
|
166 | return this.codeUri.query;
|
167 | }
|
168 | get fragment() {
|
169 | return this.codeUri.fragment;
|
170 | }
|
171 | toString(skipEncoding) {
|
172 | return this.codeUri.toString(skipEncoding);
|
173 | }
|
174 | isEqual(uri, caseSensitive = true) {
|
175 | if (!this.hasSameOrigin(uri)) {
|
176 | return false;
|
177 | }
|
178 | return caseSensitive
|
179 | ? this.toString() === uri.toString()
|
180 | : this.toString().toLowerCase() === uri.toString().toLowerCase();
|
181 | }
|
182 | isEqualOrParent(uri, caseSensitive = true) {
|
183 | if (!this.hasSameOrigin(uri)) {
|
184 | return false;
|
185 | }
|
186 | let left = this.path;
|
187 | let right = uri.path;
|
188 | if (!caseSensitive) {
|
189 | left = new path_1.Path(left.toString().toLowerCase());
|
190 | right = new path_1.Path(right.toString().toLowerCase());
|
191 | }
|
192 | return left.isEqualOrParent(right);
|
193 | }
|
194 | static getDistinctParents(uris) {
|
195 | const result = [];
|
196 | uris.forEach((uri, i) => {
|
197 | if (!uris.some((otherUri, index) => index !== i && otherUri.isEqualOrParent(uri))) {
|
198 | result.push(uri);
|
199 | }
|
200 | });
|
201 | return result;
|
202 | }
|
203 | hasSameOrigin(uri) {
|
204 | return (this.authority === uri.authority) && (this.scheme === uri.scheme);
|
205 | }
|
206 | toComponents() {
|
207 | return {
|
208 | scheme: this.scheme,
|
209 | authority: this.authority,
|
210 | path: this.path.toString(),
|
211 | query: this.query,
|
212 | fragment: this.fragment
|
213 | };
|
214 | }
|
215 | }
|
216 | exports.URI = URI;
|
217 | exports.default = URI;
|
218 |
|
\ | No newline at end of file |