MCPcopy Index your code
hub / github.com/VSpaceCode/VSpaceCode / relativePath

Function relativePath

src/pathCommands.ts:203–239  ·  view source on GitHub ↗

* Compute the relative path of two uris. * * This differs from the vscode version is that this doesn't normalize slash for Windows; therefore, * we can use posix path to compute relative instead of host machine specific path. * * Modified from https://github.com/microsoft/vscode/blob/f74e473238

(
    from: Uri,
    to: Uri,
    ignorePathCasing = false
)

Source from the content-addressed store, hash-verified

201 * Modified from https://github.com/microsoft/vscode/blob/f74e473238aca7b79c08be761d99a0232838ca4c/src/vs/base/common/resources.ts#L228-L249
202 */
203function relativePath(
204 from: Uri,
205 to: Uri,
206 ignorePathCasing = false
207): string | undefined {
208 if (
209 from.scheme !== to.scheme ||
210 !isEqualAuthority(from.authority, to.authority)
211 ) {
212 return undefined;
213 }
214 if (from.scheme === UriScheme.File) {
215 return path.posix.relative(uriToFsPath(from), uriToFsPath(to));
216 }
217 let fromPath = from.path || "/";
218 const toPath = to.path || "/";
219 if (ignorePathCasing) {
220 // make casing of fromPath match toPath
221 let i = 0;
222 for (
223 const len = Math.min(fromPath.length, toPath.length);
224 i < len;
225 i++
226 ) {
227 if (fromPath.charCodeAt(i) !== toPath.charCodeAt(i)) {
228 if (
229 fromPath.charAt(i).toLowerCase() !==
230 toPath.charAt(i).toLowerCase()
231 ) {
232 break;
233 }
234 }
235 }
236 fromPath = toPath.substr(0, i) + fromPath.substr(i);
237 }
238 return path.posix.relative(fromPath, toPath);
239}

Callers 1

relativePathToWorkspaceFunction · 0.85

Calls 2

isEqualAuthorityFunction · 0.85
uriToFsPathFunction · 0.85

Tested by

no test coverage detected