VonHeikemen / lsp-zero.nvim

A starting point to setup some lsp related features in neovim.
https://lsp-zero.netlify.app/v4.x/
MIT License
3.76k stars 95 forks source link

How to configure efm? #388

Open RudolfVonKrugstein opened 5 months ago

RudolfVonKrugstein commented 5 months ago

Hi,

I am trying to configure efm to use markdown-lint and pandoc in markdown. Following this https://github.com/VonHeikemen/lsp-zero.nvim/blob/efm-client/doc/md/api-reference.md#efmtoolsopts I did:

-- setup efm
local efm_opts = lsp_zero.efm.tools({ -- this is line 201, from the error below
  {
    name = "markdown-lint",
    lintCommand = "markdownlint -s",
    lintStdin = true,
    lintFormats = {
      "%f:%l %m",
      "%f:%l:%c %m",
      "%f: %l: %m",
    },
    languages = { "markdown" },
  },
  {
    name = "markdown-pandoc",
    formatCommand = "pandoc -f markdown -t gfm -sp --tab-stop=2",
    languages = { "markdown" },
  },
})
require("lspconfig").efm.setup(efm_opts)

But when running this, I get:

Error detected while processing /home/nathan/dotfiles/nvim/init.lua:
E5113: Error while calling lua chunk: /home/nathan/dotfiles/nvim/init.lua:201: attempt to index field 'efm' (a nil value)
stack traceback:
        /home/nathan/dotfiles/nvim/init.lua:201: in main chunk

Why? What shall I do different?

Thanks!

VonHeikemen commented 5 months ago

That feature was never merged in any release branch. So you have to add all the relevant options to lspconfig manually.

I would do something like this.

local efm_tools = {
  pandoc = {
    formatCommand = "pandoc -f markdown -t gfm -sp --tab-stop=2",
  },
  markdownlint = {
    lintCommand = "markdownlint -s",
    lintStdin = true,
    lintFormats = {
      "%f:%l %m",
      "%f:%l:%c %m",
      "%f: %l: %m",
    },
  }
}

require('lspconfig').efm.setup({
  init_options = {
    -- enable the options that your tools support
    documentFormatting = true,
    documentRangeFormatting = false,
    hover = false,
    documentSymbol = false,
    completion = false,
    codeAction = false
  },
  settings = {
    rootMarkers = {'.git/'},
    -- here you configure the tools per language
    languages = {
      markdown = {
        efm_tools.pandoc,
        efm_tools.markdownlint,
      },
    }
  },
  -- list of file types where the language server will be active
  filetypes = {
    'markdown',
  },
})