summaryrefslogtreecommitdiff
path: root/lua/lang/sh.lua
blob: 25c453d95b0a4f40744a12060e398c48390c32b5 (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
72
73
local M = {}

M.config = function()
  -- TODO: implement config for language
  return "No config available!"
end

M.format = function()
  O.formatters.filetype["sh"] = {
    function()
      return {
        exe = O.lang.sh.formatter.exe,
        args = O.lang.sh.formatter.args,
        stdin = not (O.lang.sh.formatter.stdin ~= nil),
      }
    end,
  }

  require("formatter.config").set_defaults {
    logging = false,
    filetype = O.formatters.filetype,
  }
end

M.lint = function()
  -- sh
  local sh_arguments = {}

  local shfmt = { formatCommand = "shfmt -ci -s -bn", formatStdin = true }

  local shellcheck = {
    LintCommand = "shellcheck -f gcc -x",
    lintFormats = { "%f:%l:%c: %trror: %m", "%f:%l:%c: %tarning: %m", "%f:%l:%c: %tote: %m" },
  }

  if O.lang.sh.linter == "shellcheck" then
    table.insert(sh_arguments, shellcheck)
  end

  if not require("lv-utils").check_lsp_client_active "efm" then
    require("lspconfig").efm.setup {
      -- init_options = {initializationOptions},
      cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
      init_options = { documentFormatting = true, codeAction = false },
      root_dir = require("lspconfig").util.root_pattern ".git/",
      filetypes = { "sh" },
      settings = {
        rootMarkers = { ".git/" },
        languages = {
          sh = sh_arguments,
        },
      },
    }
  end
end

M.lsp = function()
  if not require("lv-utils").check_lsp_client_active "bashls" then
    -- npm i -g bash-language-server
    require("lspconfig").bashls.setup {
      cmd = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start" },
      on_attach = require("lsp").common_on_attach,
      filetypes = { "sh", "zsh" },
    }
  end
end

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

return M