There’s now an official API for Grammarly and a language server. That means we can use eglot
to get Grammarly in Emacs buffers. Here’s the setup which mostly works.
You can get an Grammarly API client ID by creating an app here.
Build the Grammarly VSCode extension:
git clone git@github.com:znck/grammarly.git
cd grammarly
# Install pnpm if you don't have it installed already
npm install -g pnpm
# Build the extension and language server
pnpm build
Wrap the node based language server in a script:
#!/bin/sh
node /{PATH TO REPO}/grammarly/extension/dist/server/index.node.js --stdio
Add it to the path or copy it to a global bin:
cp /{PATH TO REPO}/grammarlylsp /usr/local/bin/grammarlylsp
# Make it executable
chmod +x grammarlylsp
Configure eglot
to use it when in markdown mode:
(defclass eglot-grammarlylsp (eglot-lsp-server) ()
:documentation "Grammarly Language Server.")
(cl-defmethod eglot-initialization-options ((server eglot-grammarlylsp))
"Passes the initializationOptions required to run
the server."
`(:clientId "{GRAMMARLY API CLIENT ID HERE"))
(add-to-list 'eglot-server-programs
`(markdown-mode . (eglot-grammarlylsp ,(executable-find "grammarlylsp"))))