emacs-grammarly / lsp-grammarly

lsp-mode ❤️ grammarly
GNU General Public License v3.0
197 stars 12 forks source link

How to use with markdown files? #63

Closed jcubic closed 7 months ago

jcubic commented 7 months ago

I want to use Grammarly in Markdown files, but got a prompt to install a client and then:

File mode specification error: (wrong-type-argument lsp--client nil)

After restarting emacs, got this error:

Debugger entered--Lisp error: (wrong-type-argument listp #s(lsp--client :language-id nil :add-on? t :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace) #<bytecode -0xe2723684d17a9ca>) :test? #f(compiled-function () #<bytecode 0x28d56a2851c9>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x154d78b> :request-handlers #<hash-table equal 0/65 0x159cba1> :response-handlers #<hash-table eql 0/65 0x159cdcf> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x152bb4f> :action-handlers #<hash-table equal 0/65 0x152bbf3> :major-modes (text-mode latex-mode org-mode markdown-mode) :activation-fn nil :priority -1 :server-id grammarly-ls :multi-root nil :initialization-options ((clientId . "client_BaDkMgx4X19X9UxxYRCXZo") (name . "Grammarly")) :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn nil :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn lsp-grammarly--init :async-request-handlers #<hash-table equal 2/65 0xc65b85> :download-server-fn (closure (t) (_client callback error-callback _update?) (lsp-package-ensure 'grammarly-ls callback error-callback)) :download-in-progress? nil :buffers nil :synchronize-sections nil))
  lsp--start-workspace(#s(lsp-session :folders ("/home/kuba/projects/jcubic/scheme/lips/docs/docs/s...") :folders-blocklist nil :server-id->folders #<hash-table equal 0/65 0x15ecf4f> :folder->servers #<hash-table equal 0/65 0x15befad> :metadata #<hash-table equal 0/65 0x15b7df7>) #s(lsp--client :language-id nil :add-on? t :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace) #<bytecode -0xe2723684d17a9ca>) :test? #f(compiled-function () #<bytecode 0x28d56a2851c9>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x154d78b> :request-handlers #<hash-table equal 0/65 0x159cba1> :response-handlers #<hash-table eql 0/65 0x159cdcf> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x152bb4f> :action-handlers #<hash-table equal 0/65 0x152bbf3> :major-modes (text-mode latex-mode org-mode markdown-mode) :activation-fn nil :priority -1 :server-id grammarly-ls :multi-root nil :initialization-options ((clientId . "client_BaDkMgx4X19X9UxxYRCXZo") (name . "Grammarly")) :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn nil :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn lsp-grammarly--init :async-request-handlers #<hash-table equal 2/65 0xc65b85> :download-server-fn (closure (t) (_client callback error-callback _update?) (lsp-package-ensure 'grammarly-ls callback error-callback)) :download-in-progress? nil :buffers nil :synchronize-sections nil) "/home/kuba/projects/jcubic/scheme/lips/docs/docs/s..." ((clientId . "client_BaDkMgx4X19X9UxxYRCXZo") (name . "Grammarly")))
  lsp--start-connection(#s(lsp-session :folders ("/home/kuba/projects/jcubic/scheme/lips/docs/docs/s...") :folders-blocklist nil :server-id->folders #<hash-table equal 0/65 0x15ecf4f> :folder->servers #<hash-table equal 0/65 0x15befad> :metadata #<hash-table equal 0/65 0x15b7df7>) #s(lsp--client :language-id nil :add-on? t :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace) #<bytecode -0xe2723684d17a9ca>) :test? #f(compiled-function () #<bytecode 0x28d56a2851c9>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x154d78b> :request-handlers #<hash-table equal 0/65 0x159cba1> :response-handlers #<hash-table eql 0/65 0x159cdcf> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x152bb4f> :action-handlers #<hash-table equal 0/65 0x152bbf3> :major-modes (text-mode latex-mode org-mode markdown-mode) :activation-fn nil :priority -1 :server-id grammarly-ls :multi-root nil :initialization-options ((clientId . "client_BaDkMgx4X19X9UxxYRCXZo") (name . "Grammarly")) :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn nil :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn lsp-grammarly--init :async-request-handlers #<hash-table equal 2/65 0xc65b85> :download-server-fn (closure (t) (_client callback error-callback _update?) (lsp-package-ensure 'grammarly-ls callback error-callback)) :download-in-progress? nil :buffers nil :synchronize-sections nil) "/home/kuba/projects/jcubic/scheme/lips/docs/docs/s...")
  #f(compiled-function (client) #<bytecode 0x1caba33dc45fd5de>)(#s(lsp--client :language-id nil :add-on? t :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace) #<bytecode -0xe2723684d17a9ca>) :test? #f(compiled-function () #<bytecode 0x28d56a2851c9>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x154d78b> :request-handlers #<hash-table equal 0/65 0x159cba1> :response-handlers #<hash-table eql 0/65 0x159cdcf> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x152bb4f> :action-handlers #<hash-table equal 0/65 0x152bbf3> :major-modes (text-mode latex-mode org-mode markdown-mode) :activation-fn nil :priority -1 :server-id grammarly-ls :multi-root nil :initialization-options ((clientId . "client_BaDkMgx4X19X9UxxYRCXZo") (name . "Grammarly")) :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn nil :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn lsp-grammarly--init :async-request-handlers #<hash-table equal 2/65 0xc65b85> :download-server-fn (closure (t) (_client callback error-callback _update?) (lsp-package-ensure 'grammarly-ls callback error-callback)) :download-in-progress? nil :buffers nil :synchronize-sections nil))
  -map(#f(compiled-function (client) #<bytecode 0x1caba33dc45fd5de>) (#s(lsp--client :language-id nil :add-on? t :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace) #<bytecode -0xe2723684d17a9ca>) :test? #f(compiled-function () #<bytecode 0x28d56a2851c9>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x154d78b> :request-handlers #<hash-table equal 0/65 0x159cba1> :response-handlers #<hash-table eql 0/65 0x159cdcf> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x152bb4f> :action-handlers #<hash-table equal 0/65 0x152bbf3> :major-modes (text-mode latex-mode org-mode markdown-mode) :activation-fn nil :priority -1 :server-id grammarly-ls :multi-root nil :initialization-options ((clientId . "client_BaDkMgx4X19X9UxxYRCXZo") (name . "Grammarly")) :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn nil :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn lsp-grammarly--init :async-request-handlers #<hash-table equal 2/65 0xc65b85> :download-server-fn (closure (t) (_client callback error-callback _update?) (lsp-package-ensure 'grammarly-ls callback error-callback)) :download-in-progress? nil :buffers nil :synchronize-sections nil)))
  lsp--ensure-lsp-servers(#s(lsp-session :folders ("/home/kuba/projects/jcubic/scheme/lips/docs/docs/s...") :folders-blocklist nil :server-id->folders #<hash-table equal 0/65 0x15ecf4f> :folder->servers #<hash-table equal 0/65 0x15befad> :metadata #<hash-table equal 0/65 0x15b7df7>) (#s(lsp--client :language-id nil :add-on? t :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace) #<bytecode -0xe2723684d17a9ca>) :test? #f(compiled-function () #<bytecode 0x28d56a2851c9>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x154d78b> :request-handlers #<hash-table equal 0/65 0x159cba1> :response-handlers #<hash-table eql 0/65 0x159cdcf> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x152bb4f> :action-handlers #<hash-table equal 0/65 0x152bbf3> :major-modes (text-mode latex-mode org-mode markdown-mode) :activation-fn nil :priority -1 :server-id grammarly-ls :multi-root nil :initialization-options ((clientId . "client_BaDkMgx4X19X9UxxYRCXZo") (name . "Grammarly")) :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn nil :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn lsp-grammarly--init :async-request-handlers #<hash-table equal 2/65 0xc65b85> :download-server-fn (closure (t) (_client callback error-callback _update?) (lsp-package-ensure 'grammarly-ls callback error-callback)) :download-in-progress? nil :buffers nil :synchronize-sections nil)) "/home/kuba/projects/jcubic/scheme/lips/docs/docs/s..." nil)
  lsp--try-project-root-workspaces(nil nil)
  lsp()
  markdown()
  run-hooks(change-major-mode-after-body-hook text-mode-hook markdown-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook text-mode-hook markdown-mode-hook))
  run-mode-hooks(markdown-mode-hook)
  markdown-mode()
  set-auto-mode-0(markdown-mode nil)
  set-auto-mode--apply-alist((("\\.cjs\\'" . web-mode) ("\\.mjs\\'" . web-mode) ("\\.tsx\\'" . web-mode) ("\\.ts$" . typescript-mode) ("\\.R$" . R-mode) ("\\.\\(js\\)\\'" . javascript-mode) ("\\.\\(gs\\)\\'" . ruby-mode) ("\\.jsx\\'" . web-mode) ("\\.\\(template\\|tpl\\)\\'" . mustache-mode) ("\\.markdown$" . jekyll-markdown-mode) ("\\.\\(prisma\\)\\'" . prisma-mode) ("\\.\\(md\\)\\'" . markdown-mode) ("\\.\\(php\\|php\\.in\\|xml\\|twig\\|rss\\|xsl\\|svg\\|glade\\..." . web-mode) ("\\.\\(liquid\\)\\'" . web-mode) ("\\.\\(ejs\\)\\'" . web-mode) ("\\.\\(css\\)\\'" . web-mode) ("\\.\\(cs\\)\\'" . csharp-mode) ("\\.ya?ml$" . yaml-mode) ("\\.prisma$" . prisma-mode) ("\\.stpm$" . systemtap-mode) ("\\.stp$" . systemtap-mode) ("\\.desktop\\(\\.in\\)?$" . desktop-entry-mode) ("CMakeLists\\.txt\\'" . cmake-mode) ("\\.cmake\\'" . cmake-mode) (".at'" . autotest-mode) ("\\(?:build\\|profile\\)\\.boot\\'" . clojure-mode) ("\\.cljs\\'" . clojurescript-mode) ("\\.cljc\\'" . clojurec-mode) ("\\.\\(clj\\|cljd\\|dtm\\|edn\\)\\'" . clojure-mode) ("\\.editorconfig\\'" . editorconfig-conf-mode) ("\\.[Ss][Aa][Ss]\\'" . SAS-mode) ("\\.Sout\\'" . S-transcript-mode) ("\\.[Ss]t\\'" . S-transcript-mode) ("\\.Rd\\'" . Rd-mode) ("DESCRIPTION\\'" . conf-colon-mode) ("/Makevars\\(\\.win\\)?\\'" . makefile-mode) ("\\.[Rr]out\\'" . ess-r-transcript-mode) ("CITATION\\'" . ess-r-mode) ("NAMESPACE\\'" . ess-r-mode) ("\\.[rR]profile\\'" . ess-r-mode) ("\\.[rR]\\'" . ess-r-mode) ("/R/.*\\.q\\'" . ess-r-mode) ("\\.[Jj][Aa][Gg]\\'" . ess-jags-mode) ("\\.[Bb][Mm][Dd]\\'" . ess-bugs-mode) ("\\.[Bb][Oo][Gg]\\'" . ess-bugs-mode) ("\\.[Bb][Uu][Gg]\\'" . ess-bugs-mode) ("\\.\\(?:md\\|markdown\\|mkd\\|mdown\\|mkdn\\|mdwn\\)\\'" . markdown-mode) ("\\.jsx\\'" . rjsx-mode) ("\\.tsx?\\'" . typescript-mode) ("\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'" nil epa-file) ...) nil nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil t)
  find-file-noselect-1(#<buffer basic-expressions.md> "~/projects/jcubic/scheme/lips/docs/docs/scheme-int..." nil nil "~/projects/jcubic/scheme/lips/docs/docs/scheme-int..." (205553635 2053))
  find-file-noselect("~/projects/jcubic/scheme/lips/docs/docs/scheme-int..." nil nil nil)
  find-file("~/projects/jcubic/scheme/lips/docs/docs/scheme-int...")
  find-every-file("~/projects/jcubic/scheme/lips/docs/docs/scheme-int..." t)
  funcall-interactively(find-every-file "~/projects/jcubic/scheme/lips/docs/docs/scheme-int..." t)
  command-execute(find-every-file)

I run this code:

(defun markdown ()
  (setq fill-column 100)
  (ispell-change-dictionary
   (if (let ((name (buffer-file-name)))
         (or (string-match-p "jcubic/www/blog/repo" name)
             (string-match-p "jcubic/www/jankiewicz" name)
             (string-match-p "jcubic/astek/blog" name)
             (string-match-p "/pl/" name)))
       "polish"
     "english"))
  (flyspell-mode)
  (flyspell-buffer)
  (require 'lsp-grammarly)
  (lsp))

(add-hook 'markdown-mode-hook 'markdown)

Removing flyspell makes no difference.

When trying to login I got this error:

lsp--send-request-async: The connected server(s) does not support method $/isUserAccountConnected.
To find out what capabilities support your server use ‘M-x lsp-describe-session’
and expand the capabilities section
jcs090218 commented 7 months ago

Can you try reinstalling lsp-mode and lsp-grammarly? It doesn't look right. 🤔 Markdown is supported by default.

When trying to login, I got this error:

Login is not supported yet. I'm trying to migrate from the old language server (login works with the old one) to a new language server with official API support. However, I don't have the knowledge to implement this feature since they are using some VSCode-specific API. 🥲

jcubic commented 7 months ago

Previously I was using code from git (I had wrong repo and was not able to install from melpa) but after installing from melpa I still have the same error.

jcubic commented 7 months ago

Ok, reinstalled lsp-mode and it seems to work. Kind of because it doesn't correct the grammar.

Is there a way to use the old server so I can login and use Grammarly?

when executed: lsp-grammarly-check-grammar I got this error:

LSP :: Error from the Language Server: Request $/resume failed with message: object is not iterable (cannot read property Symbol(Symbol.iterator)) (Internal Error)

Note that I use lsp-mode for the first time.

jcs090218 commented 7 months ago

Is there a way to use the old server so I can login and use Grammarly?

I don't recommended since it's pretty much unmaintained and the result can be inaccurate. But here are the links:

when executed: lsp-grammarly-check-grammar I got this error:

This still doesn't look right. Can you try M-x toggle-debug-on-error and paste the backtrace here? 🤔 BTW, normally you don't need to do this since it will be checked by default.

jcubic commented 7 months ago

And you don't need to log in to use lsp-grammarly? I only use Grammarly as a Chrome extension and I think that I'm always logged in even though I don't have a pro account.

jcs090218 commented 7 months ago

Yes, you don't need to login to use Grammarly. You are only required to login if you want the premium version.

jcubic commented 7 months ago

I ran it again in a new session and I think it's working, more or less.