python.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. O.formatters.filetype["python"] = {
  2. function()
  3. return {
  4. exe = O.lang.python.formatter.exe,
  5. args = O.lang.python.formatter.args,
  6. stdin = not (O.lang.python.formatter.stdin ~= nil),
  7. }
  8. end,
  9. }
  10. require("formatter.config").set_defaults {
  11. logging = false,
  12. filetype = O.formatters.filetype,
  13. }
  14. local python_arguments = {}
  15. -- TODO: replace with path argument
  16. local flake8 = {
  17. LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -",
  18. lintStdin = true,
  19. lintFormats = { "%f:%l:%c: %m" },
  20. }
  21. local isort = { formatCommand = "isort --quiet -", formatStdin = true }
  22. local yapf = { formatCommand = "yapf --quiet", formatStdin = true }
  23. local black = { formatCommand = "black --quiet -", formatStdin = true }
  24. if O.lang.python.linter == "flake8" then
  25. table.insert(python_arguments, flake8)
  26. end
  27. if O.lang.python.isort then
  28. table.insert(python_arguments, isort)
  29. end
  30. if not require("lv-utils").check_lsp_client_active "efm" then
  31. require("lspconfig").efm.setup {
  32. -- init_options = {initializationOptions},
  33. cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
  34. init_options = { documentFormatting = true, codeAction = false },
  35. root_dir = require("lspconfig").util.root_pattern(".git/", "requirements.txt"),
  36. filetypes = { "python" },
  37. settings = {
  38. rootMarkers = { ".git/", "requirements.txt" },
  39. languages = {
  40. python = python_arguments,
  41. },
  42. },
  43. }
  44. end
  45. if not require("lv-utils").check_lsp_client_active "pyright" then
  46. -- npm i -g pyright
  47. require("lspconfig").pyright.setup {
  48. cmd = {
  49. DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver",
  50. "--stdio",
  51. },
  52. on_attach = require("lsp").common_on_attach,
  53. handlers = {
  54. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  55. virtual_text = O.lang.python.diagnostics.virtual_text,
  56. signs = O.lang.python.diagnostics.signs,
  57. underline = O.lang.python.diagnostics.underline,
  58. update_in_insert = true,
  59. }),
  60. },
  61. settings = {
  62. python = {
  63. analysis = {
  64. typeCheckingMode = O.lang.python.analysis.type_checking,
  65. autoSearchPaths = O.lang.python.analysis.auto_search_paths,
  66. useLibraryCodeForTypes = O.lang.python.analysis.use_library_code_types,
  67. },
  68. },
  69. },
  70. }
  71. end
  72. if O.plugin.dap.active then
  73. local dap_install = require "dap-install"
  74. dap_install.config("python_dbg", {})
  75. end