python.lua 2.1 KB

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