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. "svelte",
  35. },
  36. timeout = 10000,
  37. prefer_local = "node_modules/.bin",
  38. }),
  39. -- rustfmt
  40. -- rustup component add rustfmt
  41. formatting.rustfmt,
  42. -- Python
  43. -- pip install black
  44. -- asdf reshim python
  45. formatting.black.with({ extra_args = { "--fast" } }),
  46. -----------------------------------------------------
  47. -- Ruby
  48. -- gem install rubocop
  49. formatting.rubocop,
  50. -- json
  51. -- npm install -g fixjson
  52. formatting.fixjson,
  53. -- toml
  54. -- cargo install taplo-cli
  55. formatting.taplo,
  56. -----------------------------------------------------
  57. -- Diagnostics ---------------------
  58. -- diagnostics.eslint.with({
  59. -- prefer_local = "node_modules/.bin",
  60. -- }),
  61. -- npm install -g eslint_d
  62. diagnostics.eslint_d.with({
  63. prefer_local = "node_modules/.bin",
  64. }),
  65. -- diagnostics.markdownlint,
  66. -- markdownlint-cli2
  67. -- diagnostics.markdownlint.with({
  68. -- prefer_local = "node_modules/.bin",
  69. -- command = "markdownlint-cli2",
  70. -- args = { "$FILENAME", "#node_modules" },
  71. -- }),
  72. --
  73. -- code actions ---------------------
  74. code_actions.gitsigns,
  75. -- code_actions.eslint.with({
  76. -- prefer_local = "node_modules/.bin",
  77. -- }),
  78. -- npm install -g eslint_d
  79. code_actions.eslint_d,
  80. },
  81. -- #{m}: message
  82. -- #{s}: source name (defaults to null-ls if not specified)
  83. -- #{c}: code (if available)
  84. diagnostics_format = "[#{s}] #{m}",
  85. on_attach = function(_)
  86. vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()']])
  87. -- if client.resolved_capabilities.document_formatting then
  88. -- vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()")
  89. -- end
  90. end,
  91. })