python.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. local M = {}
  2. M.config = function()
  3. O.lang.python = {
  4. -- @usage can be flake8 or yapf
  5. linter = "",
  6. isort = false,
  7. diagnostics = {
  8. virtual_text = { spacing = 0, prefix = "" },
  9. signs = true,
  10. underline = true,
  11. },
  12. analysis = {
  13. type_checking = "basic",
  14. auto_search_paths = true,
  15. use_library_code_types = true,
  16. },
  17. formatter = {
  18. exe = "yapf",
  19. args = {},
  20. },
  21. linters = {
  22. "flake8",
  23. "pylint",
  24. "mypy",
  25. },
  26. }
  27. end
  28. M.format = function()
  29. O.formatters.filetype["python"] = {
  30. function()
  31. return {
  32. exe = O.lang.python.formatter.exe,
  33. args = O.lang.python.formatter.args,
  34. stdin = not (O.lang.python.formatter.stdin ~= nil),
  35. }
  36. end,
  37. }
  38. require("formatter.config").set_defaults {
  39. logging = false,
  40. filetype = O.formatters.filetype,
  41. }
  42. end
  43. M.lint = function()
  44. require("lint").linters_by_ft = {
  45. python = O.lang.python.linters,
  46. }
  47. end
  48. M.lsp = function()
  49. if require("lv-utils").check_lsp_client_active "pyright" then
  50. return
  51. end
  52. -- npm i -g pyright
  53. require("lspconfig").pyright.setup {
  54. cmd = {
  55. DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver",
  56. "--stdio",
  57. },
  58. on_attach = require("lsp").common_on_attach,
  59. handlers = {
  60. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  61. virtual_text = O.lang.python.diagnostics.virtual_text,
  62. signs = O.lang.python.diagnostics.signs,
  63. underline = O.lang.python.diagnostics.underline,
  64. update_in_insert = true,
  65. }),
  66. },
  67. settings = {
  68. python = {
  69. analysis = {
  70. typeCheckingMode = O.lang.python.analysis.type_checking,
  71. autoSearchPaths = O.lang.python.analysis.auto_search_paths,
  72. useLibraryCodeForTypes = O.lang.python.analysis.use_library_code_types,
  73. },
  74. },
  75. },
  76. }
  77. end
  78. M.dap = function()
  79. if O.plugin.dap.active then
  80. local dap_install = require "dap-install"
  81. dap_install.config("python_dbg", {})
  82. end
  83. end
  84. return M