|
1 | 1 | import * as vscode from 'vscode'; |
| 2 | +import DocumentStore from '../core/document.store'; |
| 3 | +import { TextEncoder } from 'util'; |
| 4 | +import { Document } from './couch.collection'; |
2 | 5 |
|
3 | 6 | export class CouchFileSystemProvider implements vscode.FileSystemProvider { |
4 | 7 | public static scheme = 'couchdb'; |
5 | 8 |
|
6 | 9 | onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]>; |
7 | 10 |
|
8 | | - constructor() { |
| 11 | + constructor(private readonly documentStore: DocumentStore) { |
9 | 12 | this.onDidChangeFile = new vscode.EventEmitter< |
10 | 13 | vscode.FileChangeEvent[] |
11 | 14 | >().event; |
12 | 15 | } |
13 | 16 |
|
14 | | - watch( |
| 17 | + public watch( |
15 | 18 | uri: vscode.Uri, |
16 | 19 | options: { readonly recursive: boolean; readonly excludes: readonly string[] } |
17 | 20 | ): vscode.Disposable { |
18 | | - throw new Error('Method not implemented.'); |
| 21 | + console.log('watch', uri, options); |
| 22 | + |
| 23 | + return new vscode.Disposable(() => {}); |
19 | 24 | } |
20 | 25 |
|
21 | | - stat(uri: vscode.Uri): vscode.FileStat | Thenable<vscode.FileStat> { |
22 | | - throw new Error('Method not implemented.'); |
| 26 | + public stat(uri: vscode.Uri): vscode.FileStat { |
| 27 | + const doc = this.documentStore.findByURI(uri); |
| 28 | + |
| 29 | + return { |
| 30 | + type: vscode.FileType.File, |
| 31 | + ctime: (doc as Document).ctime, |
| 32 | + mtime: (doc as Document).mtime, |
| 33 | + size: new TextEncoder().encode((doc as Document).content || '').length, |
| 34 | + }; |
23 | 35 | } |
24 | 36 |
|
25 | | - readDirectory( |
| 37 | + public readDirectory( |
26 | 38 | uri: vscode.Uri |
27 | 39 | ): [string, vscode.FileType][] | Thenable<[string, vscode.FileType][]> { |
28 | | - throw new Error('Method not implemented.'); |
| 40 | + console.log('readDirectory', uri); |
| 41 | + |
| 42 | + return Promise.reject(); |
29 | 43 | } |
30 | 44 |
|
31 | | - createDirectory(uri: vscode.Uri): void | Thenable<void> { |
32 | | - throw new Error('Method not implemented.'); |
| 45 | + public createDirectory(uri: vscode.Uri): void | Thenable<void> { |
| 46 | + console.log('createDirectory', uri); |
| 47 | + |
| 48 | + return Promise.reject(); |
33 | 49 | } |
34 | 50 |
|
35 | | - readFile(uri: vscode.Uri): Uint8Array | Thenable<Uint8Array> { |
36 | | - throw new Error('Method not implemented.'); |
| 51 | + public async readFile(uri: vscode.Uri): Promise<Uint8Array> { |
| 52 | + const document = await this.documentStore.get({ |
| 53 | + source: uri.authority, |
| 54 | + _id: uri.path.slice(1), |
| 55 | + }); |
| 56 | + |
| 57 | + if (!document) { |
| 58 | + throw new Error('Document not found'); |
| 59 | + } |
| 60 | + |
| 61 | + return new TextEncoder().encode(document.content); |
37 | 62 | } |
38 | 63 |
|
39 | | - writeFile( |
| 64 | + public writeFile( |
40 | 65 | uri: vscode.Uri, |
41 | 66 | content: Uint8Array, |
42 | 67 | options: { readonly create: boolean; readonly overwrite: boolean } |
43 | 68 | ): void | Thenable<void> { |
44 | | - throw new Error('Method not implemented.'); |
| 69 | + console.log('writeFile', uri, content, options); |
| 70 | + |
| 71 | + return Promise.reject(); |
45 | 72 | } |
46 | 73 |
|
47 | | - delete( |
| 74 | + public delete( |
48 | 75 | uri: vscode.Uri, |
49 | 76 | options: { readonly recursive: boolean } |
50 | 77 | ): void | Thenable<void> { |
51 | | - throw new Error('Method not implemented.'); |
| 78 | + console.log('delete', uri, options); |
| 79 | + |
| 80 | + return Promise.reject(); |
52 | 81 | } |
53 | 82 |
|
54 | | - rename( |
| 83 | + public rename( |
55 | 84 | oldUri: vscode.Uri, |
56 | 85 | newUri: vscode.Uri, |
57 | 86 | options: { readonly overwrite: boolean } |
58 | 87 | ): void | Thenable<void> { |
59 | | - throw new Error('Method not implemented.'); |
| 88 | + console.log('rename', oldUri, newUri, options); |
| 89 | + |
| 90 | + return Promise.reject(); |
60 | 91 | } |
61 | 92 |
|
62 | | - copy?( |
| 93 | + public copy?( |
63 | 94 | source: vscode.Uri, |
64 | 95 | destination: vscode.Uri, |
65 | 96 | options: { readonly overwrite: boolean } |
66 | 97 | ): void | Thenable<void> { |
67 | | - throw new Error('Method not implemented.'); |
| 98 | + console.log('copy', source, destination, options); |
| 99 | + |
| 100 | + return Promise.reject(); |
68 | 101 | } |
69 | 102 | } |
0 commit comments