init.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.telescope-shroud"),
  28. require("proj-conf.projects.ruff_pyright"),
  29. require("proj-conf.projects.deno_typescript_monorepo"),
  30. }) do
  31. map.default = vim.list_extend(map.default, i.default)
  32. i.default = nil
  33. map = vim.tbl_deep_extend("error", map, i)
  34. end
  35. local setup = function()
  36. if status.loaded then
  37. return
  38. end
  39. status.initial = {}
  40. status.found = {}
  41. status.failed = {}
  42. status.loaded = false
  43. local settings = {}
  44. local add_to_settings
  45. add_to_settings = function(item)
  46. if type(map[item]) == "table" then
  47. for _, key in pairs(map[item]) do add_to_settings(key) end
  48. table.insert(status.initial, item)
  49. else
  50. settings[item] = true
  51. end
  52. end
  53. if vim.fn.filereadable(filename) == 1 then
  54. for line in io.lines(filename) do
  55. if map[line] then add_to_settings(line) end
  56. end
  57. else
  58. add_to_settings("default")
  59. table.insert(status.initial, "default")
  60. end
  61. for item, _ in pairs(settings) do
  62. if pcall(map[item]) then
  63. table.insert(status.found, item)
  64. else
  65. table.insert(status.failed, item)
  66. end
  67. end
  68. status.loaded = true
  69. end
  70. return {
  71. setup = setup,
  72. map = map,
  73. status = function()
  74. return status
  75. end
  76. }