Skip to content

Commit

Permalink
fix: readonly editors
Browse files Browse the repository at this point in the history
Closes arduino#1501
Upstream: eclipse-theia/theia#12354

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed Apr 20, 2023
1 parent 1142296 commit e4fc3cf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions arduino-ide-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"ncp": "^2.0.0",
"protoc": "^1.0.4",
"shelljs": "^0.8.3",
"stat-mode": "^1.0.0",
"uuid": "^3.2.1",
"yargs": "^11.1.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export class MonacoTextModelService extends TheiaMonacoTextModelService {
const factory = this.factories
.getContributions()
.find(({ scheme }) => resource.uri.scheme === scheme);
const readOnly = this.sketchesServiceClient.isReadOnly(resource.uri);
const readOnly =
resource.isReadonly ??
this.sketchesServiceClient.isReadOnly(resource.uri);
return factory
? factory.createModel(resource)
: new MaybeReadonlyMonacoEditorModel(
Expand Down
5 changes: 5 additions & 0 deletions arduino-ide-extension/src/node/arduino-ide-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ import {
PluginDeployer_GH_12064,
} from './theia/plugin-ext/plugin-deployer';
import { SettingsReader } from './settings-reader';
import { DiskFileSystemProvider } from './theia/filesystem/disk-file-system-provider';
import { DiskFileSystemProvider as TheiaDiskFileSystemProvider } from '@theia/filesystem/lib/node/disk-file-system-provider';

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

bind(SettingsReader).toSelf().inSingletonScope();

bind(DiskFileSystemProvider).toSelf().inSingletonScope();
rebind(TheiaDiskFileSystemProvider).toService(DiskFileSystemProvider);
});

function bindChildLogger(bind: interfaces.Bind, name: string): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import URI from '@theia/core/lib/common/uri';
import { injectable } from '@theia/core/shared/inversify';
import { FilePermission, Stat } from '@theia/filesystem/lib/common/files';
import { DiskFileSystemProvider as TheiaDiskFileSystemProvider } from '@theia/filesystem/lib/node/disk-file-system-provider';
import { Mode } from 'stat-mode';

@injectable()
export class DiskFileSystemProvider extends TheiaDiskFileSystemProvider {
override async stat(resource: URI): Promise<Stat> {
try {
const { stat, symbolicLink } = await this.statLink(
this.toFilePath(resource)
); // cannot use fs.stat() here to support links properly
const mode = new Mode(stat);
return {
type: this['toType'](stat, symbolicLink),
ctime: stat.birthtime.getTime(), // intentionally not using ctime here, we want the creation time
mtime: stat.mtime.getTime(),
size: stat.size,
permissions: !mode.owner.write ? FilePermission.Readonly : undefined, // Customized for https://github.com/eclipse-theia/theia/pull/12354
};
} catch (error) {
throw this['toFileSystemProviderError'](error);
}
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13839,6 +13839,11 @@ ssri@^9.0.0, ssri@^9.0.1:
dependencies:
minipass "^3.1.1"

stat-mode@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/stat-mode/-/stat-mode-1.0.0.tgz#68b55cb61ea639ff57136f36b216a291800d1465"
integrity sha512-jH9EhtKIjuXZ2cWxmXS8ZP80XyC3iasQxMDV8jzhNJpfDb7VbQLVW4Wvsxz9QZvzV+G4YoSfBUVKDOyxLzi/sg==

static-extend@^0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"
Expand Down

0 comments on commit e4fc3cf

Please sign in to comment.