init.lua 3.7 KB

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