python.lua 2.1 KB

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