| 16 | Logger.setLevel('error'); |
| 17 | |
| 18 | export class InMemoryDataStore implements IDataStore { |
| 19 | private files = new Map<string, string>(); |
| 20 | |
| 21 | set(uri: URI, content: string): void { |
| 22 | this.files.set(uri.path, content); |
| 23 | } |
| 24 | |
| 25 | async delete(uri: URI): Promise<void> { |
| 26 | this.files.delete(uri.path); |
| 27 | } |
| 28 | |
| 29 | clear(): void { |
| 30 | this.files.clear(); |
| 31 | } |
| 32 | |
| 33 | async list(pattern?: string): Promise<URI[]> { |
| 34 | const paths = Array.from(this.files.keys()); |
| 35 | if (!pattern) { |
| 36 | return paths.map(p => URI.parse(p, 'file')); |
| 37 | } |
| 38 | const matched = micromatch(paths, [`**/${pattern}`]); |
| 39 | return matched.map(p => URI.parse(p, 'file')); |
| 40 | } |
| 41 | |
| 42 | async read(uri: URI): Promise<string | null> { |
| 43 | return this.files.get(uri.path) ?? null; |
| 44 | } |
| 45 | |
| 46 | async write(uri: URI, content: string): Promise<void> { |
| 47 | this.files.set(uri.path, content); |
| 48 | } |
| 49 | |
| 50 | async move(from: URI, to: URI): Promise<void> { |
| 51 | const content = this.files.get(from.path); |
| 52 | if (content === undefined) { |
| 53 | throw new Error(`Source file not found: ${from.path}`); |
| 54 | } |
| 55 | this.files.delete(from.path); |
| 56 | this.files.set(to.path, content); |
| 57 | } |
| 58 | |
| 59 | async exists(uri: URI): Promise<boolean> { |
| 60 | return this.files.has(uri.path); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | const position = Range.create(0, 0, 0, 100); |
| 65 |
nothing calls this directly
no outgoing calls
no test coverage detected