init.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. -- This plugin enables simple, safe, and reusable project-level settings. This
  2. -- plugin contains much configuration that is unlikely to be useful outside the
  3. -- context of the rest of this repository, aside from `./init.lua` and
  4. -- `./health.lua`.
  5. -- Configurations loaded into `init.lua` should contain a table of either
  6. -- configuration functions or the names of configuration functions (as strings).
  7. -- The keys of these tables must be globally unique, except for `default`, which
  8. -- is a special item that must be a table of zero or more configuration function
  9. -- names. These configurations will be aggregated and executed (in no particular
  10. -- order).
  11. -- If a file called `.proj-conf.neovim` is found in Neovim's working directory,
  12. -- then each line of that file will be parsed as the name of a configuration
  13. -- function. If no such file exists, then `default` will be used as the root
  14. -- setting. This allows composing project-specific settings.
  15. -- The appeal of this hack is enabling composable settings without needing to
  16. -- navigate the security challenges of `set exrc`.
  17. --
  18. local filename = ".proj-conf.neovim"
  19. local map = { default = {} }
  20. local status = {
  21. initial = {},
  22. found = {},
  23. failed = {},
  24. loaded = false
  25. }
  26. for _, i in pairs({
  27. require("proj-conf.lsp"),
  28. require("proj-conf.save-formatter"),
  29. require("proj-conf.projects.deno_typescript_monorepo"),
  30. require("proj-conf.projects.ruff_pyright")
  31. }) do
  32. map.default = vim.list_extend(map.default, i.default)
  33. i.default = nil
  34. map = vim.tbl_deep_extend("error", map, i)
  35. end
  36. local setup = function()
  37. if status.loaded then
  38. return
  39. end
  40. status.initial = {}
  41. status.found = {}
  42. status.failed = {}
  43. status.loaded = false
  44. local settings = {}
  45. local add_to_settings
  46. add_to_settings = function(item)
  47. if type(map[item]) == "table" then
  48. for _, key in pairs(map[item]) do add_to_settings(key) end
  49. table.insert(status.initial, item)
  50. else
  51. settings[item] = true
  52. end
  53. end
  54. if vim.fn.filereadable(filename) == 1 then
  55. for line in io.lines(filename) do
  56. if map[line] then add_to_settings(line) end
  57. end
  58. else
  59. add_to_settings("default")
  60. table.insert(status.initial, "default")
  61. end
  62. for item, _ in pairs(settings) do
  63. if pcall(map[item]) then
  64. table.insert(status.found, item)
  65. else
  66. table.insert(status.failed, item)
  67. end
  68. end
  69. status.loaded = true
  70. end
  71. return {
  72. setup = setup,
  73. map = map,
  74. status = function()
  75. return status
  76. end
  77. }