@theia/plugin-ext 1.20.0 → 1.21.0-next.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/lib/common/connection.d.ts +47 -33
  2. package/lib/common/connection.d.ts.map +1 -1
  3. package/lib/common/connection.js +90 -28
  4. package/lib/common/connection.js.map +1 -1
  5. package/lib/common/plugin-api-rpc.d.ts +0 -2
  6. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  7. package/lib/common/plugin-api-rpc.js.map +1 -1
  8. package/lib/common/plugin-protocol.d.ts +1 -0
  9. package/lib/common/plugin-protocol.d.ts.map +1 -1
  10. package/lib/common/plugin-protocol.js.map +1 -1
  11. package/lib/hosted/browser/hosted-plugin.js +1 -1
  12. package/lib/hosted/browser/hosted-plugin.js.map +1 -1
  13. package/lib/hosted/node/scanners/scanner-theia.d.ts.map +1 -1
  14. package/lib/hosted/node/scanners/scanner-theia.js +4 -1
  15. package/lib/hosted/node/scanners/scanner-theia.js.map +1 -1
  16. package/lib/main/browser/debug/debug-main.d.ts +3 -3
  17. package/lib/main/browser/debug/debug-main.d.ts.map +1 -1
  18. package/lib/main/browser/debug/debug-main.js +1 -2
  19. package/lib/main/browser/debug/debug-main.js.map +1 -1
  20. package/lib/main/browser/debug/plugin-debug-session-factory.d.ts +4 -4
  21. package/lib/main/browser/debug/plugin-debug-session-factory.d.ts.map +1 -1
  22. package/lib/main/browser/debug/plugin-debug-session-factory.js +1 -1
  23. package/lib/main/browser/debug/plugin-debug-session-factory.js.map +1 -1
  24. package/lib/main/browser/file-system-main-impl.js +1 -1
  25. package/lib/main/browser/file-system-main-impl.js.map +1 -1
  26. package/lib/main/browser/main-context.js +2 -2
  27. package/lib/main/browser/main-context.js.map +1 -1
  28. package/lib/main/browser/view/plugin-view-registry.d.ts.map +1 -1
  29. package/lib/main/browser/view/plugin-view-registry.js +14 -3
  30. package/lib/main/browser/view/plugin-view-registry.js.map +1 -1
  31. package/lib/plugin/node/debug/debug.d.ts +4 -4
  32. package/lib/plugin/node/debug/debug.d.ts.map +1 -1
  33. package/lib/plugin/node/debug/debug.js +3 -4
  34. package/lib/plugin/node/debug/debug.js.map +1 -1
  35. package/lib/plugin/node/debug/plugin-debug-adapter-session.d.ts +7 -7
  36. package/lib/plugin/node/debug/plugin-debug-adapter-session.d.ts.map +1 -1
  37. package/lib/plugin/node/debug/plugin-debug-adapter-session.js +6 -6
  38. package/lib/plugin/node/debug/plugin-debug-adapter-session.js.map +1 -1
  39. package/lib/plugin/node/debug/plugin-debug-adapter-starter.d.ts +7 -5
  40. package/lib/plugin/node/debug/plugin-debug-adapter-starter.d.ts.map +1 -1
  41. package/lib/plugin/node/debug/plugin-debug-adapter-starter.js +6 -13
  42. package/lib/plugin/node/debug/plugin-debug-adapter-starter.js.map +1 -1
  43. package/lib/plugin/plugin-context.d.ts.map +1 -1
  44. package/lib/plugin/plugin-context.js +2 -2
  45. package/lib/plugin/plugin-context.js.map +1 -1
  46. package/package.json +23 -23
  47. package/src/common/connection.ts +98 -41
  48. package/src/common/plugin-api-rpc.ts +0 -2
  49. package/src/common/plugin-protocol.ts +1 -0
  50. package/src/hosted/browser/hosted-plugin.ts +1 -1
  51. package/src/hosted/node/scanners/scanner-theia.ts +4 -1
  52. package/src/main/browser/debug/debug-main.ts +3 -4
  53. package/src/main/browser/debug/plugin-debug-session-factory.ts +3 -3
  54. package/src/main/browser/file-system-main-impl.ts +1 -1
  55. package/src/main/browser/main-context.ts +3 -3
  56. package/src/main/browser/view/plugin-view-registry.ts +16 -3
  57. package/src/plugin/node/debug/debug.ts +7 -8
  58. package/src/plugin/node/debug/plugin-debug-adapter-session.ts +9 -9
  59. package/src/plugin/node/debug/plugin-debug-adapter-starter.ts +11 -18
  60. package/src/plugin/plugin-context.ts +4 -3
  61. package/lib/common/plugin-message-reader.d.ts +0 -46
  62. package/lib/common/plugin-message-reader.d.ts.map +0 -1
  63. package/lib/common/plugin-message-reader.js +0 -116
  64. package/lib/common/plugin-message-reader.js.map +0 -1
  65. package/lib/common/plugin-message-writer.d.ts +0 -38
  66. package/lib/common/plugin-message-writer.d.ts.map +0 -1
  67. package/lib/common/plugin-message-writer.js +0 -67
  68. package/lib/common/plugin-message-writer.js.map +0 -1
  69. package/lib/main/browser/connection-main.d.ts +0 -59
  70. package/lib/main/browser/connection-main.d.ts.map +0 -1
  71. package/lib/main/browser/connection-main.js +0 -98
  72. package/lib/main/browser/connection-main.js.map +0 -1
  73. package/lib/plugin/connection-ext.d.ts +0 -56
  74. package/lib/plugin/connection-ext.d.ts.map +0 -1
  75. package/lib/plugin/connection-ext.js +0 -88
  76. package/lib/plugin/connection-ext.js.map +0 -1
  77. package/src/common/plugin-message-reader.ts +0 -111
  78. package/src/common/plugin-message-writer.ts +0 -65
  79. package/src/main/browser/connection-main.ts +0 -107
  80. package/src/plugin/connection-ext.ts +0 -95
