brymer-meneses / grammar-guard.nvim

Grammar Guard is a Neovim plugin that checks your grammar as you write your LaTeX, Markdown or plain text document.
Apache License 2.0
154 stars 6 forks source link

Problems with setup: `attempt to index field 'grammar_guard' (a nil value)` #5

Closed David-Else closed 2 years ago

David-Else commented 2 years ago

It says [grammar-guard] The ltex language server has not been installed. Run :GrammarInstall to install it., this is not true, I have ltex-ls installed and in the path. I don't want to run the installer as I don't know what it does to my system, I would like to use my own installation.

In my init.vim I have this extension installed via vim-plug:

Plug 'brymer-meneses/grammar-guard.nvim'

lua require("lsp")

lsp.lua

  local nvim_lsp = require 'lspconfig'

  require('grammar-guard').init()

  nvim_lsp.grammar_guard.setup {
    settings = {
      ltex = {
        enabled = { 'latex', 'tex', 'bib', 'markdown' },
        language = 'en',
        diagnosticSeverity = 'information',
        setenceCacheSize = 2000,
        additionalRules = {
          enablePickyRules = true,
          motherTongue = 'en',
        },
        trace = { server = 'verbose' },
        dictionary = {},
        disabledRules = {},
        hiddenFalsePositives = {},
      },
    },
  }

But I get E5108: Error executing lua xxx/lsp.lua:17: attempt to index field 'grammar_guard' (a nil value)

PS I hope this pull request https://github.com/neovim/nvim-lspconfig/pull/863 gets sorted soon, I am trying this extension until then.

I tried with Neovim 0.5.1 and the master, Thanks!

mjlbach commented 2 years ago

The installer looks harmless FWIW https://github.com/brymer-meneses/grammar-guard.nvim/blob/a52876d45ce29f22a4e538ce389eec848fb9f078/lua/grammar-guard/installer.lua#L1-L40

If you don't want to use the installer, there isn't much difference between this extension and just:

local bin_path = '/home/michael/.local/share/nvim/grammar-guard/ltex/bin/ltex-ls'
require('lspconfig/configs').ltex_ls = {
  default_config = {
    cmd = { bin_path },
    filetypes = { 'tex', 'bib', 'markdown' },
    root_dir = require('lspconfig/util').find_git_ancestor,
    settings = {
      ltex = {
        enabled = { 'latex', 'tex', 'bib', 'markdown' },
        language = 'en',
        diagnosticSeverity = 'information',
        setenceCacheSize = 2000,
        additionalRules = {
          enablePickyRules = true,
          motherTongue = 'en',
        },
        trace = { server = 'verbose' },
        dictionary = {},
        disabledRules = {},
        hiddenFalsePositives = {},
      },
    },
  },
}

require('lspconfig').ltex_ls.setup {
  --on_attach = on_attach,
  --handlers = handlers,
}
David-Else commented 2 years ago

@mjlbach Thanks for helping! I added the above, but it is not attaching. I get the following from Lspinfo:

Other clients that match the filetype: markdown                                                                                                         
~                                                                                                                                                                           
~                   Config: ltex_ls                                                                                                                                         
~                    filetypes:         tex, bib, markdown                                                                                                                  
~                    root directory:    NA                                                                                                                                  
~                    cmd:               /home/david/bin/ltex-ls-14.0.0/bin/ltex-ls                                                                                          
~                    cmd is executable: true                                                                                                                                
~                    autostart:         true                                                                                                                                
~                    custom handlers:             

The logs don't mention ltex_ls. Does it need a root directory type, or maybe something else is missing?

mjlbach commented 2 years ago

Yeah, I always keep my latex files under a git directory. While the built in client doesn't need you to pass root, lspconfig still expects a "root" (note, not rootUri) in order to handle "autoattaching" vs autospawning. This is a holdover from the original design of lspconfig, I would just move your files into a git directory (sorry, it's late for me). In the rewrite you can use a scratch server for all latex docs, or declaratively set up projects (via project local configuration files, or my declaratively specifying the project in a runtime lua file, with fallback behavior resembling the current lspconfig behavior but will all the util.dirname hacks purged.

David-Else commented 2 years ago

@mjlbach I think I have found a bug in the LSP setup you provided, or maybe Neovim itself. Please have a look at these two comments, what do you think? https://github.com/valentjn/ltex-ls/issues/113#issuecomment-951239242

mjlbach commented 2 years ago

Codeactions is more @mfusseneggers's thing (sorry to throw you under the bus :P) as I don't really use them. You can file an issue on neovim/neovim (core, not lspconfig) with:

  1. The exact repository including the text document and n-gram data (or whatever it is you need to support the code action from that linked issue
  2. Your minimal init.lua (preferably the one from lspconfig with the minimal changes for ltex-ls
  3. The RPC logs from that linked issue, specifically reproduced in neovim. I didn't look at them closely yet, but nothing was obviously wrong to me, and it didn't look like the code action was trying to match against a command that needed to be implemented client-side, which would have been my first guess (it might have)
oblitum commented 2 years ago

~@mfusseneggers~@mfussenegger ^

David-Else commented 2 years ago

@mjlbach @oblitum The https://github.com/brymer-meneses/grammar-guard.nvim/issues/5#issuecomment-951661711 bug was a user error, plz ignore.

@mjlbach It would be great to get the config you gave me into nvim-lspconfig! It works perfectly, I see no reason to delay it.

mjlbach commented 2 years ago

I'm not delaying it, someone just needs to file/follow-up on the PR, and preferably continue implementing client-side, of-spec functionality in grammarguard (or another) plugin that we can then link to if someone wants something more full featured.

David-Else commented 2 years ago

Now ltex-lsp is in nvim-lspconfig I assume grammar-guard is going to need a major update, so this issue is probably irrelevant, I will close it.