Skip to content

Commit

Permalink
Add Preference settings for trace configuration
Browse files Browse the repository at this point in the history
Set the default values for the trace server preferences
Read the trace server preference values and spawn the server from the path specified in the
preferences

fixes #191
fixes #184

Signed-off-by: Ankush Tyagi <[email protected]>
  • Loading branch information
ankusht-work authored and bhufmann committed Jan 12, 2021
1 parent 9becf9d commit f87b732
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 69 deletions.
5 changes: 4 additions & 1 deletion browser-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"config": {
"applicationName": "Theia-Trace Example Application",
"preferences": {
"editor.autoSave": "on"
"editor.autoSave": "on",
"trace-viewer.path" : "../trace-compass-server/tracecompass-server",
"trace-viewer.port" : 8080

}
}
}
Expand Down
4 changes: 3 additions & 1 deletion electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"config": {
"applicationName": "Theia-Trace Example Application",
"preferences": {
"editor.autoSave": "on"
"editor.autoSave": "on",
"trace-viewer.path" : "../trace-compass-server/tracecompass-server",
"trace-viewer.port" : 8080
}
}
}
Expand Down
96 changes: 48 additions & 48 deletions viewer-prototype/package.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
{
"name": "theia-trace-viewer",
"private": "true",
"version": "0.0.0",
"description": "Trace Compass trace viewer Theia Extension",
"keywords": [
"theia-extension"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/theia-ide/theia-trace-extension"
},
"files": [
"lib",
"src"
],
"dependencies": {
"@trace-viewer/base": "0.0.0",
"@trace-viewer/react-components": "0.0.0",
"@theia/core": "latest",
"@theia/editor": "latest",
"@theia/filesystem": "latest"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^3.4.0",
"@typescript-eslint/parser": "^3.4.0",
"eslint": "^7.3.0",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-react": "^7.20.0",
"rimraf": "latest",
"typescript": "latest"
},
"scripts": {
"build": "tsc",
"clean": "rimraf lib",
"lint": "eslint .",
"prepare": "yarn run clean && yarn run build",
"test": "echo 'test'",
"watch": "tsc -w"
},
"theiaExtensions": [
{
"frontend": "lib/browser/trace-viewer/trace-viewer-frontend-module"
}
]
}
"name": "theia-trace-viewer",
"private": "true",
"version": "0.0.0",
"description": "Trace Compass trace viewer Theia Extension",
"keywords": [
"theia-extension"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/theia-ide/theia-trace-extension"
},
"files": [
"lib",
"src"
],
"dependencies": {
"@trace-viewer/base": "0.0.0",
"@trace-viewer/react-components": "0.0.0",
"@theia/core": "latest",
"@theia/editor": "latest",
"@theia/filesystem": "latest"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^3.4.0",
"@typescript-eslint/parser": "^3.4.0",
"eslint": "^7.3.0",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-react": "^7.20.0",
"rimraf": "latest",
"typescript": "latest"
},
"scripts": {
"build": "tsc",
"clean": "rimraf lib",
"lint": "eslint .",
"prepare": "yarn run clean && yarn run build",
"test": "echo 'test'",
"watch": "tsc -w"
},
"theiaExtensions": [
{
"frontend": "lib/browser/trace-viewer/trace-viewer-frontend-module",
"backend": "lib/node/trace-server-backend-module"
}
]
}
15 changes: 15 additions & 0 deletions viewer-prototype/src/browser/trace-server-bindings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { interfaces } from 'inversify';
import { PreferenceService, createPreferenceProxy, PreferenceContribution } from '@theia/core/lib/browser';
import { TracePreferences, ServerSchema } from './trace-server-preference';

export function bindTraceServerPreferences(bind: interfaces.Bind): void {
bind(TracePreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createPreferenceProxy(preferences, ServerSchema);
}).inSingletonScope();

bind(PreferenceContribution).toConstantValue({
schema: ServerSchema,
});

}
30 changes: 30 additions & 0 deletions viewer-prototype/src/browser/trace-server-preference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { PreferenceSchema, PreferenceProxy, PreferenceScope } from '@theia/core/lib/browser';

