mattn / efm-langserver

General purpose Language Server
MIT License
1.32k stars 59 forks source link

efm with json and prettier setup help #234

Closed kaykhan closed 1 year ago

kaykhan commented 1 year ago

Hi friends,

I would like to format a local .json file using rules set a local .prettierrc file. Both of these files exist in my repository. However i can see under LspInfo that efm is not recognising the "json" file type.

image


 Client: efm (id: 2, pid: 3110594, bufnr: [14])
    filetypes:       javascript, typescript, javascriptreact, javascript.jsx, typescript.tsx, typescriptreact, less, scss, css, html, python
    autostart:       true
    root directory:  /home/kay/test/api-auth
    cmd:             efm-langserver

However in my efm config, i do remember adding json. as you can see here in my config. What am i doing wrong?

efm.vim

 lua << EOF

local prettier = {
  formatCommand = "prettier --stdin-filepath ${INPUT}",
  formatStdin = true,
}

local eslint = {
  lintCommand = "eslint_d -f unix --stdin --stdin-filename ${INPUT}",
  lintStdin = true,
  lintFormats = {"%f:%l:%c: %m"},
  lintIgnoreExitCode = true,
  formatCommand = "eslint_d --fix-to-stdout --stdin --stdin-filename=${INPUT}",
  formatStdin = true,
}

local pylint = {
  lintCommand = 'pylint --output-format text --score no --msg-template {path}:{line}:{column}:{C}:{msg} ${INPUT}',
  lintStdin = false,
  lintFormats = {"%f:%l:%c:%t:%m"},
}

local black = {
  formatCommand = 'black --line-length 100 -',
  formatStdin = true
}

local isort = {
  formatCommand = "isort --profile black -",
  formatStdin = true,
}

local autopep8 = {
  formatCommand = "autopep8 -",
  formatStdin = true
}

require'lspconfig'.efm.setup{
  on_attach = function(client)
    local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
    capabilities = capabilities
    client.resolved_capabilities.goto_definition = false
    client.resolved_capabilities.declaration = false  
  end,
  init_options = { documentFormatting = true },
  settings = {
    rootMarkers = {".git/"},
    languages = {
      javascript = { prettier, eslint },
      typescript = { prettier, eslint },
      typescriptreact = {prettier, eslint},
      javascriptreact = {prettier, eslint},
      ["javascript.jsx"] = {prettier, eslint},
      ["typescript.tsx"] = {prettier, eslint},
      yaml = {prettier},
      json = {prettier},
      html = {prettier},
      less = {prettier},
      scss = {prettier},
      css = {prettier},
      markdown = {prettier},
      python = {black, isort}  
    }
  },
  filetypes = {
    "javascript",
    "typescript",
    "javascriptreact",
    "javascript.jsx",  
    "typescript.tsx",
    "typescriptreact",
    "less",
    "scss",
    "css",
    "html",
    "python",
  },
}

EOF
kaykhan commented 1 year ago

Oh i just saw the problem after posting this filetypes does not contain json.