python.lua 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. stdin = true,
  21. },
  22. linters = {
  23. "flake8",
  24. "pylint",
  25. "mypy",
  26. },
  27. }
  28. end
  29. M.format = function()
  30. O.formatters.filetype["python"] = {
  31. function()
  32. return {
  33. exe = O.lang.python.formatter.exe,
  34. args = O.lang.python.formatter.args,
  35. stdin = O.lang.python.formatter.stdin,
  36. }
  37. end,
  38. }
  39. require("formatter.config").set_defaults {
  40. logging = false,
  41. filetype = O.formatters.filetype,
  42. }
  43. end
  44. M.lint = function()
  45. require("lint").linters_by_ft = {
  46. python = O.lang.python.linters,
  47. }
  48. end
  49. M.lsp = function()
  50. if require("lv-utils").check_lsp_client_active "pyright" then
  51. return
  52. end
  53. -- npm i -g pyright
  54. require("lspconfig").pyright.setup {
  55. cmd = {
  56. DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver",
  57. "--stdio",
  58. },
  59. on_attach = require("lsp").common_on_attach,
  60. handlers = {
  61. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  62. virtual_text = O.lang.python.diagnostics.virtual_text,
  63. signs = O.lang.python.diagnostics.signs,
  64. underline = O.lang.python.diagnostics.underline,
  65. update_in_insert = true,
  66. }),
  67. },
  68. settings = {
  69. python = {
  70. analysis = {
  71. typeCheckingMode = O.lang.python.analysis.type_checking,
  72. autoSearchPaths = O.lang.python.analysis.auto_search_paths,
  73. useLibraryCodeForTypes = O.lang.python.analysis.use_library_code_types,
  74. },
  75. },
  76. },
  77. }
  78. end
  79. M.dap = function()
  80. if O.plugin.dap.active then
  81. local dap_install = require "dap-install"
  82. dap_install.config("python_dbg", {})
  83. end
  84. end
  85. return M