-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #990 from eclipsesource/976-JSON-RPC
Refactor server communication to JSON-RPC
- Loading branch information
Showing
26 changed files
with
708 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,47 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import { TspClient } from 'tsp-typescript-client'; | ||
import { ITspClient } from 'tsp-typescript-client'; | ||
import { HttpTspClient } from 'tsp-typescript-client/lib/protocol/http-tsp-client'; | ||
|
||
/** | ||
* Hack! | ||
* The `LazyTspClient` replaces _every_ method with an asynchronous one. | ||
* Only keep methods, discard properties. | ||
*/ | ||
export type LazyTspClient = { | ||
[K in keyof TspClient]: TspClient[K] extends (...args: infer A) => infer R | Promise<infer R> | ||
[K in keyof ITspClient]: ITspClient[K] extends (...args: infer A) => infer R | Promise<infer R> | ||
? (...args: A) => Promise<R> | ||
: never; // Discard property. | ||
}; | ||
|
||
export type LazyTspClientFactory = typeof LazyTspClientFactory; | ||
export function LazyTspClientFactory(url: Promise<string>): TspClient { | ||
// All methods from the `TspClient` are asynchronous. The `LazyTspClient` | ||
export function LazyTspClientFactory(provider: () => Promise<string>): ITspClient { | ||
// All methods from the `HttpTspClient` are asynchronous. The `LazyTspClient` | ||
// will just delay each call to its methods by first awaiting for the | ||
// asynchronous `baseUrl` resolution to then get a valid `TspClient`. | ||
const tspClientPromise = url.then(baseUrl => new TspClient(baseUrl)); | ||
// asynchronous `baseUrl` resolution to then get a valid `HttpTspClient`. | ||
|
||
// Save the current HttpTspClient and the URL used for it. | ||
let tspClient: HttpTspClient; | ||
let lastUrl: string; | ||
// eslint-disable-next-line no-null/no-null | ||
return new Proxy(Object.create(null), { | ||
get(target, property, _receiver) { | ||
let method = target[property]; | ||
if (!method) { | ||
target[property] = method = async (...args: any[]) => { | ||
const tspClient = (await tspClientPromise) as any; | ||
return tspClient[property](...args); | ||
tspClient = await provider().then(baseUrl => { | ||
// If the url has not been updated keep the same client. | ||
if (lastUrl === baseUrl) { | ||
return tspClient; | ||
} | ||
// If the url has changed save it and create a new client. | ||
lastUrl = baseUrl; | ||
return new HttpTspClient(baseUrl); | ||
}); | ||
return (tspClient as any)[property](...args); | ||
}; | ||
} | ||
return method; | ||
} | ||
}) as LazyTspClient as TspClient; | ||
}) as LazyTspClient as ITspClient; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { TspClient } from 'tsp-typescript-client/lib/protocol/tsp-client'; | ||
import { ITspClient } from 'tsp-typescript-client/lib/protocol/tsp-client'; | ||
import { ExperimentManager } from './experiment-manager'; | ||
import { TraceManager } from './trace-manager'; | ||
|
||
export interface ITspClientProvider { | ||
getTspClient(): TspClient; | ||
getTspClient(): ITspClient; | ||
getTraceManager(): TraceManager; | ||
getExperimentManager(): ExperimentManager; | ||
/** | ||
* Add a listener for trace server url changes | ||
* @param listener The listener function to be called when the url is | ||
* changed | ||
*/ | ||
addTspClientChangeListener(listener: (tspClient: TspClient) => void): void; | ||
addTspClientChangeListener(listener: (tspClient: ITspClient) => void): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
packages/react-components/src/components/data-providers/style-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/react-components/src/components/trace-overview-selection-dialog-component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
theia-extensions/viewer-prototype/src/browser/preferences-frontend-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { FrontendApplicationContribution } from '@theia/core/lib/browser'; | ||
import { inject, injectable } from 'inversify'; | ||
import { PortPreferenceProxy } from '../common/trace-server-url-provider'; | ||
import { TracePreferences, TRACE_PORT } from './trace-server-preference'; | ||
|
||
@injectable() | ||
export class PreferencesFrontendContribution implements FrontendApplicationContribution { | ||
constructor( | ||
@inject(TracePreferences) protected tracePreferences: TracePreferences, | ||
@inject(PortPreferenceProxy) protected portPreferenceProxy: PortPreferenceProxy | ||
) {} | ||
|
||
async initialize(): Promise<void> { | ||
this.tracePreferences.ready.then(() => { | ||
this.portPreferenceProxy.onPortPreferenceChanged(this.tracePreferences[TRACE_PORT]); | ||
this.tracePreferences.onPreferenceChanged(async event => { | ||
if (event.preferenceName === TRACE_PORT) { | ||
const newValue = typeof event.newValue === 'string' ? parseInt(event.newValue) : event.newValue; | ||
const oldValue = typeof event.oldValue === 'string' ? parseInt(event.oldValue) : event.oldValue; | ||
this.portPreferenceProxy.onPortPreferenceChanged(newValue, oldValue, true); | ||
} | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.