Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

These messages can be caught on the client side by defining the message that is caught like this:

Code Block
titleClient side message definition
export const snapshotDescriptionMessageType = new NotificationType<CodeContainer, void>('keith/kicool/compile');

This message type is bound to a method that should be called whenever the client receives such a message.

Code Block
titleClient side message registration
const lClient: ILanguageClient = await this.client.languageClient
lClient.onNotification(snapshotDescriptionMessageType, this.handleNewSnapshotDescriptions.bind(this))

...

Such a notification from server to client is send like this:

Code Block
titleServer side message sending
future.thenAccept([
	// client is the KeithLanguageClient registered in a LanguageServerExtension that implements a ILanguageClientProvider
	// compile is the command defined in the KeithLanguageClientInterface
	client.compile(new CompilationResults(this.snapshotMap.get(uri)), uri, finished)
])

...

You can send a request or a notification to the language server like this:

Code Block
titleClient side message sending
const lclient = await this.client.languageClient
const snapshotsDescriptions: CodeContainer = await lclient.sendRequest("keith/kicool/compile", [uri, KeithDiagramManager.DIAGRAM_TYPE + '_sprotty', command,
	this.compilerWidget.compileInplace]) as CodeContainer
// or via a thenable
client.languageClient.then(lClient => {
lClient.sendRequest("keith/kicool/compile").then((snapshotsDescriptions: CodeContainer) => {
	// very important stuff
}
// await is preferred, since it is shorter. 

In this example client is an instance of a language client. It is usually injected like this:

constructor(
Code Block
titleClient side LanguageClientContribution injection
@inject(KeithLanguageClientContribution) public readonly client: KeithLanguageClientContribution
constructor(
	// other injected classes that are relevant for the constructor
    ) {
	// constructor stuff
}

...