Skip to content

Commit e4fc3cf

Browse files
author
Akos Kitta
committed
fix: readonly editors
Closes arduino#1501 Upstream: eclipse-theia/theia#12354 Signed-off-by: Akos Kitta <[email protected]>
1 parent 1142296 commit e4fc3cf

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

Diff for: arduino-ide-extension/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"ncp": "^2.0.0",
124124
"protoc": "^1.0.4",
125125
"shelljs": "^0.8.3",
126+
"stat-mode": "^1.0.0",
126127
"uuid": "^3.2.1",
127128
"yargs": "^11.1.0"
128129
},

Diff for: arduino-ide-extension/src/browser/theia/monaco/monaco-text-model-service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export class MonacoTextModelService extends TheiaMonacoTextModelService {
1919
const factory = this.factories
2020
.getContributions()
2121
.find(({ scheme }) => resource.uri.scheme === scheme);
22-
const readOnly = this.sketchesServiceClient.isReadOnly(resource.uri);
22+
const readOnly =
23+
resource.isReadonly ??
24+
this.sketchesServiceClient.isReadOnly(resource.uri);
2325
return factory
2426
? factory.createModel(resource)
2527
: new MaybeReadonlyMonacoEditorModel(

Diff for: arduino-ide-extension/src/node/arduino-ide-backend-module.ts

+5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ import {
119119
PluginDeployer_GH_12064,
120120
} from './theia/plugin-ext/plugin-deployer';
121121
import { SettingsReader } from './settings-reader';
122+
import { DiskFileSystemProvider } from './theia/filesystem/disk-file-system-provider';
123+
import { DiskFileSystemProvider as TheiaDiskFileSystemProvider } from '@theia/filesystem/lib/node/disk-file-system-provider';
122124

123125
export default new ContainerModule((bind, unbind, isBound, rebind) => {
124126
bind(BackendApplication).toSelf().inSingletonScope();
@@ -406,6 +408,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
406408
rebind(PluginDeployer).to(PluginDeployer_GH_12064).inSingletonScope();
407409

408410
bind(SettingsReader).toSelf().inSingletonScope();
411+
412+
bind(DiskFileSystemProvider).toSelf().inSingletonScope();
413+
rebind(TheiaDiskFileSystemProvider).toService(DiskFileSystemProvider);
409414
});
410415

411416
function bindChildLogger(bind: interfaces.Bind, name: string): void {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import URI from '@theia/core/lib/common/uri';
2+
import { injectable } from '@theia/core/shared/inversify';
3+
import { FilePermission, Stat } from '@theia/filesystem/lib/common/files';
4+
import { DiskFileSystemProvider as TheiaDiskFileSystemProvider } from '@theia/filesystem/lib/node/disk-file-system-provider';
5+
import { Mode } from 'stat-mode';
6+
7+
@injectable()
8+
export class DiskFileSystemProvider extends TheiaDiskFileSystemProvider {
9+
override async stat(resource: URI): Promise<Stat> {
10+
try {
11+
const { stat, symbolicLink } = await this.statLink(
12+
this.toFilePath(resource)
13+
); // cannot use fs.stat() here to support links properly
14+
const mode = new Mode(stat);
15+
return {
16+
type: this['toType'](stat, symbolicLink),
17+
ctime: stat.birthtime.getTime(), // intentionally not using ctime here, we want the creation time
18+
mtime: stat.mtime.getTime(),
19+
size: stat.size,
20+
permissions: !mode.owner.write ? FilePermission.Readonly : undefined, // Customized for https://github.com/eclipse-theia/theia/pull/12354
21+
};
22+
} catch (error) {
23+
throw this['toFileSystemProviderError'](error);
24+
}
25+
}
26+
}

Diff for: yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -13839,6 +13839,11 @@ ssri@^9.0.0, ssri@^9.0.1:
1383913839
dependencies:
1384013840
minipass "^3.1.1"
1384113841

13842+
stat-mode@^1.0.0:
13843+
version "1.0.0"
13844+
resolved "https://registry.yarnpkg.com/stat-mode/-/stat-mode-1.0.0.tgz#68b55cb61ea639ff57136f36b216a291800d1465"
13845+
integrity sha512-jH9EhtKIjuXZ2cWxmXS8ZP80XyC3iasQxMDV8jzhNJpfDb7VbQLVW4Wvsxz9QZvzV+G4YoSfBUVKDOyxLzi/sg==
13846+
1384213847
static-extend@^0.1.1:
1384313848
version "0.1.2"
1384413849
resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"

0 commit comments

Comments
 (0)