@@ -21,9 +21,8 @@ import { Breakpoint } from '../../../common/plugin-api-rpc-model';
21
21
  import { DebugConfigurationProviderTriggerKind, DebugExt, DebugMain, PLUGIN_RPC_CONTEXT as Ext, TerminalOptionsExt } from '../../../common/plugin-api-rpc';
22
22
  import { PluginPackageDebuggersContribution } from '../../../common/plugin-protocol';
23
23
  import { RPCProtocol } from '../../../common/rpc-protocol';
24
- import { PluginWebSocketChannel } from '../../../common/connection';
25
24
  import { CommandRegistryImpl } from '../../command-registry';
26
- import { ConnectionExtImpl } from '../../connection-ext';
25
+ import { ConnectionImpl } from '../../../common/connection';
27
26
  import {
28
27
  Disposable, Breakpoint as BreakpointExt, SourceBreakpoint, FunctionBreakpoint, Location, Range,
29
28
  DebugAdapterServer, DebugAdapterExecutable, DebugAdapterNamedPipeServer, DebugAdapterInlineImplementation
@@ -33,7 +32,7 @@ import { PluginDebugAdapterSession } from './plugin-debug-adapter-session';
33
32
  import { connectInlineDebugAdapter, connectPipeDebugAdapter, connectSocketDebugAdapter, startDebugAdapter } from './plugin-debug-adapter-starter';
34
33
  import { PluginDebugAdapterTracker } from './plugin-debug-adapter-tracker';
35
34
  import uuid = require('uuid');
36
- import { CommunicationProvider } from '@theia/debug/lib/node/debug-model';
35
+ import { DebugAdapter } from '@theia/debug/lib/node/debug-model';
37
36
 
38
37
  /* eslint-disable @typescript-eslint/no-explicit-any */
39
38
 
@@ -60,7 +59,7 @@ export class DebugExtImpl implements DebugExt {
60
59
  private trackerFactories: [string, theia.DebugAdapterTrackerFactory][] = [];
61
60
  private contributionPaths = new Map<string, string>();
62
61
 
63
- private connectionExt: ConnectionExtImpl;
62
+ private connectionExt: ConnectionImpl;
64
63
  private commandRegistryExt: CommandRegistryImpl;
65
64
 
66
65
  private proxy: DebugMain;
@@ -91,7 +90,7 @@ export class DebugExtImpl implements DebugExt {
91
90
  /**
92
91
  * Sets dependencies.
93
92
  */
94
- assistedInject(connectionExt: ConnectionExtImpl, commandRegistryExt: CommandRegistryImpl): void {
93
+ assistedInject(connectionExt: ConnectionImpl, commandRegistryExt: CommandRegistryImpl): void {
95
94
  this.connectionExt = connectionExt;
96
95
  this.commandRegistryExt = commandRegistryExt;
97
96
  }
@@ -301,13 +300,13 @@ export class DebugExtImpl implements DebugExt {
301
300
  };
302
301
 
303
302
  const tracker = await this.createDebugAdapterTracker(theiaSession);
304
- const communicationProvider = await this.createCommunicationProvider(theiaSession, debugConfiguration);
303
+ const communicationProvider = await this.createDebugAdapter(theiaSession, debugConfiguration);
305
304
 
306
305
  const debugAdapterSession = new PluginDebugAdapterSession(communicationProvider, tracker, theiaSession);
307
306
  this.sessions.set(sessionId, debugAdapterSession);
308
307
 
309
308
  const connection = await this.connectionExt!.ensureConnection(sessionId);
310
- debugAdapterSession.start(new PluginWebSocketChannel(connection));
309
+ debugAdapterSession.start(connection);
311
310
 
312
311
  return sessionId;
313
312
  }
@@ -406,7 +405,7 @@ export class DebugExtImpl implements DebugExt {
406
405
  return PluginDebugAdapterTracker.create(session, this.trackerFactories);
407
406
  }
408
407
 
409
- protected async createCommunicationProvider(session: theia.DebugSession, debugConfiguration: theia.DebugConfiguration): Promise<CommunicationProvider> {
408
+ protected async createDebugAdapter(session: theia.DebugSession, debugConfiguration: theia.DebugConfiguration): Promise<DebugAdapter> {
410
409
  const executable = await this.resolveDebugAdapterExecutable(debugConfiguration);
411
410
  const descriptorFactory = this.descriptorFactories.get(session.type);
412
411
  if (descriptorFactory) {
@@ -16,32 +16,32 @@
16
16
 
17
17
  import { DebugAdapterSessionImpl } from '@theia/debug/lib/node/debug-adapter-session';
18
18
  import * as theia from '@theia/plugin';
19
- import { IWebSocket } from '@theia/core/shared/vscode-ws-jsonrpc';
20
- import { CommunicationProvider, DebugAdapterSession } from '@theia/debug/lib/node/debug-model';
19
+ import { DebugAdapter } from '@theia/debug/lib/node/debug-model';
20
+ import { Channel } from '@theia/debug/lib/common/debug-service';
21
21
 
22
22
  /* eslint-disable @typescript-eslint/no-explicit-any */
23
23
 
24
24
  /**
25
25
  * Server debug adapter session.
26
26
  */
27
- export class PluginDebugAdapterSession extends DebugAdapterSessionImpl implements theia.DebugSession, DebugAdapterSession {
27
+ export class PluginDebugAdapterSession extends DebugAdapterSessionImpl {
28
28
  readonly type: string;
29
29
  readonly name: string;
30
30
  readonly configuration: theia.DebugConfiguration;
31
31
 
32
32
  constructor(
33
- readonly communicationProvider: CommunicationProvider,
33
+ readonly debugAdapter: DebugAdapter,
34
34
  protected readonly tracker: theia.DebugAdapterTracker,
35
35
  protected readonly theiaSession: theia.DebugSession) {
36
36
 
37
- super(theiaSession.id, communicationProvider);
37
+ super(theiaSession.id, debugAdapter);
38
38
 
39
39
  this.type = theiaSession.type;
40
40
  this.name = theiaSession.name;
41
41
  this.configuration = theiaSession.configuration;
42
42
  }
43
43
 
44
- async start(channel: IWebSocket): Promise<void> {
44
+ async start(channel: Channel): Promise<void> {
45
45
  if (this.tracker.onWillStartSession) {
46
46
  this.tracker.onWillStartSession();
47
47
  }
@@ -83,10 +83,10 @@ export class PluginDebugAdapterSession extends DebugAdapterSessionImpl implement
83
83
  super.write(message);
84
84
  }
85
85
 
86
- protected onDebugAdapterExit(exitCode: number, signal: string | undefined): void {
86
+ protected onDebugAdapterExit(): void {
87
87
  if (this.tracker.onExit) {
88
- this.tracker.onExit(exitCode, signal);
88
+ this.tracker.onExit(undefined, undefined);
89
89
  }
90
- super.onDebugAdapterExit(exitCode, signal);
90
+ super.onDebugAdapterExit();
91
91
  }
92
92
  }
@@ -16,17 +16,16 @@
16
16
 
17
17
  import * as net from 'net';
18
18
  import { ChildProcess, spawn, fork, ForkOptions } from 'child_process';
19
- import { CommunicationProvider } from '@theia/debug/lib/node/debug-model';
20
- import { StreamCommunicationProvider } from '@theia/debug/lib/node/stream-communication-provider';
21
- import { Disposable } from '@theia/core/lib/common/disposable';
19
+ import { DebugAdapter } from '@theia/debug/lib/node/debug-model';
22
20
  import { DebugAdapterExecutable, DebugAdapterInlineImplementation, DebugAdapterNamedPipeServer, DebugAdapterServer } from '../../types-impl';
23
- import { InlineCommunicationProvider } from '@theia/debug/lib/node/inline-communication-provider';
21
+ import { InlineDebugAdapter } from '@theia/debug/lib/node/inline-debug-adapter';
22
+ import { ProcessDebugAdapter, SocketDebugAdapter } from '@theia/debug/lib/node/stream-debug-adapter';
24
23
  const isElectron = require('is-electron');
25
24
 
26
25
  /**
27
26
  * Starts debug adapter process.
28
27
  */
29
- export function startDebugAdapter(executable: DebugAdapterExecutable): CommunicationProvider {
28
+ export function startDebugAdapter(executable: DebugAdapterExecutable): DebugAdapter {
30
29
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
30
  const options: any = { stdio: ['pipe', 'pipe', 2] };
32
31
 
@@ -66,28 +65,22 @@ export function startDebugAdapter(executable: DebugAdapterExecutable): Communica
66
65
  childProcess = spawn(command, args, options);
67
66
  }
68
67
 
69
- const provider = new StreamCommunicationProvider(childProcess.stdout!, childProcess.stdin!);
70
- provider.push(Disposable.create(() => childProcess.kill()));
71
- return provider;
68
+ return new ProcessDebugAdapter(childProcess);
72
69
  }
73
70
 
74
71
  /**
75
72
  * Connects to a remote debug server.
76
73
  */
77
- export function connectSocketDebugAdapter(server: DebugAdapterServer): CommunicationProvider {
74
+ export function connectSocketDebugAdapter(server: DebugAdapterServer): SocketDebugAdapter {
78
75
  const socket = net.createConnection(server.port, server.host);
79
- const provider = new StreamCommunicationProvider(socket, socket);
80
- provider.push(Disposable.create(() => socket.end()));
81
- return provider;
76
+ return new SocketDebugAdapter(socket);
82
77
  }
83
78
 
84
- export function connectPipeDebugAdapter(adapter: DebugAdapterNamedPipeServer): CommunicationProvider {
79
+ export function connectPipeDebugAdapter(adapter: DebugAdapterNamedPipeServer): SocketDebugAdapter {
85
80
  const socket = net.createConnection(adapter.path);
86
- const provider = new StreamCommunicationProvider(socket, socket);
87
- provider.push(Disposable.create(() => socket.end()));
88
- return provider;
81
+ return new SocketDebugAdapter(socket);
89
82
  }
90
83
 
91
- export function connectInlineDebugAdapter(adapter: DebugAdapterInlineImplementation): CommunicationProvider {
92
- return new InlineCommunicationProvider(adapter.implementation);
84
+ export function connectInlineDebugAdapter(adapter: DebugAdapterInlineImplementation): InlineDebugAdapter {
85
+ return new InlineDebugAdapter(adapter.implementation);
93
86
  }
@@ -28,7 +28,8 @@ import {
28
28
  PluginManager,
29
29
  PluginAPIFactory,
30
30
  MainMessageType,
31
- DebugConfigurationProviderTriggerKind
31
+ DebugConfigurationProviderTriggerKind,
32
+ PLUGIN_RPC_CONTEXT
32
33
  } from '../common/plugin-api-rpc';
33
34
  import { RPCProtocol } from '../common/rpc-protocol';
34
35
  import { MessageRegistryExt } from './message-registry';
@@ -156,7 +157,7 @@ import { NotificationExtImpl } from './notification';
156
157
  import { score } from '@theia/callhierarchy/lib/common/language-selector';
157
158
  import { MarkdownString } from './markdown-string';
158
159
  import { TreeViewsExtImpl } from './tree/tree-views';
159
- import { ConnectionExtImpl } from './connection-ext';
160
+ import { ConnectionImpl } from '../common/connection';
160
161
  import { TasksExtImpl } from './tasks/tasks';
161
162
  import { DebugExtImpl } from './node/debug/debug';
162
163
  import { FileSystemExtImpl } from './file-system-ext-impl';
@@ -200,7 +201,7 @@ export function createAPIFactory(
200
201
  const languagesExt = rpc.set(MAIN_RPC_CONTEXT.LANGUAGES_EXT, new LanguagesExtImpl(rpc, documents, commandRegistry));
201
202
  const treeViewsExt = rpc.set(MAIN_RPC_CONTEXT.TREE_VIEWS_EXT, new TreeViewsExtImpl(rpc, commandRegistry));
202
203
  const tasksExt = rpc.set(MAIN_RPC_CONTEXT.TASKS_EXT, new TasksExtImpl(rpc, terminalExt));
203
- const connectionExt = rpc.set(MAIN_RPC_CONTEXT.CONNECTION_EXT, new ConnectionExtImpl(rpc));
204
+ const connectionExt = rpc.set(MAIN_RPC_CONTEXT.CONNECTION_EXT, new ConnectionImpl(rpc.getProxy(PLUGIN_RPC_CONTEXT.CONNECTION_MAIN)));
204
205
  const fileSystemExt = rpc.set(MAIN_RPC_CONTEXT.FILE_SYSTEM_EXT, new FileSystemExtImpl(rpc, languagesExt));
205
206
  const extHostFileSystemEvent = rpc.set(MAIN_RPC_CONTEXT.ExtHostFileSystemEventService, new ExtHostFileSystemEventService(rpc, editorsAndDocumentsExt));
206
207
  const scmExt = rpc.set(MAIN_RPC_CONTEXT.SCM_EXT, new ScmExtImpl(rpc, commandRegistry));
@@ -1,46 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2018 Red Hat, Inc. and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import { DataCallback, Emitter, Event, PartialMessageInfo } from '@theia/core/shared/vscode-ws-jsonrpc';
17
- export declare abstract class AbstractMessageReader {
18
- protected errorEmitter: Emitter<Error>;
19
- protected closeEmitter: Emitter<void>;
20
- protected partialMessageEmitter: Emitter<PartialMessageInfo>;
21
- dispose(): void;
22
- get onError(): Event<Error>;
23
- fireError(error: Error): void;
24
- get onClose(): Event<void>;
25
- fireClose(): void;
26
- get onPartialMessage(): Event<PartialMessageInfo>;
27
- firePartialMessage(info: PartialMessageInfo): void;
28
- asError(error: any): Error;
29
- }
30
- /**
31
- * Support for reading string message through RPC protocol.
32
- */
33
- export declare class PluginMessageReader extends AbstractMessageReader {
34
- protected state: 'initial' | 'listening' | 'closed';
35
- protected callback: DataCallback | undefined;
36
- protected readonly events: {
37
- message?: any;
38
- error?: any;
39
- }[];
40
- constructor();
41
- listen(callback: DataCallback): void;
42
- readMessage(message: string): void;
43
- fireError(error: any): void;
44
- fireClose(): void;
45
- }
46
- //# sourceMappingURL=plugin-message-reader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin-message-reader.d.ts","sourceRoot":"","sources":["../../src/common/plugin-message-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAExG,8BAAsB,qBAAqB;IACvC,SAAS,CAAC,YAAY,iBAAwB;IAC9C,SAAS,CAAC,YAAY,gBAAuB;IAC7C,SAAS,CAAC,qBAAqB,8BAAqC;IACpE,OAAO,IAAI,IAAI;IAIf,IAAI,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAE1B;IACD,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAG7B,IAAI,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,CAEzB;IACD,SAAS,IAAI,IAAI;IAGjB,IAAI,gBAAgB,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAEhD;IACD,kBAAkB,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI;IAIlD,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK;CAO7B;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,qBAAqB;IAC1D,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAa;IAChE,SAAS,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IAE7C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE;QAAE,OAAO,CAAC,EAAE,GAAG,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,CAAM;;IAMjE,MAAM,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAiBpC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAUlC,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAQ3B,SAAS,IAAI,IAAI;CAQpB"}
@@ -1,116 +0,0 @@
1
- "use strict";
2
- /********************************************************************************
3
- * Copyright (C) 2018 Red Hat, Inc. and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.PluginMessageReader = exports.AbstractMessageReader = void 0;
19
- const vscode_ws_jsonrpc_1 = require("@theia/core/shared/vscode-ws-jsonrpc");
20
- class AbstractMessageReader {
21
- constructor() {
22
- this.errorEmitter = new vscode_ws_jsonrpc_1.Emitter();
23
- this.closeEmitter = new vscode_ws_jsonrpc_1.Emitter();
24
- this.partialMessageEmitter = new vscode_ws_jsonrpc_1.Emitter();
25
- }
26
- dispose() {
27
- this.errorEmitter.dispose();
28
- this.closeEmitter.dispose();
29
- }
30
- get onError() {
31
- return this.errorEmitter.event;
32
- }
33
- fireError(error) {
34
- this.errorEmitter.fire(this.asError(error));
35
- }
36
- get onClose() {
37
- return this.closeEmitter.event;
38
- }
39
- fireClose() {
40
- this.closeEmitter.fire(undefined);
41
- }
42
- get onPartialMessage() {
43
- return this.partialMessageEmitter.event;
44
- }
45
- firePartialMessage(info) {
46
- this.partialMessageEmitter.fire(info);
47
- }
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- asError(error) {
50
- if (error instanceof Error) {
51
- return error;
52
- }
53
- else {
54
- return new Error(`Reader received error. Reason: ${typeof error.message === 'string' ? error.message : 'unknown'}`);
55
- }
56
- }
57
- }
58
- exports.AbstractMessageReader = AbstractMessageReader;
59
- /**
60
- * Support for reading string message through RPC protocol.
61
- */
62
- class PluginMessageReader extends AbstractMessageReader {
63
- constructor() {
64
- super();
65
- this.state = 'initial';
66
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- this.events = [];
68
- }
69
- listen(callback) {
70
- if (this.state === 'initial') {
71
- this.state = 'listening';
72
- this.callback = callback;
73
- while (this.events.length !== 0) {
74
- const event = this.events.pop();
75
- if (event.message) {
76
- this.readMessage(event.message);
77
- }
78
- else if (event.error) {
79
- this.fireError(event.error);
80
- }
81
- else {
82
- this.fireClose();
83
- }
84
- }
85
- }
86
- }
87
- readMessage(message) {
88
- if (this.state === 'initial') {
89
- this.events.splice(0, 0, { message });
90
- }
91
- else if (this.state === 'listening') {
92
- const data = JSON.parse(message);
93
- this.callback(data);
94
- }
95
- }
96
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
- fireError(error) {
98
- if (this.state === 'initial') {
99
- this.events.splice(0, 0, { error });
100
- }
101
- else if (this.state === 'listening') {
102
- super.fireError(error);
103
- }
104
- }
105
- fireClose() {
106
- if (this.state === 'initial') {
107
- this.events.splice(0, 0, {});
108
- }
109
- else if (this.state === 'listening') {
110
- super.fireClose();
111
- }
112
- this.state = 'closed';
113
- }
114
- }
115
- exports.PluginMessageReader = PluginMessageReader;
116
- //# sourceMappingURL=plugin-message-reader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin-message-reader.js","sourceRoot":"","sources":["../../src/common/plugin-message-reader.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,4EAAwG;AAExG,MAAsB,qBAAqB;IAA3C;QACc,iBAAY,GAAG,IAAI,2BAAO,EAAS,CAAC;QACpC,iBAAY,GAAG,IAAI,2BAAO,EAAQ,CAAC;QACnC,0BAAqB,GAAG,IAAI,2BAAO,EAAsB,CAAC;IA+BxE,CAAC;IA9BG,OAAO;QACH,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IACD,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACnC,CAAC;IACD,SAAS,CAAC,KAAY;QAClB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACnC,CAAC;IACD,SAAS;QACL,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,gBAAgB;QAChB,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC;IAC5C,CAAC;IACD,kBAAkB,CAAC,IAAwB;QACvC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IACD,8DAA8D;IAC9D,OAAO,CAAC,KAAU;QACd,IAAI,KAAK,YAAY,KAAK,EAAE;YACxB,OAAO,KAAK,CAAC;SAChB;aAAM;YACH,OAAO,IAAI,KAAK,CAAC,kCAAkC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;SACvH;IACL,CAAC;CACJ;AAlCD,sDAkCC;AAED;;GAEG;AACH,MAAa,mBAAoB,SAAQ,qBAAqB;IAM1D;QACI,KAAK,EAAE,CAAC;QANF,UAAK,GAAuC,SAAS,CAAC;QAEhE,8DAA8D;QAC3C,WAAM,GAAqC,EAAE,CAAC;IAIjE,CAAC;IAED,MAAM,CAAC,QAAsB;QACzB,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC1B,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC;YACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACzB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAG,CAAC;gBACjC,IAAI,KAAK,CAAC,OAAO,EAAE;oBACf,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;iBACnC;qBAAM,IAAI,KAAK,CAAC,KAAK,EAAE;oBACpB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBAC/B;qBAAM;oBACH,IAAI,CAAC,SAAS,EAAE,CAAC;iBACpB;aACJ;SACJ;IACL,CAAC;IAED,WAAW,CAAC,OAAe;QACvB,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;SACzC;aAAM,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,EAAE;YACnC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACjC,IAAI,CAAC,QAAS,CAAC,IAAI,CAAC,CAAC;SACxB;IACL,CAAC;IAED,8DAA8D;IAC9D,SAAS,CAAC,KAAU;QAChB,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;SACvC;aAAM,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,EAAE;YACnC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SAC1B;IACL,CAAC;IAED,SAAS;QACL,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;SAChC;aAAM,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,EAAE;YACnC,KAAK,CAAC,SAAS,EAAE,CAAC;SACrB;QACD,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;IAC1B,CAAC;CACJ;AArDD,kDAqDC"}
@@ -1,38 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2018 Red Hat, Inc. and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import { Message, MessageWriter, Emitter, Event } from '@theia/core/shared/vscode-ws-jsonrpc';
17
- import { ConnectionMain, ConnectionExt } from './plugin-api-rpc';
18
- export declare abstract class AbstractMessageWriter {
19
- protected errorEmitter: Emitter<[Error, Message | undefined, number | undefined]>;
20
- protected closeEmitter: Emitter<void>;
21
- dispose(): void;
22
- get onError(): Event<[Error, Message | undefined, number | undefined]>;
23
- fireError(error: Error, message: Message | undefined, count: number | undefined): void;
24
- get onClose(): Event<void>;
25
- fireClose(): void;
26
- asError(error: any): Error;
27
- }
28
- /**
29
- * Support for writing string message through RPC protocol.
30
- */
31
- export declare class PluginMessageWriter extends AbstractMessageWriter implements MessageWriter {
32
- protected readonly id: string;
33
- protected readonly proxy: ConnectionMain | ConnectionExt;
34
- constructor(id: string, proxy: ConnectionMain | ConnectionExt);
35
- write(message: string): void;
36
- write(message: Message): void;
37
- }
38
- //# sourceMappingURL=plugin-message-writer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin-message-writer.d.ts","sourceRoot":"","sources":["../../src/common/plugin-message-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjE,8BAAsB,qBAAqB;IACvC,SAAS,CAAC,YAAY,4DAAmE;IACzF,SAAS,CAAC,YAAY,gBAAuB;IAC7C,OAAO,IAAI,IAAI;IAIf,IAAI,OAAO,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAErE;IACD,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAGtF,IAAI,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,CAEzB;IACD,SAAS,IAAI,IAAI;IAIjB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK;CAO7B;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,qBAAsB,YAAW,aAAa;IAE/E,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM;IAC7B,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,aAAa;gBADrC,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,cAAc,GAAG,aAAa;IAI5D,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAC5B,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;CAKhC"}
@@ -1,67 +0,0 @@
1
- "use strict";
2
- /********************************************************************************
3
- * Copyright (C) 2018 Red Hat, Inc. and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.PluginMessageWriter = exports.AbstractMessageWriter = void 0;
19
- const vscode_ws_jsonrpc_1 = require("@theia/core/shared/vscode-ws-jsonrpc");
20
- class AbstractMessageWriter {
21
- constructor() {
22
- this.errorEmitter = new vscode_ws_jsonrpc_1.Emitter();
23
- this.closeEmitter = new vscode_ws_jsonrpc_1.Emitter();
24
- }
25
- dispose() {
26
- this.errorEmitter.dispose();
27
- this.closeEmitter.dispose();
28
- }
29
- get onError() {
30
- return this.errorEmitter.event;
31
- }
32
- fireError(error, message, count) {
33
- this.errorEmitter.fire([this.asError(error), message, count]);
34
- }
35
- get onClose() {
36
- return this.closeEmitter.event;
37
- }
38
- fireClose() {
39
- this.closeEmitter.fire(undefined);
40
- }
41
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
- asError(error) {
43
- if (error instanceof Error) {
44
- return error;
45
- }
46
- else {
47
- return new Error(`Writer received error. Reason: ${typeof error.message === 'string' ? error.message : 'unknown'}`);
48
- }
49
- }
50
- }
51
- exports.AbstractMessageWriter = AbstractMessageWriter;
52
- /**
53
- * Support for writing string message through RPC protocol.
54
- */
55
- class PluginMessageWriter extends AbstractMessageWriter {
56
- constructor(id, proxy) {
57
- super();
58
- this.id = id;
59
- this.proxy = proxy;
60
- }
61
- write(arg) {
62
- const content = JSON.stringify(arg);
63
- this.proxy.$sendMessage(this.id, content);
64
- }
65
- }
66
- exports.PluginMessageWriter = PluginMessageWriter;
67
- //# sourceMappingURL=plugin-message-writer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin-message-writer.js","sourceRoot":"","sources":["../../src/common/plugin-message-writer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,4EAA8F;AAG9F,MAAsB,qBAAqB;IAA3C;QACc,iBAAY,GAAG,IAAI,2BAAO,EAAoD,CAAC;QAC/E,iBAAY,GAAG,IAAI,2BAAO,EAAQ,CAAC;IAyBjD,CAAC;IAxBG,OAAO;QACH,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IACD,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACnC,CAAC;IACD,SAAS,CAAC,KAAY,EAAE,OAA4B,EAAE,KAAyB;QAC3E,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACnC,CAAC;IACD,SAAS;QACL,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IACD,8DAA8D;IAC9D,OAAO,CAAC,KAAU;QACd,IAAI,KAAK,YAAY,KAAK,EAAE;YACxB,OAAO,KAAK,CAAC;SAChB;aAAM;YACH,OAAO,IAAI,KAAK,CAAC,kCAAkC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;SACvH;IACL,CAAC;CACJ;AA3BD,sDA2BC;AAED;;GAEG;AACH,MAAa,mBAAoB,SAAQ,qBAAqB;IAC1D,YACuB,EAAU,EACV,KAAqC;QACxD,KAAK,EAAE,CAAC;QAFW,OAAE,GAAF,EAAE,CAAQ;QACV,UAAK,GAAL,KAAK,CAAgC;IAE5D,CAAC;IAID,KAAK,CAAC,GAAqB;QACvB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACJ;AAbD,kDAaC"}
@@ -1,59 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (C) 2018 Red Hat, Inc. and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import { Disposable } from '@theia/core/lib/common/disposable';
17
- import { ConnectionMain } from '../../common/plugin-api-rpc';
18
- import { RPCProtocol } from '../../common/rpc-protocol';
19
- import { PluginConnection } from '../../common/connection';
20
- /**
21
- * Implementation of connection system of the plugin API.
22
- * Creates holds the connections to the plugins. Allows to send a message to the plugin by getting already created connection via id.
23
- */
24
- export declare class ConnectionMainImpl implements ConnectionMain, Disposable {
25
- private readonly proxy;
26
- private readonly connections;
27
- private readonly toDispose;
28
- constructor(rpc: RPCProtocol);
29
- dispose(): void;
30
- /**
31
- * Gets the connection between plugin by id and sends string message to it.
32
- *
33
- * @param id connection's id
34
- * @param message incoming message
35
- */
36
- $sendMessage(id: string, message: string): Promise<void>;
37
- /**
38
- * Instantiates a new connection by the given id.
39
- * @param id the connection id
40
- */
41
- $createConnection(id: string): Promise<void>;
42
- /**
43
- * Deletes a connection.
44
- * @param id the connection id
45
- */
46
- $deleteConnection(id: string): Promise<void>;
47
- /**
48
- * Returns existed connection or creates a new one.
49
- * @param id the connection id
50
- */
51
- ensureConnection(id: string): Promise<PluginConnection>;
52
- /**
53
- * Returns existed connection or creates a new one.
54
- * @param id the connection id
55
- */
56
- doEnsureConnection(id: string): Promise<PluginConnection>;
57
- protected doCreateConnection(id: string): Promise<PluginConnection>;
58
- }
59
- //# sourceMappingURL=connection-main.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection-main.d.ts","sourceRoot":"","sources":["../../../src/main/browser/connection-main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,OAAO,EAAE,UAAU,EAAwB,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAoB,cAAc,EAAiB,MAAM,6BAA6B,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAI3D;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,cAAc,EAAE,UAAU;IAEjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuC;IACnE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;gBAC5C,GAAG,EAAE,WAAW;IAI5B,OAAO,IAAI,IAAI;IAIf;;;;;OAKG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9D;;;OAGG;IACG,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD;;;OAGG;IACG,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD;;;OAGG;IACG,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAM7D;;;OAGG;IACG,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;cAM/C,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAgB5E"}
@@ -1,98 +0,0 @@
1
- "use strict";
2
- /********************************************************************************
3
- * Copyright (C) 2018 Red Hat, Inc. and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * This Source Code may also be made available under the following Secondary
10
- * Licenses when the conditions for such availability set forth in the Eclipse
11
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- * with the GNU Classpath Exception which is available at
13
- * https://www.gnu.org/software/classpath/license.html.
14
- *
15
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- ********************************************************************************/
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ConnectionMainImpl = void 0;
19
- const disposable_1 = require("@theia/core/lib/common/disposable");
20
- const plugin_api_rpc_1 = require("../../common/plugin-api-rpc");
21
- const connection_1 = require("../../common/connection");
22
- const plugin_message_reader_1 = require("../../common/plugin-message-reader");
23
- const plugin_message_writer_1 = require("../../common/plugin-message-writer");
24
- /**
25
- * Implementation of connection system of the plugin API.
26
- * Creates holds the connections to the plugins. Allows to send a message to the plugin by getting already created connection via id.
27
- */
28
- class ConnectionMainImpl {
29
- constructor(rpc) {
30
- this.connections = new Map();
31
- this.toDispose = new disposable_1.DisposableCollection();
32
- this.proxy = rpc.getProxy(plugin_api_rpc_1.MAIN_RPC_CONTEXT.CONNECTION_EXT);
33
- }
34
- dispose() {
35
- this.toDispose.dispose();
36
- }
37
- /**
38
- * Gets the connection between plugin by id and sends string message to it.
39
- *
40
- * @param id connection's id
41
- * @param message incoming message
42
- */
43
- async $sendMessage(id, message) {
44
- if (this.connections.has(id)) {
45
- this.connections.get(id).reader.readMessage(message);
46
- }
47
- else {
48
- console.warn('It is not possible to read message. Connection missed.');
49
- }
50
- }
51
- /**
52
- * Instantiates a new connection by the given id.
53
- * @param id the connection id
54
- */
55
- async $createConnection(id) {
56
- await this.doEnsureConnection(id);
57
- }
58
- /**
59
- * Deletes a connection.
60
- * @param id the connection id
61
- */
62
- async $deleteConnection(id) {
63
- this.connections.delete(id);
64
- }
65
- /**
66
- * Returns existed connection or creates a new one.
67
- * @param id the connection id
68
- */
69
- async ensureConnection(id) {
70
- const connection = await this.doEnsureConnection(id);
71
- await this.proxy.$createConnection(id);
72
- return connection;
73
- }
74
- /**
75
- * Returns existed connection or creates a new one.
76
- * @param id the connection id
77
- */
78
- async doEnsureConnection(id) {
79
- const connection = this.connections.get(id) || await this.doCreateConnection(id);
80
- this.connections.set(id, connection);
81
- return connection;
82
- }
83
- async doCreateConnection(id) {
84
- const reader = new plugin_message_reader_1.PluginMessageReader();
85
- const writer = new plugin_message_writer_1.PluginMessageWriter(id, this.proxy);
86
- const connection = new connection_1.PluginConnection(reader, writer, () => {
87
- this.connections.delete(id);
88
- if (!toClose.disposed) {
89
- this.proxy.$deleteConnection(id);
90
- }
91
- });
92
- const toClose = new disposable_1.DisposableCollection(disposable_1.Disposable.create(() => reader.fireClose()));
93
- this.toDispose.push(toClose);
94
- return connection;
95
- }
96
- }
97
- exports.ConnectionMainImpl = ConnectionMainImpl;
98
- //# sourceMappingURL=connection-main.js.map