export const TRACE_PATH = 'trace-viewer.path';
export const TRACE_PORT = 'trace-viewer.port';

export const ServerSchema: PreferenceSchema = {
type: 'object',
properties: {
[TRACE_PATH]: {
'type': 'string',
'default': '',
'description': 'The path to trace-server executable, e.g.: /usr/bin/tracecompass-server',
},
[TRACE_PORT]: {
'type': 'number',
'default': '',
'description': 'Specify the port on which you want to execute the server.',
}

},
scope: PreferenceScope.Folder,
};

interface TracePreferenceContribution {
[TRACE_PATH]: string;
[TRACE_PORT]: number;
}

export const TracePreferences = Symbol('TracePreferences');
export type TracePreferences = PreferenceProxy<TracePreferenceContribution>;
54 changes: 51 additions & 3 deletions viewer-prototype/src/browser/trace-server-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { Disposable, DisposableCollection } from '@theia/core/lib//common';
import { ConnectionStatusService, ConnectionStatus, AbstractConnectionStatusService } from '@theia/core/lib/browser/connection-status-service';
import { TspClient } from 'tsp-typescript-client/lib/protocol/tsp-client';
import { TspClientProvider } from './tsp-client-provider';
import { TraceServerConfigService } from '../common/trace-server-config';
import { PreferenceService } from '@theia/core/lib/browser';
import { TRACE_PATH, TRACE_PORT } from './trace-server-preference';

