python.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. require("lspconfig").efm.setup {
  18. -- init_options = {initializationOptions},
  19. cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
  20. init_options = { documentFormatting = true, codeAction = false },
  21. filetypes = { "python" },
  22. settings = {
  23. rootMarkers = { ".git/", "requirements.txt" },
  24. languages = {
  25. python = python_arguments,
  26. },
  27. },
  28. }
  29. -- npm i -g pyright
  30. require("lspconfig").pyright.setup {
  31. cmd = {
  32. DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver",
  33. "--stdio",
  34. },
  35. on_attach = require("lsp").common_on_attach,
  36. handlers = {
  37. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  38. virtual_text = O.lang.python.diagnostics.virtual_text,
  39. signs = O.lang.python.diagnostics.signs,
  40. underline = O.lang.python.diagnostics.underline,
  41. update_in_insert = true,
  42. }),
  43. },
  44. settings = {
  45. python = {
  46. analysis = {
  47. typeCheckingMode = O.lang.python.analysis.type_checking,
  48. autoSearchPaths = O.lang.python.analysis.auto_search_paths,
  49. useLibraryCodeForTypes = O.lang.python.analysis.use_library_code_types,
  50. },
  51. },
  52. },
  53. }
  54. if O.plugin.debug.active and O.plugin.dap_install.active then
  55. local dap_install = require("dap-install")
  56. dap_install.config("python_dbg", {})
  57. end