basedpyright.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --- @type vim.lsp.ClientConfig
  2. return {
  3. cmd = { 'basedpyright-langserver', '--stdio' },
  4. filetypes = { 'python' },
  5. root_markers = {
  6. 'pyproject.toml',
  7. 'setup.py',
  8. 'setup.cfg',
  9. 'requirements.txt',
  10. 'Pipfile',
  11. 'pyrightconfig.json',
  12. },
  13. single_file_support = true,
  14. settings = {
  15. basedpyright = {
  16. analysis = {
  17. typeCheckingMode = "standard",
  18. diagnosticMode = "openFilesOnly",
  19. autoSearchPaths = true,
  20. include = { "*" },
  21. exclude = { "**/node_modules", "**/__pycache__", "**/build" },
  22. useLibraryCodeForTypes = true,
  23. analyzeUnannotatedFunctions = true,
  24. reportUnreachable = true,
  25. },
  26. openFilesOnly = true,
  27. autoImportCompletions = true,
  28. disableOrganizeImports = true,
  29. }
  30. },
  31. on_init = function(client, _)
  32. local typecheckingPicker = function(opts)
  33. local pickers = require("telescope.pickers")
  34. local themes = require("telescope.themes")
  35. local actions = require("telescope.actions")
  36. local action_state = require("telescope.actions.state")
  37. local finders = require("telescope.finders")
  38. local conf = require("telescope.config").values
  39. local current = client.settings.basedpyright.analysis
  40. .typeCheckingMode
  41. if current == nil then current = "unset" end
  42. pickers.new(themes.get_dropdown({}), {
  43. prompt_title = "BasedPyright Typechecking (Current: " ..
  44. current .. ")",
  45. finder = finders.new_table({
  46. results = vim.tbl_filter(
  47. function(r) return r ~= current end,
  48. { "off", "basic", "standard", "strict", "all" }),
  49. }),
  50. sorter = conf.generic_sorter(opts),
  51. attach_mappings = function(prompt_bufnr, _)
  52. actions.select_default:replace(function()
  53. actions.close(prompt_bufnr)
  54. local selection = action_state
  55. .get_selected_entry()
  56. client.settings.basedpyright.analysis.typeCheckingMode =
  57. selection.value
  58. client:notify(
  59. "workspace/didChangeConfiguration",
  60. client.settings)
  61. end)
  62. return true
  63. end,
  64. }):find()
  65. end
  66. if pcall(require, "command-palette") and pcall(require, "telescope.pickers") then
  67. require("command-palette").add({ {
  68. "BasedPyright Typechecking",
  69. "Set `typeCheckingMode` of BasedPyright",
  70. typecheckingPicker }
  71. })
  72. end
  73. end,
  74. }