python.lua 2.1 KB

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