mattn / efm-langserver

General purpose Language Server
MIT License
1.35k stars 61 forks source link

Set init_options for each language #164

Open guilhermehubner opened 3 years ago

guilhermehubner commented 3 years ago

Hello, I am using efm-langserver with nvim-lspconfig, this is my configuration:

local prettier = {
  formatCommand = 'prettier'
}

local golangcilint = {
  lintCommand = "golangci-lint run",
  lintSource = "golanci-lint",
}

lsp.efm.setup{
  init_options = {documentFormatting = true},
  root_dir = vim.loop.cwd,
  settings = {
    rootMarkers = {".git/"},
    languages = {
        go                     = {golangcilint},
        typescript      = {prettier},
    }
  }
}

As you can see, for golang I am using efm only for lint, the rest I do using gopls; There is a problem though, for typescript I am using prettier for formating, so I need to set init_options = {documentFormatting = true} and I have a format command set on save. For typescript it is ok, but for go, I have 2 server which offer documentFormating, so everytime I save a document I need to select the LSP I want to use for formatting. In this case my EFM don't format for Go so it is useless and inconvenient. I wonder if it is possible to do something like:

local prettier = {
  formatCommand = 'prettier'
  init_options = {documentFormatting = true}, -- SET HERE
}

local golangcilint = {
  lintCommand = "golangci-lint run",
  lintSource = "golanci-lint",
  init_options = {documentFormatting = false}, -- SET HERE
}

lsp.efm.setup{
  root_dir = vim.loop.cwd,
  settings = {
    rootMarkers = {".git/"},
    languages = {
        go                     = {golangcilint},
        typescript      = {prettier},
    }
  }
}