init.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. -- Fuck off with the warnings...
  2. ---@diagnostic disable-next-line: duplicate-set-field
  3. vim.deprecate = function() end
  4. require("globals")
  5. require("config.options")
  6. require("config.remap")
  7. require("config.autocomands")
  8. require("config.lazy")
  9. vim.api.nvim_create_autocmd("VimEnter", {
  10. callback = function()
  11. local config_path = vim.fn.stdpath("config")
  12. local current_dir = vim.fn.getcwd()
  13. if current_dir == config_path then
  14. vim.fn.system("git config core.hooksPath .githooks")
  15. if vim.v.shell_error ~= 0 then
  16. vim.notify("Failed to set git hooks path for Neovim config", vim.log.levels.WARN)
  17. end
  18. end
  19. end,
  20. desc = "Set git hooks path for Neovim config directory only",
  21. })
  22. -- Define a highlight group for the floating filename
  23. vim.api.nvim_create_autocmd("VimEnter", {
  24. callback = function()
  25. -- Create a highlight group for the floating window text
  26. vim.cmd("highlight ClaseFloatText guifg=#FFD700 guibg=#1E1E2E") -- gold text on dark background
  27. local config_path = vim.fn.stdpath("config")
  28. local current_dir = vim.fn.getcwd()
  29. if current_dir == config_path then
  30. vim.fn.system("git config core.hooksPath .githooks")
  31. if vim.v.shell_error ~= 0 then
  32. vim.notify("Failed to set git hooks path for Neovim config", vim.log.levels.WARN)
  33. end
  34. end
  35. end,
  36. desc = "Set git hooks path for Neovim config directory only",
  37. })
  38. vim.g.clase_floating_enabled = false
  39. local function toggle_lsp_features(enable)
  40. if vim.lsp.inlay_hint and vim.lsp.inlay_hint.enable then
  41. pcall(vim.lsp.inlay_hint.enable, enable)
  42. end
  43. end
  44. local function show_filename_float()
  45. local enabled = vim.g.clase_floating_enabled
  46. local ft = vim.bo.filetype
  47. local filename = vim.fn.expand("%:~:.")
  48. local should_skip = not enabled or ft == "oil" or filename == ""
  49. if should_skip then
  50. if vim.g.filename_float_win and vim.api.nvim_win_is_valid(vim.g.filename_float_win) then
  51. vim.api.nvim_win_close(vim.g.filename_float_win, true)
  52. vim.g.filename_float_win = nil
  53. end
  54. return
  55. end
  56. if vim.g.filename_float_win and vim.api.nvim_win_is_valid(vim.g.filename_float_win) then
  57. vim.api.nvim_win_close(vim.g.filename_float_win, true)
  58. end
  59. local buf = vim.api.nvim_create_buf(false, true)
  60. local text = "🗂 " .. filename
  61. vim.api.nvim_buf_set_lines(buf, 0, -1, false, { text })
  62. -- Apply the highlight group to the entire line
  63. vim.api.nvim_buf_add_highlight(buf, -1, "ClaseFloatText", 0, 0, -1)
  64. local width = vim.fn.strdisplaywidth(text) + 2
  65. local opts = {
  66. relative = "editor",
  67. width = width,
  68. height = 1,
  69. row = 0,
  70. col = vim.o.columns - width,
  71. style = "minimal",
  72. focusable = false,
  73. border = "rounded",
  74. }
  75. local win = vim.api.nvim_open_win(buf, false, opts)
  76. vim.g.filename_float_win = win
  77. end
  78. -- Autocomando para actualizar en cambios de buffer
  79. vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
  80. callback = show_filename_float,
  81. })
  82. -- Enhanced :Class command that also toggles inlay hints and diagnostics
  83. vim.api.nvim_create_user_command("Class", function()
  84. vim.g.clase_floating_enabled = not vim.g.clase_floating_enabled
  85. if not vim.g.clase_floating_enabled then
  86. -- Class mode OFF: Restore normal behavior
  87. if vim.g.filename_float_win and vim.api.nvim_win_is_valid(vim.g.filename_float_win) then
  88. vim.api.nvim_win_close(vim.g.filename_float_win, true)
  89. vim.g.filename_float_win = nil
  90. end
  91. toggle_lsp_features(true) -- Enable LSP features
  92. vim.opt.relativenumber = true -- Restore relative numbers
  93. else
  94. -- Class mode ON: Minimal UI for students
  95. show_filename_float()
  96. toggle_lsp_features(false) -- Disable LSP features
  97. vim.opt.relativenumber = false -- Hide relative numbers
  98. end
  99. end, {})