python.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 O.lang.python.formatter == "yapf" then
  18. table.insert(python_arguments, yapf)
  19. elseif O.lang.python.formatter == "black" then
  20. table.insert(python_arguments, black)
  21. end
  22. require("lspconfig").efm.setup {
  23. -- init_options = {initializationOptions},
  24. cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
  25. init_options = { documentFormatting = true, codeAction = false },
  26. filetypes = { "python" },
  27. settings = {
  28. rootMarkers = { ".git/", "requirements.txt" },
  29. languages = {
  30. python = python_arguments,
  31. },
  32. },
  33. }
  34. -- npm i -g pyright
  35. require("lspconfig").pyright.setup {
  36. cmd = {
  37. DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver",
  38. "--stdio",
  39. },
  40. on_attach = require("lsp").common_on_attach,
  41. handlers = {
  42. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  43. virtual_text = O.lang.python.diagnostics.virtual_text,
  44. signs = O.lang.python.diagnostics.signs,
  45. underline = O.lang.python.diagnostics.underline,
  46. update_in_insert = true,
  47. }),
  48. },
  49. settings = {
  50. python = {
  51. analysis = {
  52. typeCheckingMode = O.lang.python.analysis.type_checking,
  53. autoSearchPaths = O.lang.python.analysis.auto_search_paths,
  54. useLibraryCodeForTypes = O.lang.python.analysis.use_library_code_types,
  55. },
  56. },
  57. },
  58. }
  59. if O.lang.python.autoformat then
  60. require("lv-utils").define_augroups {
  61. _python_autoformat = {
  62. {
  63. "BufWritePre",
  64. "*.py",
  65. "lua vim.lsp.buf.formatting_sync(nil, 1000)",
  66. },
  67. },
  68. }
  69. end
  70. local dap_install = require("dap-install")
  71. dap_install.config("python_dbg", {})