aboutsummaryrefslogtreecommitdiffstats
path: root/lua/pi/lsp/null-ls.lua
blob: eef6be62adccb6544b4ff436ef37e1b1f75b44b1 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
local null_ls = require "null-ls"
-- local php_actions = require "php-code-actions"
-- local laravel_actions = require("laravel.code-actions")

null_ls.setup {
  sources = {
    -- null_ls.builtins.code_actions.gitsigns,
    require "none-ls.formatting.jq",
    -- require("none-ls.diagnostics.cpplint"),
    require "none-ls.code_actions.eslint",
    null_ls.builtins.code_actions.refactoring,
    null_ls.builtins.formatting.alejandra,
    require "none-ls-luacheck.diagnostics.luacheck",
    null_ls.builtins.formatting.stylua,

    require "none-ls.diagnostics.yamllint",
    -- require("none-ls.diagnostics.ruff"),
    -- require("none-ls.diagnostics.flake8"),
    require "none-ls-shellcheck.diagnostics",
    require "none-ls-shellcheck.code_actions",
    -- null_ls.builtins.diagnostics.yamllint,

    -- php_actions.getter_setter,
    -- php_actions.file_creator,

    -- null_ls.builtins.diagnostics.phpstan.with {
    --   to_temp_file = false,
    --   method = null_ls.methods.DIAGNOSTICS_ON_SAVE,
    --   -- command = "./bin/phpstan",
    --   -- condition = function ()
    --   --   return vim.fn.findfile("bin/phpstan") ~= ""
    --   -- end
    -- },
    null_ls.builtins.diagnostics.phpcs.with {
      method = null_ls.methods.DIAGNOSTICS_ON_SAVE,
      condition = function(utils)
        return utils.root_has_file "phpcs.xml"
      end,
    },
    null_ls.builtins.formatting.pint,
    null_ls.builtins.formatting.clang_format,
    null_ls.builtins.formatting.prettier.with {
      extra_args = {
        "--print-width",
        "100",
        "--tab-width",
        "2",
        "--single-quote",
        "true",
        "--trailing-comma",
        "all",
        "--arrow-parens",
        "always",
        "--semi",
        "false",
        "--bracket-spacing",
        "false",
        "--jsx-single-quote",
        "true",
        "--end-of-line",
        "lf",
      },
    },
    -- Opciones avanzadas de Black:
    -- --line-length 100: ancho máximo de línea
    -- --fast: omite comprobaciones de seguridad
    -- --skip-string-normalization: no cambia comillas
    -- --skip-magic-trailing-comma: ignora trailing comma mágica
    -- --target-version py310: versión objetivo de Python 3.10
    -- --preview: activa funciones experimentales
    -- --diff: muestra el diff en vez de modificar archivos
    -- --quiet: suprime la salida normal
    -- --color: colorea el diff
    -- --exclude ".*test.*": excluye archivos que coincidan con el patrón
    -- null_ls.builtins.formatting.black.with {
    --   extra_args = {
    --     "--line-length",
    --     "120",
    --     -- "--fast",
    --     "--skip-string-normalization",
    --     "--skip-magic-trailing-comma",
    --     "--target-version",
    --     "py312",
    --     -- "--preview",
    --     -- "--diff",
    --     -- "--quiet",
    --     -- "--color",
    --     "--exclude",
    --     ".*test.*",
    --   },
    -- },
    -- Assembly formatter
    {
      name = "asmfmt",
      method = null_ls.methods.FORMATTING,
      filetypes = { "asm", "s", "S" },
      generator = null_ls.formatter {
        command = "asmfmt",
        to_stdin = true,
        condition = function()
          return vim.fn.executable "asmfmt" == 1
        end,
      },
    },
    -- null_ls.builtins.formatting.clang_format.with {
    --   extra_args = { "--style={IndentWidth: 4}" },
    -- },
  },
}

vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, { desc = "LSP (null ls) Code actions" })
vim.keymap.set("n", "<leader>vf", function()
  return vim.lsp.buf.format { async = true }
end, { desc = "LSP (null ls) Format file" })

-- function to toogle and possible restart it
vim.api.nvim_create_user_command("NullLsToggle", function()
  local sources = vim.tbl_map(function(el)
    return el.name
  end, null_ls.get_sources())
  vim.ui.select(sources, {}, function(selected)
    if not selected then
      return
    end
    null_ls.toggle(selected)
  end)
end, {})