null-ls.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. local status, null_ls = pcall(require, "null-ls")
  2. if not status then
  3. vim.notify("没有找到 null-ls")
  4. return
  5. end
  6. local formatting = null_ls.builtins.formatting
  7. local diagnostics = null_ls.builtins.diagnostics
  8. local code_actions = null_ls.builtins.code_actions
  9. null_ls.setup({
  10. debug = false,
  11. sources = {
  12. -- Formatting ---------------------
  13. -- brew install shfmt
  14. formatting.shfmt,
  15. -- StyLua
  16. formatting.stylua,
  17. -- frontend
  18. formatting.prettier.with({
  19. -- 比默认少了 markdown
  20. filetypes = {
  21. "javascript",
  22. "javascriptreact",
  23. "typescript",
  24. "typescriptreact",
  25. "vue",
  26. "css",
  27. "scss",
  28. "less",
  29. "html",
  30. "json",
  31. "yaml",
  32. "graphql",
  33. "markdown",
  34. },
  35. timeout = 10000,
  36. prefer_local = "node_modules/.bin",
  37. }),
  38. -- rustfmt
  39. -- rustup component add rustfmt
  40. formatting.rustfmt,
  41. -- Python
  42. -- pip install black
  43. -- asdf reshim python
  44. formatting.black.with({ extra_args = { "--fast" } }),
  45. -----------------------------------------------------
  46. -- Ruby
  47. -- gem install rubocop
  48. formatting.rubocop,
  49. -- json
  50. -- npm install -g fixjson
  51. formatting.fixjson,
  52. -- toml
  53. -- cargo install taplo-cli
  54. formatting.taplo,
  55. -----------------------------------------------------
  56. -- Diagnostics ---------------------
  57. -- diagnostics.eslint.with({
  58. -- prefer_local = "node_modules/.bin",
  59. -- }),
  60. -- npm install -g eslint_d
  61. diagnostics.eslint_d.with({
  62. prefer_local = "node_modules/.bin",
  63. }),
  64. -- diagnostics.markdownlint,
  65. -- markdownlint-cli2
  66. -- diagnostics.markdownlint.with({
  67. -- prefer_local = "node_modules/.bin",
  68. -- command = "markdownlint-cli2",
  69. -- args = { "$FILENAME", "#node_modules" },
  70. -- }),
  71. --
  72. -- code actions ---------------------
  73. code_actions.gitsigns,
  74. -- code_actions.eslint.with({
  75. -- prefer_local = "node_modules/.bin",
  76. -- }),
  77. -- npm install -g eslint_d
  78. code_actions.eslint_d,
  79. },
  80. -- #{m}: message
  81. -- #{s}: source name (defaults to null-ls if not specified)
  82. -- #{c}: code (if available)
  83. diagnostics_format = "[#{s}] #{m}",
  84. on_attach = function(_)
  85. vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()']])
  86. -- if client.resolved_capabilities.document_formatting then
  87. -- vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()")
  88. -- end
  89. end,
  90. })