@injectable()
export class TraceServerConnectionStatusService extends AbstractConnectionStatusService {
Expand Down Expand Up @@ -52,6 +55,29 @@ export class TraceServerConnectionStatusService extends AbstractConnectionStatus
@injectable()
export class TraceServerConnectionStatusContribution extends DefaultFrontendApplicationContribution {

@inject(PreferenceService) protected readonly preferenceService: PreferenceService;

private path: string | undefined;
private port: number | undefined;

@postConstruct()
async init(): Promise<void> {

this.path = this.preferenceService.get(TRACE_PATH);
this.port = this.preferenceService.get(TRACE_PORT);

this.preferenceService.onPreferenceChanged(event => {
if (event.preferenceName === TRACE_PORT) {
this.port = event.newValue;
}
if (event.preferenceName === TRACE_PATH) {
this.path = event.newValue;
}
});
}

@inject(TraceServerConfigService) protected readonly traceServerConfigService: TraceServerConfigService;

protected readonly toDisposeOnOnline = new DisposableCollection();

constructor(
Expand All @@ -61,6 +87,9 @@ export class TraceServerConnectionStatusContribution extends DefaultFrontendAppl
) {
super();
this.connectionStatusService.onStatusChange(state => this.onStateChange(state));
if (this.connectionStatusService.currentStatus === ConnectionStatus.ONLINE) {
this.handleOnline();
}
}

protected onStateChange(state: ConnectionStatus): void {
Expand All @@ -80,15 +109,34 @@ export class TraceServerConnectionStatusContribution extends DefaultFrontendAppl

protected handleOnline(): void {
this.toDisposeOnOnline.dispose();
this.statusBar.setElement(this.statusbarId, {
alignment: StatusBarAlignment.LEFT,
text: '$(fas fa-stop) Stop trace server',
tooltip: 'Click here to stop the trace server',
priority: 5003,
onclick: this.stopServer.bind(this)
});

}

private async startServer() {
await this.traceServerConfigService.startTraceServer(this.path, this.port);
}

private async stopServer() {
await this.traceServerConfigService.stopTraceServer(this.port);
}

protected handleOffline(): void {
this.toDisposeOnOnline.dispose();
this.statusBar.setElement(this.statusbarId, {
alignment: StatusBarAlignment.LEFT,
text: 'Trace Server Offline',
tooltip: 'Cannot connect to trace server.',
priority: 5000
text: '$(fas fa-play) Start trace server',
tooltip: 'Click here to start the trace server',
priority: 5001,
onclick: this.startServer.bind(this)
});

this.toDisposeOnOnline.push(Disposable.create(() => this.statusBar.removeElement(this.statusbarId)));
document.body.classList.add('traceserver-mod-offline');
this.toDisposeOnOnline.push(Disposable.create(() => document.body.classList.remove('traceserver-mod-offline')));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import { inject, injectable } from 'inversify';
import { TraceViewerEnvironment } from '../common/trace-viewer-environment';
import { TraceServerUrlProvider, TRACE_SERVER_DEFAULT_URL } from '../common/trace-server-url-provider';
import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser';
import { TraceServerUrlProvider, TRACE_SERVER_DEFAULT_URL, TRACE_SERVER_DEFAULT_PORT } from '../common/trace-server-url-provider';
import { FrontendApplicationContribution, FrontendApplication, PreferenceService } from '@theia/core/lib/browser';
import { TRACE_PORT } from './trace-server-preference';

@injectable()
export class TraceServerUrlProviderImpl implements TraceServerUrlProvider, FrontendApplicationContribution {

protected _traceServerUrl: string;
protected _listeners: ((url: string) => void)[];
private port: string | undefined;

constructor(
@inject(TraceViewerEnvironment) protected readonly traceViewerEnvironment: TraceViewerEnvironment
@inject(TraceViewerEnvironment) protected readonly traceViewerEnvironment: TraceViewerEnvironment,
@inject(PreferenceService) protected readonly preferenceService: PreferenceService

) {
this._traceServerUrl = TRACE_SERVER_DEFAULT_URL;
this.port = this.preferenceService.get(TRACE_PORT);
this.preferenceService.onPreferenceChanged(event => {
if (event.preferenceName === TRACE_PORT) {
this.port = event.newValue;
this._traceServerUrl = TRACE_SERVER_DEFAULT_URL.replace(/{}/g, this.port ? this.port : TRACE_SERVER_DEFAULT_PORT);
this.updateListeners();
}

});

this._traceServerUrl = TRACE_SERVER_DEFAULT_URL.replace(/{}/g, this.port ? this.port : TRACE_SERVER_DEFAULT_PORT);
this._listeners = [];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContainerModule, Container } from 'inversify';
import { WidgetFactory, OpenHandler, FrontendApplicationContribution, bindViewContribution } from '@theia/core/lib/browser';
import { WidgetFactory, OpenHandler, FrontendApplicationContribution, bindViewContribution, WebSocketConnectionProvider } from '@theia/core/lib/browser';
import { TraceViewerWidget, TraceViewerWidgetOptions } from './trace-viewer';
import { TraceViewerContribution } from './trace-viewer-contribution';
import { TraceViewerEnvironment } from '../../common/trace-viewer-environment';
Expand All @@ -11,16 +11,14 @@ import 'ag-grid-community/dist/styles/ag-theme-balham-dark.css';
import 'ag-grid-community/dist/styles/ag-theme-balham.css';
import 'react-grid-layout/css/styles.css';
import 'react-resizable/css/styles.css';
// import 'semantic-ui-css/semantic.min.css';
import { TraceExplorerContribution } from '../trace-explorer/trace-explorer-contribution';
import { TRACE_EXPLORER_ID, TraceExplorerWidget } from '../trace-explorer/trace-explorer-widget';
import { TspClientProvider } from '../tsp-client-provider';
import { TheiaMessageManager } from '../theia-message-manager';
import { TraceServerConnectionStatusService, TraceServerConnectionStatusContribution } from '../../browser/trace-server-status';
import { TraceServerUrlProviderImpl } from '../trace-server-url-provider-frontend-impl';
// import { TracePropertiesContribution } from '../trace-properties-view/trace-properties-view-contribution';
// import { TracePropertiesWidget, TRACE_PROPERTIES_ID } from '../trace-properties-view/trace-properties-view-widget';

import { bindTraceServerPreferences } from '../trace-server-bindings';
import { TraceServerConfigService, traceServerPath } from '../../common/trace-server-config';
export default new ContainerModule(bind => {

bind(TraceViewerEnvironment).toSelf().inRequestScope();
Expand Down Expand Up @@ -54,11 +52,18 @@ export default new ContainerModule(bind => {
createWidget: () => context.container.get<TraceExplorerWidget>(TraceExplorerWidget)
}));

bind(TraceServerConfigService).toDynamicValue(ctx => {
const connection = ctx.container.get(WebSocketConnectionProvider);
return connection.createProxy<TraceServerConfigService>(traceServerPath);
}).inSingletonScope();

bind(TraceServerConnectionStatusService).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(TraceServerConnectionStatusService);
bind(TraceServerConnectionStatusContribution).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(TraceServerConnectionStatusContribution);

bindTraceServerPreferences(bind);

// bindViewContribution(bind, TracePropertiesContribution);
// bind(TracePropertiesWidget).toSelf();
// bind(WidgetFactory).toDynamicValue(context => ({
Expand Down
15 changes: 15 additions & 0 deletions viewer-prototype/src/common/trace-server-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

export const traceServerPath = '/services/trace-server-config';
export const TraceServerConfigService = Symbol('TraceServerConfigService');
export interface TraceServerConfigService {
/**
* Spawn the trace server from a given path
*/
startTraceServer(path: string | undefined, port: number | undefined): Promise<void>;

/**
* Stop the trace server
*/
stopTraceServer(port: number | undefined): Promise<void>;
}

4 changes: 3 additions & 1 deletion viewer-prototype/src/common/trace-server-url-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const TraceServerUrlProvider = Symbol('TraceServerUrlProvider');
export const TRACE_SERVER_DEFAULT_URL = 'http://localhost:8080/tsp/api';
export const TRACE_SERVER_DEFAULT_URL = 'http://localhost:{}/tsp/api';
export const TRACE_SERVER_DEFAULT_PORT = '8080';

export interface TraceServerUrlProvider {

/**
Expand Down
17 changes: 14 additions & 3 deletions viewer-prototype/src/common/trace-viewer-environment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { injectable, inject } from 'inversify';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { TRACE_SERVER_DEFAULT_URL } from './trace-server-url-provider';
import { TRACE_SERVER_DEFAULT_URL, TRACE_SERVER_DEFAULT_PORT } from './trace-server-url-provider';
import { PreferenceService } from '@theia/core/lib/browser';
import { TRACE_PORT } from '../browser/trace-server-preference';

@injectable()
export class TraceViewerEnvironment {
private port: string | undefined;

constructor(
@inject(EnvVariablesServer) protected readonly environments: EnvVariablesServer) {
@inject(EnvVariablesServer) protected readonly environments: EnvVariablesServer,
@inject(PreferenceService) protected readonly preferenceService: PreferenceService) {

this.port = this.preferenceService.get(TRACE_PORT);
this.preferenceService.onPreferenceChanged(event => {
if (event.preferenceName === TRACE_PORT) {
this.port = event.newValue;
this._traceServerUrl = TRACE_SERVER_DEFAULT_URL.replace(/{}/g, this.port ? this.port : TRACE_SERVER_DEFAULT_PORT);
}
});
}

protected _traceServerUrl: string | undefined;
Expand All @@ -16,7 +27,7 @@ export class TraceViewerEnvironment {
const traceServerUrl = await this.environments.getValue('TRACE_SERVER_URL');
this._traceServerUrl = traceServerUrl ? this.parseUrl(traceServerUrl.value || TRACE_SERVER_DEFAULT_URL) : TRACE_SERVER_DEFAULT_URL;
}
return this._traceServerUrl;
return this._traceServerUrl.replace(/{}/g, this.port ? this.port : TRACE_SERVER_DEFAULT_PORT);
}

private parseUrl(url: string): string {
Expand Down
Loading

0 comments on commit f87b732

Please sign in to comment.