Theia Spring-Boot extension new live hover mechanism adoption

This commit is contained in:
BoykoAlex
2019-10-17 12:30:32 -04:00
parent 523e4f7238
commit 6bf343eb6b
2 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2019 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
import {CommandContribution, CommandRegistry} from '@theia/core';
import {QuickPickService} from '@theia/core/lib/common/quick-pick-service';
import {injectable, inject} from 'inversify';
interface ProcessCommandInfo {
processKey : string;
label: string;
action: string
}
@injectable()
export class LiveDataCommandContribution implements CommandContribution {
constructor(
@inject(QuickPickService) private readonly quickPickService: QuickPickService
) {}
registerCommands(commands: CommandRegistry): void {
commands.registerCommand({
id: 'theia-spring-boot.live-hover.connect',
label: 'Manage Live Spring Boot Process Connections'
}, {
execute: () => this.liveHoverConnectHandler(commands, this.quickPickService)
});
}
private async liveHoverConnectHandler(commands: CommandRegistry, quickPickService: QuickPickService) {
const processData : ProcessCommandInfo[] = await commands.executeCommand('sts/livedata/listProcesses');
const choiceMap = new Map<string, ProcessCommandInfo>();
const choices : string[] = [];
processData.forEach(p => {
const slash = p.action.lastIndexOf('/');
if (slash>=0) {
var actionLabel = p.action.substring(slash+1);
actionLabel = actionLabel.substring(0, 1).toUpperCase() + actionLabel.substring(1);
const choiceLabel = actionLabel + " " + p.label;
choiceMap.set(choiceLabel, p);
choices.push(choiceLabel);
}
});
if (choices) {
const picked = await quickPickService.show(choices);
if (picked) {
const chosen = choiceMap.get(picked);
await commands.executeCommand(chosen.action, chosen);
}
}
}
}

View File

@@ -20,6 +20,8 @@ import { BootPropertiesGrammarContribution } from './boot-properties-grammar-con
import { BootYamlGrammarContribution } from './boot-yaml-grammar-contribution';
import { ClasspathService } from './classpath-service';
import {JavaDataService} from './java-data';
import {LiveDataCommandContribution} from './live-data-commands';
import {CommandContribution} from '@theia/core';
export default new ContainerModule(bind => {
// add your contribution bindings here
@@ -31,4 +33,5 @@ export default new ContainerModule(bind => {
bind(HighlightCodeLensService).toSelf().inSingletonScope();
bind(ClasspathService).toSelf().inSingletonScope();
bind(JavaDataService).toSelf().inRequestScope();
bind(CommandContribution).to(LiveDataCommandContribution).inSingletonScope();
});