-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added poc for in-memory COMMIT_MESSAGE file editor handling
- Loading branch information
1 parent
e000928
commit f18ba9a
Showing
5 changed files
with
114 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { FileSystemProvider, FileChangeEvent, EventEmitter, Event, Disposable, FileStat, Uri, FileType, workspace, FileSystemError } from 'vscode'; | ||
import { EmptyDisposable } from './util'; | ||
import { promises as fs } from 'fs'; | ||
|
||
export class GitCommitFileSystemProvider implements FileSystemProvider { | ||
private _onDidChangeFile = new EventEmitter<FileChangeEvent[]>(); | ||
readonly onDidChangeFile: Event<FileChangeEvent[]> = this._onDidChangeFile.event; | ||
|
||
private disposables: Disposable[] = []; | ||
|
||
private fileCache: Record<string, Uint8Array> = {}; | ||
|
||
constructor() { | ||
this.disposables.push( | ||
workspace.registerFileSystemProvider('gitcommit', this, { isReadonly: false, isCaseSensitive: true }), | ||
workspace.registerResourceLabelFormatter({ | ||
scheme: 'gitcommit', | ||
formatting: { | ||
label: '${authority} (gitcommit)', | ||
separator: '/' | ||
} | ||
}) | ||
); | ||
} | ||
|
||
async stat(uri: Uri): Promise<FileStat> { | ||
// TODO: Should we do error handling here? If so, we may need sth like toFileSystemProviderErrorCode | ||
if (this.fileCache[uri.authority]) { | ||
return { type: FileType.File, ctime: 0, mtime: 0, size: this.fileCache[uri.authority].length }; | ||
} | ||
|
||
const { size } = await fs.stat(uri.fsPath); | ||
return { ctime: 0, mtime: 0, size, type: FileType.File }; | ||
} | ||
|
||
readDirectory(): Thenable<[string, FileType][]> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
createDirectory(): void { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
async readFile(uri: Uri): Promise<Uint8Array> { | ||
// TODO: Should we do more error handling here? If so, we may need sth like toFileSystemProviderErrorCode | ||
if (!this.fileCache[uri.authority]) { | ||
try { | ||
this.fileCache[uri.authority] = await fs.readFile(uri.fsPath); | ||
} catch (error) { | ||
// TODO ingore for now, maybe go for toFileSystemProviderErrorCode | ||
} | ||
} | ||
return this.fileCache[uri.authority]; | ||
} | ||
|
||
async writeFile(uri: Uri, content: Uint8Array): Promise<void> { | ||
if (this.fileCache[uri.authority]) { | ||
this.fileCache[uri.authority] = content; | ||
} else { | ||
throw FileSystemError.FileNotFound(); | ||
} | ||
} | ||
|
||
delete(uri: Uri): void { | ||
if (this.fileCache[uri.authority]) { | ||
delete this.fileCache[uri.authority]; | ||
} else { | ||
throw FileSystemError.FileNotFound(); | ||
} | ||
} | ||
|
||
rename(): void { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
dispose(): void { | ||
this.disposables.forEach(d => d.dispose()); | ||
} | ||
|
||
watch(): Disposable { | ||
return EmptyDisposable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,11 @@ | |
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.31.tgz#d6b4f9645fee17f11319b508fb1001797425da51" | ||
integrity sha512-T+wnJno8uh27G9c+1T+a1/WYCHzLeDqtsGJkoEdSp2X8RTh3oOCZQcUnjAx90CS8cmmADX51O0FI/tu9s0yssg== | ||
|
||
"@types/uuid@^8.0.0": | ||
version "8.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.0.0.tgz#165aae4819ad2174a17476dbe66feebd549556c0" | ||
integrity sha512-xSQfNcvOiE5f9dyd4Kzxbof1aTrLobL278pGLKOZI6esGfZ7ts9Ka16CzIN6Y8hFHE1C7jIBZokULhK1bOgjRw== | ||
|
||
"@types/which@^1.0.28": | ||
version "1.0.28" | ||
resolved "https://registry.yarnpkg.com/@types/which/-/which-1.0.28.tgz#016e387629b8817bed653fe32eab5d11279c8df6" | ||
|
@@ -850,6 +855,11 @@ uuid@^3.3.2: | |
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" | ||
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== | ||
|
||
uuid@^8.2.0: | ||
version "8.2.0" | ||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.2.0.tgz#cb10dd6b118e2dada7d0cd9730ba7417c93d920e" | ||
integrity sha512-CYpGiFTUrmI6OBMkAdjSDM0k5h8SkkiTP4WAjQgDgNB1S3Ou9VBEvr6q0Kv2H1mMk7IWfxYGpMH5sd5AvcIV2Q== | ||
|
||
[email protected]: | ||
version "1.10.0" | ||
resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400" | ||
|