From 1ce02ff18b8e92f4757773dd605b767df64f107e Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Wed, 9 May 2018 18:41:40 -0400 Subject: [PATCH] theia-spring-boot: preparation for classpath from JDT LS --- .../src/browser/classpath-service.ts | 36 +++++++++++++++++++ .../src/browser/highlight-service.ts | 8 +++-- .../browser/language-client-contribution.ts | 11 +++--- .../browser/spring-boot-frontend-module.ts | 4 ++- 4 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 theia-extensions/theia-spring-boot/spring-boot/src/browser/classpath-service.ts diff --git a/theia-extensions/theia-spring-boot/spring-boot/src/browser/classpath-service.ts b/theia-extensions/theia-spring-boot/spring-boot/src/browser/classpath-service.ts new file mode 100644 index 000000000..d79a7087d --- /dev/null +++ b/theia-extensions/theia-spring-boot/spring-boot/src/browser/classpath-service.ts @@ -0,0 +1,36 @@ +import { injectable, inject } from 'inversify'; +import { RequestType } from 'vscode-jsonrpc'; +import { CommandRegistry } from '@theia/core/lib/common'; +import { ILanguageClient } from '@theia/languages/lib/common'; + +export const ADD_LISTENER_REQUEST_TYPE = new RequestType("sts/addClasspathListener"); +export const REMOVE_LISTENER_REQUEST_TYPE = new RequestType("sts/removeClasspathListener"); + +@injectable() +export class ClasspathService { + + constructor( + @inject(CommandRegistry) protected readonly commands: CommandRegistry + ) {} + + attach(client: ILanguageClient) { + client.onRequest(ADD_LISTENER_REQUEST_TYPE, params => this.addListener(params)); + client.onRequest(REMOVE_LISTENER_REQUEST_TYPE, params => this.removeListener(params)); + } + + private async addListener(params: ClasspathListenerParams) { + this.commands.executeCommand('sts.java.addClasspathListener', params.callbackCommandId); + } + + private async removeListener(params: ClasspathListenerParams) { + this.commands.executeCommand('sts.java.removeClasspathListener', params.callbackCommandId); + } +} + + +export interface ClasspathListenerParams { + callbackCommandId: string +} + +export interface ClasspathListenerResponse { +} diff --git a/theia-extensions/theia-spring-boot/spring-boot/src/browser/highlight-service.ts b/theia-extensions/theia-spring-boot/spring-boot/src/browser/highlight-service.ts index 57c7ab83b..a05dcc39e 100644 --- a/theia-extensions/theia-spring-boot/spring-boot/src/browser/highlight-service.ts +++ b/theia-extensions/theia-spring-boot/spring-boot/src/browser/highlight-service.ts @@ -2,8 +2,9 @@ import { injectable, inject } from 'inversify'; import { NotificationType } from 'vscode-jsonrpc'; import { TextDocumentIdentifier, Range } from 'vscode-base-languageclient/lib/base'; import { EditorDecorationsService, SetDecorationParams, EditorDecorationStyle } from '@theia/editor/lib/browser'; +import { ILanguageClient } from '@theia/languages/lib/common'; -export const HIGHLIGHTS_NOTIFICATION_TYPE = new NotificationType("sts/highlight"); +const HIGHLIGHTS_NOTIFICATION_TYPE = new NotificationType("sts/highlight"); const BOOT_LIVE_HINTS = 'Boot-Live-Hints'; @@ -28,6 +29,10 @@ export class HighlightService { @inject(EditorDecorationsService) protected readonly decorationService: EditorDecorationsService ) {} + attach(client: ILanguageClient) { + client.onNotification(HIGHLIGHTS_NOTIFICATION_TYPE, (params) => this.highlight(params)); + } + highlight(params: HighlightParams) { const decorationParams: SetDecorationParams = { uri: params.doc.uri, @@ -45,7 +50,6 @@ export class HighlightService { }) }; this.decorationService.setDecorations(decorationParams); - } } diff --git a/theia-extensions/theia-spring-boot/spring-boot/src/browser/language-client-contribution.ts b/theia-extensions/theia-spring-boot/spring-boot/src/browser/language-client-contribution.ts index 80d92447f..79c6db294 100644 --- a/theia-extensions/theia-spring-boot/spring-boot/src/browser/language-client-contribution.ts +++ b/theia-extensions/theia-spring-boot/spring-boot/src/browser/language-client-contribution.ts @@ -8,7 +8,8 @@ import { } from '../common'; import { DocumentSelector } from '@theia/languages/lib/common'; import { JAVA_LANGUAGE_ID } from '@theia/java/lib/common'; -import {HIGHLIGHTS_NOTIFICATION_TYPE, HighlightService} from "./highlight-service"; +import { HighlightService} from "./highlight-service"; +import {ClasspathService} from "./classpath-service"; @injectable() export class SpringBootClientContribution extends BaseLanguageClientContribution { @@ -20,12 +21,14 @@ export class SpringBootClientContribution extends BaseLanguageClientContribution @inject(Workspace) protected readonly workspace: Workspace, @inject(Languages) protected readonly languages: Languages, @inject(LanguageClientFactory) protected readonly languageClientFactory: LanguageClientFactory, - @inject(HighlightService) protected readonly highlightService: HighlightService + @inject(HighlightService) protected readonly highlightService: HighlightService, + @inject(ClasspathService) protected readonly classpathService: ClasspathService ) { super(workspace, languages, languageClientFactory); this.languageClient.then(client => { - client.onNotification(HIGHLIGHTS_NOTIFICATION_TYPE, (params) => this.highlightService.highlight(params)) - }) + this.highlightService.attach(client); + // this.classpathService.attach(client); + }); } protected get documentSelector(): DocumentSelector | undefined { diff --git a/theia-extensions/theia-spring-boot/spring-boot/src/browser/spring-boot-frontend-module.ts b/theia-extensions/theia-spring-boot/spring-boot/src/browser/spring-boot-frontend-module.ts index 5ceb04f64..63696352d 100644 --- a/theia-extensions/theia-spring-boot/spring-boot/src/browser/spring-boot-frontend-module.ts +++ b/theia-extensions/theia-spring-boot/spring-boot/src/browser/spring-boot-frontend-module.ts @@ -5,9 +5,11 @@ import { ContainerModule } from 'inversify'; import './monaco-yaml-contribution'; import './monaco-properties-contribution'; import {HighlightService} from "./highlight-service"; +import {ClasspathService} from "./classpath-service"; export default new ContainerModule(bind => { // add your contribution bindings here - bind(HighlightService).toSelf().inSingletonScope(); bind(LanguageClientContribution).to(SpringBootClientContribution).inSingletonScope(); + bind(HighlightService).toSelf().inSingletonScope(); + bind(ClasspathService).toSelf().inSingletonScope(); }); \ No newline at end of file