Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

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

Closed
David-Else opened this issue Oct 20, 2021 · 9 comments

Comments

@David-Else
Copy link

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 neovim/nvim-lspconfig#863 gets sorted soon, I am trying this extension until then.

I tried with Neovim 0.5.1 and the master, Thanks!

@mjlbach
Copy link

mjlbach commented Oct 23, 2021

The installer looks harmless FWIW

local M = {}
M.install_ltex_ls = function()
local path = require("grammar-guard.vars").install_path
local function onExit(_, code)
if code ~= 0 then
if vim.fn.delete(path, "rf") ~= 0 then -- here 0: success, -1: fail
error("[grammar-guard] Could not delete directory grammar-guard.")
end
error("[grammar-guard] Could not install language server.")
end
vim.notify("[grammar-guard] Successfully installed language server.")
end
local install_script = [[
os=$(uname -s | tr "[:upper:]" "[:lower:]")
case $os in
linux)
platform="linux"
;;
darwin)
platform="mac"
;;
esac
curl -L -o ltex.tar.gz $(curl -s https://api.github.com/repos/valentjn/ltex-ls/releases/latest | grep 'browser_' | cut -d\" -f4 | grep "$platform")
tar -xzf ltex.tar.gz
rm ltex.tar.gz
for i in ./*ltex*; do mv "$i" "ltex";done
]]
vim.fn.mkdir(path, "p")
vim.cmd("new")
local shell = vim.o.shell
vim.o.shell = "/usr/bin/env bash"
vim.fn.termopen("set -e\n" .. install_script, { cwd = path, on_exit = onExit })
vim.o.shell = shell
vim.cmd("startinsert")
end
return M

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
Copy link
Author

@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
Copy link

mjlbach commented Oct 24, 2021

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
Copy link
Author

@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? valentjn/ltex-ls#113 (comment)

@mjlbach
Copy link

mjlbach commented Oct 26, 2021

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
Copy link

oblitum commented Oct 28, 2021

@mfusseneggers@mfussenegger ^

@David-Else
Copy link
Author

@mjlbach @oblitum The #5 (comment) 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
Copy link

mjlbach commented Oct 29, 2021

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
Copy link
Author

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.

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

No branches or pull requests

3 participants