1
>
/*---------------------------------------------------------------------------------------------
mockFilesystem.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 { URI } from '../../../../../../../base/common/uri.js';
7
>
import { VSBuffer } from '../../../../../../../base/common/buffer.js';
8
>
import { FileSystemProviderCapabilities, FileType, IFileService, IFileSystemProviderWithFileRealpathCapability, IStat } from '../../../../../../../platform/files/common/files.js';
9
>
import { dirname } from '../../../../../../../base/common/resources.js';
10
>
import { InMemoryFileSystemProvider } from '../../../../../../../platform/files/common/inMemoryFilesystemProvider.js';
11
>
import { ResourceMap } from '../../../../../../../base/common/map.js';
12
>
13
>
/**
14
>
* Test file system provider that extends InMemoryFileSystemProvider with realpath support.
15
>
* Allows tests to define custom realpath mappings to simulate symlinks.
16
>
*/
17
>
export class TestInMemoryFileSystemProviderWithRealPath extends InMemoryFileSystemProvider implements IFileSystemProviderWithFileRealpathCapability {
18
private readonly realPathMappings = new ResourceMap<URI>();
20
>
override get capabilities(): FileSystemProviderCapabilities {
21
return super.capabilities | FileSystemProviderCapabilities.FileRealpath;
22
}
24
>
/**
25
>
* Defines a realpath mapping for a URI.
26
>
* When realpath() is called for the given URI, it will return the mapped realPath.
27
>
* Use this to simulate symlinks - multiple URIs can map to the same realPath.
28
>
*/
29
>
setRealPath(uri: URI, realPath: URI): void {
30
this.realPathMappings.set(uri, realPath);
31
}
33
>
/**
34
>
* Clears all realpath mappings.
35
>
*/
36
>
clearRealPathMappings(): void {
37
this.realPathMappings.clear();
38
}
40
>
/**
41
>
* Returns the realpath for the given resource.
42
>
* If a mapping was set via setRealPath(), returns that mapped path.
43
>
* Otherwise returns the original path (simulating a non-symlink file).
44
>
*/
45
>
async realpath(resource: URI): Promise<string> {
46
const mapped = this.realPathMappings.get(resource);
47
if (mapped) {