Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow service plugins to define request / notification handlers. #120

Open
remcohaszing opened this issue Dec 29, 2023 · 0 comments
Open

Comments

@remcohaszing
Copy link
Member

Based on mdx-js/mdx-analyzer#384, a bit of boilerplate is needed to define custom LSP request and notification handlers.

I think it would be neat if service plugins can specify request and notification handlers. This means language servers no longer have to deal with any of this.

The following service plugin:

export function createMdxServicePlugin() {
  return {
    name: 'mdx',

    create(context) {
      return {
        notification: {
          sayHi(params) {
            // Handle notification
          }
        },

        request: {
          toggleStrong(params) {
            // Handle request
          }
        }
      }
    }
  }
}

Would be equivalent to the following language server code:

connection.onRequest('mdx/toggleStrong', params => {
  // Handle request
})

connection.onNotification('mdx/sayHi', params => {
  // Handle request
})

The service plugin name is used to scope the requests and notifications, and is therefor required.

This could also make usage from contexts other than a language server more straight-forward, e.g. for testing purposes or usage from Monaco editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant