Skip to content

Commit a2af5be

Browse files
author
Akos Kitta
committed
remove custom CLI binding.
Signed-off-by: Akos Kitta <[email protected]>
1 parent ff606a5 commit a2af5be

File tree

2 files changed

+3
-118
lines changed

2 files changed

+3
-118
lines changed

arduino-ide-extension/src/node/arduino-ide-backend-module.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
ArduinoFirmwareUploader,
55
ArduinoFirmwareUploaderPath,
66
} from '../common/protocol/arduino-firmware-uploader';
7-
87
import { ILogger } from '@theia/core/lib/common/logger';
98
import {
109
BackendApplicationContribution,
@@ -25,11 +24,7 @@ import { CoreService, CoreServicePath } from '../common/protocol/core-service';
2524
import { ConnectionContainerModule } from '@theia/core/lib/node/messaging/connection-container-module';
2625
import { CoreClientProvider } from './core-client-provider';
2726
import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core';
28-
import {
29-
DefaultWorkspaceServer,
30-
WorkspaceCliContribution,
31-
} from './theia/workspace/default-workspace-server';
32-
import { WorkspaceCliContribution as TheiaWorkspaceCliContribution } from '@theia/workspace/lib/node/default-workspace-server';
27+
import { DefaultWorkspaceServer } from './theia/workspace/default-workspace-server';
3328
import { WorkspaceServer as TheiaWorkspaceServer } from '@theia/workspace/lib/common/workspace-protocol';
3429
import { SketchesServiceImpl } from './sketches-service-impl';
3530
import {
@@ -44,7 +39,6 @@ import {
4439
ArduinoDaemon,
4540
ArduinoDaemonPath,
4641
} from '../common/protocol/arduino-daemon';
47-
4842
import { ConfigServiceImpl } from './config-service-impl';
4943
import { EnvVariablesServer as TheiaEnvVariablesServer } from '@theia/core/lib/common/env-variables';
5044
import { EnvVariablesServer } from './theia/env-variables/env-variables-server';
@@ -231,8 +225,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
231225

232226
bind(DefaultWorkspaceServer).toSelf().inSingletonScope();
233227
rebind(TheiaWorkspaceServer).toService(DefaultWorkspaceServer);
234-
bind(WorkspaceCliContribution).toSelf().inSingletonScope();
235-
rebind(TheiaWorkspaceCliContribution).toService(WorkspaceCliContribution);
236228

237229
bind(EnvVariablesServer).toSelf().inSingletonScope();
238230
rebind(TheiaEnvVariablesServer).toService(EnvVariablesServer);

arduino-ide-extension/src/node/theia/workspace/default-workspace-server.ts

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,9 @@
11
import { promises as fs, constants } from 'fs';
22
import { injectable, inject } from '@theia/core/shared/inversify';
3-
import {
4-
DefaultWorkspaceServer as TheiaDefaultWorkspaceServer,
5-
WorkspaceCliContribution as TheiaWorkspaceCliContribution,
6-
} from '@theia/workspace/lib/node/default-workspace-server';
3+
import { DefaultWorkspaceServer as TheiaDefaultWorkspaceServer } from '@theia/workspace/lib/node/default-workspace-server';
74
import { SketchesService } from '../../../common/protocol';
8-
import { FileUri } from '@theia/core/lib/node/file-uri';
5+
import { FileUri } from '@theia/core/lib/node';
96
import { IsTempSketch } from '../../is-temp-sketch';
10-
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
11-
import { Deferred } from '@theia/core/lib/common/promise-util';
12-
import { MaybePromise } from '@theia/core/lib/common/types';
13-
import URI from '@theia/core/lib/common/uri';
14-
import * as yargs from '@theia/core/shared/yargs';
15-
import { THEIA_EXT } from '@theia/workspace/lib/common/utils';
16-
import * as fsExtra from 'fs-extra';
17-
import * as path from 'path';
18-
19-
@injectable()
20-
export class WorkspaceCliContribution extends TheiaWorkspaceCliContribution {
21-
@inject(EnvVariablesServer)
22-
private readonly envVariablesServer: EnvVariablesServer;
23-
24-
override workspaceRoot = new Deferred<string | undefined>();
25-
26-
override configure(conf: yargs.Argv): void {
27-
conf.usage('$0 [workspace-directories] [options]');
28-
conf.option('root-dir', {
29-
description: 'DEPRECATED: Sets the workspace directory.',
30-
});
31-
}
32-
33-
override async setArguments(args: yargs.Arguments): Promise<void> {
34-
const workspaceArguments = args._.slice(2).map((probablyAlreadyString) =>
35-
String(probablyAlreadyString)
36-
);
37-
if (workspaceArguments.length === 0 && args['root-dir']) {
38-
workspaceArguments.push(String(args['root-dir']));
39-
}
40-
if (workspaceArguments.length === 0) {
41-
this.workspaceRoot.resolve(undefined);
42-
} else if (workspaceArguments.length === 1) {
43-
this.workspaceRoot.resolve(
44-
this.normalizeWorkspaceArg(workspaceArguments[0])
45-
);
46-
} else {
47-
this.workspaceRoot.resolve(
48-
await this.buildWorkspaceForMultipleArguments(workspaceArguments)
49-
);
50-
}
51-
}
52-
53-
protected normalizeWorkspaceArg(raw: string): string {
54-
return path.resolve(raw).replace(/\/$/, '');
55-
}
56-
57-
protected async buildWorkspaceForMultipleArguments(
58-
workspaceArguments: string[]
59-
): Promise<string | undefined> {
60-
try {
61-
const dirs = await Promise.all(
62-
workspaceArguments.map(async (maybeDir) =>
63-
(await fs.stat(maybeDir).catch(() => undefined))?.isDirectory()
64-
)
65-
);
66-
const folders = workspaceArguments
67-
.filter((_, index) => dirs[index])
68-
.map((dir) => ({ path: this.normalizeWorkspaceArg(dir) }));
69-
if (folders.length < 2) {
70-
return folders[0]?.path;
71-
}
72-
const untitledWorkspaceUri = await this.getUntitledWorkspaceUri(
73-
new URI(await this.envVariablesServer.getConfigDirUri()),
74-
async (uri) => !(await fsExtra.pathExists(uri.path.fsPath()))
75-
);
76-
const untitledWorkspacePath = untitledWorkspaceUri.path.fsPath();
77-
78-
await fsExtra.ensureDir(path.dirname(untitledWorkspacePath));
79-
await fs.writeFile(
80-
untitledWorkspacePath,
81-
JSON.stringify({ folders }, undefined, 4)
82-
);
83-
return untitledWorkspacePath;
84-
} catch {
85-
return undefined;
86-
}
87-
}
88-
89-
async getUntitledWorkspaceUri(
90-
configDirUri: URI,
91-
isAcceptable: (candidate: URI) => MaybePromise<boolean>,
92-
warnOnHits?: () => unknown
93-
): Promise<URI> {
94-
const parentDir = configDirUri.resolve('workspaces');
95-
let uri;
96-
let attempts = 0;
97-
do {
98-
attempts++;
99-
uri = parentDir.resolve(
100-
`Untitled-${Math.round(Math.random() * 1000)}.${THEIA_EXT}`
101-
);
102-
if (attempts === 10) {
103-
warnOnHits?.();
104-
}
105-
if (attempts === 50) {
106-
throw new Error(
107-
'Workspace Service: too many attempts to find unused filename.'
108-
);
109-
}
110-
} while (!(await isAcceptable(uri)));
111-
return uri;
112-
}
113-
}
1147

1158
@injectable()
1169
export class DefaultWorkspaceServer extends TheiaDefaultWorkspaceServer {

0 commit comments

Comments
 (0)