PT #157480703: switching boot hints on/off via preferences

This commit is contained in:
BoykoAlex
2018-05-16 09:31:18 -04:00
parent 566035862f
commit ceb8b43371
7 changed files with 116 additions and 6 deletions

View File

@@ -32,7 +32,7 @@ Open http://localhost:3000 in the browser.
## Developing with the browser example
Start watching of the hello world extension.
Start watching of the extension.
cd spring-boot
yarn watch
@@ -49,7 +49,7 @@ Open http://localhost:3000 in the browser.
## Developing with the Electron example
Start watching of the hello world extension.
Start watching of extension.
cd spring-boot
yarn watch

View File

@@ -12,6 +12,7 @@
"dependencies": {
"@theia/core": "latest",
"@theia/languages": "latest",
"@theia/preferences": "latest",
"@theia/editor": "latest",
"@theia/monaco": "latest",
"@theia/java": "latest",

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2018 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
import { interfaces } from 'inversify';
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';
// tslint:disable:max-line-length
export const BootConfigSchema: PreferenceSchema = {
'type': 'object',
'title': 'Spring Boot Java Configuration',
properties: {
'boot-java.boot-hints.on': {
type: 'boolean',
description: 'Enable/Disable Spring running Boot application live hints decorators in Java source code.',
default: false
},
'spring-boot.ls.java.home': {
type: 'string',
description: `Override JAVA_HOME used for launching the spring-boot-language-server JVM process.`,
default: null
},
'spring-boot.ls.java.heap': {
type: 'string',
description: `Max JVM heap value, passed via -Xmx argument when launching spring-boot-language-server JVM process.`,
default: null
}
}
};
export interface BootConfiguration {
'boot-java.boot-hints.on': boolean;
'spring-boot.ls.java.home': string | null;
'spring-boot.ls.java.heap': string | null;
}
export const BootPreferences = Symbol('BootJavaPreferences');
export type BootPreferences = PreferenceProxy<BootConfiguration>;
export function createBootPreferences(preferences: PreferenceService): BootPreferences {
return createPreferenceProxy(preferences, BootConfigSchema);
}
export function bindBootPreferences(bind: interfaces.Bind): void {
bind(BootPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createBootPreferences(preferences);
});
bind(PreferenceContribution).toConstantValue({ schema: BootConfigSchema });
}

View File

@@ -1,4 +1,4 @@
import { injectable, inject } from 'inversify';
import { injectable, inject, postConstruct } from 'inversify';
import { BaseLanguageClientContribution, Workspace, Languages, LanguageClientFactory } from '@theia/languages/lib/browser';
import {
SPRING_BOOT_SERVER_ID,
@@ -10,6 +10,13 @@ import { DocumentSelector } from '@theia/languages/lib/common';
import { JAVA_LANGUAGE_ID } from '@theia/java/lib/common';
import { HighlightService} from './highlight-service';
import { ClasspathService } from './classpath-service';
import { BootPreferences } from './boot-preferences';
import { NotificationType } from 'vscode-jsonrpc';
import { DidChangeConfigurationParams } from 'vscode-base-languageclient/lib/base';
import { Utils } from './utils';
const CONFIG_CHANGED_NOTIFICATION_TYPE = new NotificationType<DidChangeConfigurationParams,void>('workspace/didChangeConfiguration');
@injectable()
export class SpringBootClientContribution extends BaseLanguageClientContribution {
@@ -22,15 +29,35 @@ export class SpringBootClientContribution extends BaseLanguageClientContribution
@inject(Languages) protected readonly languages: Languages,
@inject(LanguageClientFactory) protected readonly languageClientFactory: LanguageClientFactory,
@inject(HighlightService) protected readonly highlightService: HighlightService,
@inject(ClasspathService) protected readonly classpathService: ClasspathService
@inject(ClasspathService) protected readonly classpathService: ClasspathService,
@inject(BootPreferences) protected readonly preferences: BootPreferences
) {
super(workspace, languages, languageClientFactory);
}
@postConstruct()
protected async init() {
await this.preferences.ready;
// Send settings to LS
this.sendConfig();
this.preferences.onPreferenceChanged(() => this.sendConfig());
this.languageClient.then(client => {
this.highlightService.attach(client);
// this.classpathService.attach(client);
});
}
private sendConfig() {
return this.languageClient.then(client => {
const params = Utils.convertDotToNested(Object.assign({}, this.preferences));
return client.sendNotification(CONFIG_CHANGED_NOTIFICATION_TYPE, {
settings: params
});
})
}
protected get documentSelector(): DocumentSelector | undefined {
return [JAVA_LANGUAGE_ID, BOOT_PROPERTIES_YAML_LANGUAGE_ID, BOOT_PROPERTIES_LANGUAGE_ID];
}

View File

@@ -6,9 +6,11 @@ import './monaco-yaml-contribution';
import './monaco-properties-contribution';
import { HighlightService } from './highlight-service';
import { ClasspathService } from './classpath-service';
import { bindBootPreferences } from './boot-preferences';
export default new ContainerModule(bind => {
// add your contribution bindings here
bindBootPreferences(bind);
bind(LanguageClientContribution).to(SpringBootClientContribution).inSingletonScope();
bind(HighlightService).toSelf().inSingletonScope();
bind(ClasspathService).toSelf().inSingletonScope();

View File

@@ -0,0 +1,27 @@
export class Utils {
private static setNestedValue(properties: string[], value: any, obj: any){
if (properties.length > 1) {
// The property doesn't exists OR is not an object (and so we overwritte it) so we create it
if (!obj.hasOwnProperty(properties[0]) || typeof obj[properties[0]] !== 'object') {
obj[properties[0]] = {};
}
Utils.setNestedValue(properties.slice(1), value, obj[properties[0]]);
} else {
obj[properties[0]] = value;
}
}
public static convertDotToNested(source: any): any {
const result = {};
Object.keys(source).forEach(property => {
const properties = property.split('.');
if (source[property] && typeof source[property] === 'object') {
Utils.setNestedValue(properties, Utils.convertDotToNested(source[property]), result);
} else {
Utils.setNestedValue(properties, source[property], result);
}
});
return result;
}
}

View File

@@ -56,8 +56,7 @@ export class SpringBootLsContribution extends BaseLanguageServerContribution {
'-Dsts.lsp.client=theia',
'-Dlsp.completions.indentation.enable=true',
'-Dlsp.yaml.completions.errors.disable=true',
'-Dorg.slf4j.simpleLogger.logFile=boot-java.log',
'-Dorg.slf4j.simpleLogger.defaultLogLevel=debug'
'-Dorg.slf4j.simpleLogger.logFile=boot-java.log'
];
args.push(`-Dserver.port=${env.CLIENT_PORT}`);