Skip to content

Commit d3a4193

Browse files
author
Akos Kitta
committed
fix: aligned file resource API changes to Theia
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 4efdb3d commit d3a4193

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

Diff for: arduino-ide-extension/src/browser/theia/filesystem/file-resource.ts

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { ResourceSaveOptions } from '@theia/core/lib/common/resource';
2-
import { Readable } from '@theia/core/lib/common/stream';
31
import URI from '@theia/core/lib/common/uri';
42
import { injectable } from '@theia/core/shared/inversify';
53
import {
@@ -11,14 +9,13 @@ import { FileService } from '@theia/filesystem/lib/browser/file-service';
119
import {
1210
FileOperationError,
1311
FileOperationResult,
14-
FileStat,
1512
} from '@theia/filesystem/lib/common/files';
1613
import * as PQueue from 'p-queue';
1714

1815
@injectable()
1916
export class FileResourceResolver extends TheiaFileResourceResolver {
2017
override async resolve(uri: URI): Promise<WriteQueuedFileResource> {
21-
let stat: FileStat | undefined;
18+
let stat;
2219
try {
2320
stat = await this.fileService.resolve(uri);
2421
} catch (e) {
@@ -37,6 +34,7 @@ export class FileResourceResolver extends TheiaFileResourceResolver {
3734
);
3835
}
3936
return new WriteQueuedFileResource(uri, this.fileService, {
37+
isReadonly: stat?.isReadonly ?? false,
4038
shouldOverwrite: () => this.shouldOverwrite(uri),
4139
shouldOpenAsText: (error) => this.shouldOpenAsText(uri, error),
4240
});
@@ -52,23 +50,32 @@ class WriteQueuedFileResource extends FileResource {
5250
options: FileResourceOptions
5351
) {
5452
super(uri, fileService, options);
53+
const originalDoWrite = this['doWrite'];
54+
this['doWrite'] = (content, options) =>
55+
this.writeQueue.add(() => originalDoWrite.bind(this)(content, options));
56+
const originalSaveStream = this['saveStream'];
57+
if (originalSaveStream) {
58+
this['saveStream'] = (content, options) =>
59+
this.writeQueue.add(() =>
60+
originalSaveStream.bind(this)(content, options)
61+
);
62+
}
63+
const originalSaveContents = this['saveContents'];
64+
if (originalSaveContents) {
65+
this['saveContents'] = (content, options) =>
66+
this.writeQueue.add(() =>
67+
originalSaveContents.bind(this)(content, options)
68+
);
69+
}
5570
const originalSaveContentChanges = this['saveContentChanges'];
5671
if (originalSaveContentChanges) {
57-
this['saveContentChanges'] = (changes, options) => {
58-
return this.writeQueue.add(() =>
72+
this['saveContentChanges'] = (changes, options) =>
73+
this.writeQueue.add(() =>
5974
originalSaveContentChanges.bind(this)(changes, options)
6075
);
61-
};
6276
}
6377
}
6478

65-
protected override async doWrite(
66-
content: string | Readable<string>,
67-
options?: ResourceSaveOptions
68-
): Promise<void> {
69-
return this.writeQueue.add(() => super.doWrite(content, options));
70-
}
71-
7279
protected override async isInSync(): Promise<boolean> {
7380
// Let all the write operations finish to update the version (mtime) before checking whether the resource is in sync.
7481
// https://github.com/eclipse-theia/theia/issues/12327

0 commit comments

Comments
 (0)