Skip to content

Commit

Permalink
Merge pull request #172 from kieler/nre/externalActionHandlers
Browse files Browse the repository at this point in the history
API fixes
  • Loading branch information
NiklasRentzCAU authored May 8, 2024
2 parents 2797033 + 4e31a8d commit 816d646
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
13 changes: 10 additions & 3 deletions applications/klighd-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,16 @@ function isLanguageClient(client: unknown): client is LanguageClient {
// Therefore, they are two different classes internally.

// To work around this, we ensure that it is an object and check the object
// for the existence of a few methods.

const wantedMethod = ['onReady', 'sendNotification', 'onNotification', 'sendRequest', 'onRequest']
// for the existence of a few methods that are used in this extension.

const wantedMethod = [
'needsStart',
'onDidChangeState',
'onNotification',
'onRequest',
'sendNotification',
'sendRequest',
]

const isObject = typeof client === 'object' && client !== null
const hasWantedMethods = wantedMethod.every(
Expand Down
19 changes: 10 additions & 9 deletions applications/klighd-vscode/src/webview-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2023 by
* Copyright 2023-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand Down Expand Up @@ -57,14 +57,6 @@ export class KlighDWebviewEndpoint extends WebviewEndpoint {
this.messenger.onRequest(
LspRequest,
async (request) => {
// Catch any diagram/accept action and call the registered action handlers.
if (request.method === 'diagram/accept' && isActionMessage(request.params)) {
const { action } = request.params
const handlers = this.klighdActionHandlers.get(request.params.action.kind)
if (handlers) {
handlers.forEach((handler) => handler(action))
}
}
const result: any =
request.params === undefined
? await this.languageClient.sendRequest(request.method)
Expand All @@ -81,6 +73,15 @@ export class KlighDWebviewEndpoint extends WebviewEndpoint {
this.messenger.onNotification(
LspNotification,
(notification) => {
// Catch any diagram/accept action and call the registered action handlers.
if (notification.method === 'diagram/accept' && isActionMessage(notification.params)) {
const { action } = notification.params
const handlers = this.klighdActionHandlers.get(notification.params.action.kind)
if (handlers) {
handlers.forEach((handler) => handler(action))
// TODO: if one of the handlers says the action does not need to be forwarded to the server, do not forward it.
}
}
this.languageClient.sendNotification(notification.method, notification.params)
},
{ sender: this.messageParticipant }
Expand Down

0 comments on commit 816d646

Please sign in to comment.