theia-spring-boot: preparation for classpath from JDT LS

This commit is contained in:
BoykoAlex
2018-05-09 18:41:40 -04:00
parent a9c2958ad9
commit 1ce02ff18b
4 changed files with 52 additions and 7 deletions

View File

@@ -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<ClasspathListenerParams, ClasspathListenerResponse, void, void>("sts/addClasspathListener");
export const REMOVE_LISTENER_REQUEST_TYPE = new RequestType<ClasspathListenerParams, ClasspathListenerResponse, void, void>("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 {
}

View File

@@ -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<HighlightParams,void>("sts/highlight");
const HIGHLIGHTS_NOTIFICATION_TYPE = new NotificationType<HighlightParams,void>("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);
}
}

View File

@@ -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 {

View File

@@ -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();
});