summaryrefslogtreecommitdiff
path: root/lua/lang/vue.lua
blob: 8725bba2be3c8b73fb13de608a7b7470e34e7acb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local M = {}

M.config = function()
  O.lang.vue = {
    formatter = {
      exe = "prettier",
      args = {
        "--stdin-filepath",
        "${FILEPATH}",
      },
      stdin = true,
    },
    auto_import = true,
    lsp = {
      path = DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls",
    },
  }
end

M.format = function()
  vim.cmd "let proj = FindRootDirectory()"
  local root_dir = vim.api.nvim_get_var "proj"

  -- use the global formatter if you didn't find the local one
  local formatter_instance = root_dir .. "/node_modules/.bin/" .. O.lang.vue.formatter.exe
  if vim.fn.executable(formatter_instance) ~= 1 then
    formatter_instance = O.lang.vue.formatter.exe
  end

  local ft = vim.bo.filetype
  O.formatters.filetype[ft] = {
    function()
      local lv_utils = require "lv-utils"
      return {
        exe = formatter_instance,
        args = lv_utils.gsub_args(O.lang.vue.formatter.args),
        stdin = O.lang.vue.formatter.stdin,
      }
    end,
  }
  require("formatter.config").set_defaults {
    logging = false,
    filetype = O.formatters.filetype,
  }
end

M.lint = function()
  -- TODO: implement linters (if applicable)
  return "No linters configured!"
end

M.lsp = function()
  if require("lv-utils").check_lsp_client_active "vuels" then
    return
  end

  -- Vue language server configuration (vetur)
  require("lspconfig").vuels.setup {
    cmd = { O.lang.vue.lsp.path, "--stdio" },
    on_attach = require("lsp").common_on_attach,
  }

  require("lsp.ts-fmt-lint").setup()
end

M.dap = function()
  -- TODO: implement dap
  return "No DAP configured!"
end

return M